我稍微修改了An Introduction to Terraform代码。我的目标是部署网络服务器集群我的代码,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
我对数据有点困惑,它有什么用?我的错误在哪里?
错误是您为
aws_launch_configuration
资源指定了两个无效的参数;即ami
andvpc_security_group_ids
,请参阅文档以了解有效内容。我怀疑您已经从使用单个
aws_instance
资源更改为使用aws_launch_configuration
资源,但是它们不使用相同的参数。