鐵人賽
AWS
Outposts
EC2
Terraform
Vagrant
、Packer
等HCL
,其名源自公司名稱aws cli
,並且在 IAM console 中,產生 key 和 secret、在運作指令的環境中,將 key 和 secret 填入 ~/.aws/credentials
main.tf
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
}
}
required_version = ">= 0.14.9"
}
provider "aws" {
profile = "default" # 這邊要注意,看你的 ~/.aws/credentials 的設置是哪一組,見下方備註
region = "ap-northeast-1"
}
resource "aws_instance" "terraform_start_app_server" {
ami = "${var.ami_id}" # Ubuntu
instance_type = "m5.large"
subnet_id = "${var.subnet_outposts_1}"
tags = {
Name = "${var.instance_name}"
}
}
output "instance_id" {
description = "ID of the EC2 instance"
value = aws_instance.terraform_start_app_server.id
}
output "instance_public_ip" {
description = "Public IP address of the EC2 instance"
value = aws_instance.terraform_start_app_server.public_ip
}
variables.tf
terraform init
terraform fmt
terraform validate
terraform apply
terraform destroy