Managing Applications and Infrastructure with Terraform-Deploying Infrastructure with Terraform-(2)Terraform for AWS-(10)Compute Part 2: The EC2 Instance
2018年10月04日
Managing Applications and Infrastructure with Terraform-Deploying Infrastructure with Terraform
2. Terraform for AWS
10. Compute Part 2: The EC2 Instance
Edit the compute/main.tf file.
#---compute/main.tf data "aws_ami" "server_ami" { most_recent = true owners = ["amazon"] filter { name = "owner-alias" values = ["amazon"] } filter { name = "name" values = ["amzn-ami-hvm*-x86_64-gp2"] } } resource "aws_key_pair" "tf_auth" { key_name = var.key_name public_key = file(var.public_key_path) } resource "aws_instance" "tf_server" { count = var.instance_count instance_type = var.instance_type ami = data.aws_ami.server_ami.id tags { Name = "tf_server-${count.index +1}" } key_name = aws_key_pair.tf_auth.id vpc_security_group_ids = [var.security_group] subnet_id = element(var.subnets, count.index) user_data = }