Terraform 中的 aws_launch_configuration 错误

Terraform 中的 aws_launch_configuration 错误

我稍微改变了Terraform 简介代码。我的目标是部署 Web 服务器集群 我的代码,main.tf

provider "aws" { region = "eu-central-1"}

resource "aws_launch_configuration" "example" {
    ami = "ami-df8406b0"
    image_id      = "${data.aws_ami.ubuntu.id}"
    instance_type = "t2.micro"
    vpc_security_group_ids = ["${aws_security_group.instance.id}"]

user_data = <<-EOF
   #!/bin/bash
   echo "Hello, World" > index.html
   nohup busybox httpd -f -p "${var.server_port}" &
   EOF

lifecycle {
    create_before_destroy = true
}   
}

variable "server_port" {
  description = "The port the server will use for HTTP requests"
  default = 8080
}


resource "aws_security_group" "instance" {
 name = "terraform-example-instance"
 ingress {
   from_port = "${var.server_port}"
   to_port = "${var.server_port}"
   protocol = "tcp"
   cidr_blocks = ["0.0.0.0/0"]
        }

lifecycle {
    create_before_destroy = true
} 

}

data "aws_ami" "ubuntu" {
  most_recent = true

  filter {
    name   = "name"
    values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
  }

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  owners = ["099720109477"] # Canonical
}


resource "aws_autoscaling_group" "example" {
    launch_configuration = "${aws_launch_configuration.example.id}"
    min_size = 2
    max_size = 10

    tag {
        key = "Name"
        value = "terraform-asg-example"
        propagate_at_launch = true
    }
}

当我去进行地形改造计划时

2 error(s) occurred:

* aws_launch_configuration.example: : invalid or unknown key: ami
* aws_launch_configuration.example: : invalid or unknown key: vpc_security_group_ids

我对数据有点困惑,它有什么用?我的错误在哪里?

答案1

错误在于您为aws_launch_configuration资源指定了两个无效的参数;即amivpc_security_group_ids,请参阅文档对于有效的事情。

我怀疑您已经从使用单一aws_instance资源转变为使用aws_launch_configuration资源,但它们使用的参数并不相同。

相关内容