我正在尝试编写ec2模块,目前我被用户数据卡住了。
resource "aws_instance" "jumphost" {
ami = "${var.ami}"
instance_type = "${var.instancetype}"
availability_zone = "${var.availability_zone}"
key_name = "${var.key}"
subnet_id = join(",", var.subnet)
associate_public_ip_address = "true"
vpc_security_group_ids = "${var.vpc_security_group_ids}"
iam_instance_profile = "${var.iam_instance_profile}"
user_data = <<EOF
#!/bin/bash -x
echo "======USER SCRIPT START==========="
touch /tmp/somename
echo "======USER SCRIPT END==========="
EOF
tags = {
Name = "${var.name}"
}
}
我看不出这个特定的user_data块没有被执行的原因。
除了这些命令之外,您的缩进是不正确的。应该是:
resource "aws_instance" "jumphost" {
ami = "${var.ami}"
instance_type = "${var.instancetype}"
availability_zone = "${var.availability_zone}"
key_name = "${var.key}"
subnet_id = join(",", var.subnet)
associate_public_ip_address = "true"
vpc_security_group_ids = "${var.vpc_security_group_ids}"
iam_instance_profile = "${var.iam_instance_profile}"
user_data = <<EOF
#!/bin/bash -x
echo "======USER SCRIPT START==========="
touch /tmp/somename
echo "======USER SCRIPT END==========="
EOF
tags = {
Name = "${var.name}"
}
}
除此之外,您必须通过检查/var/log/cloud-init-output.log
来调试用户数据,因为只有您才能访问您的实例。