我目前擁有自定義的AWS AMI映像,而Terraform無法在user_data節中執行腳本或內聯代碼。它適用於AWS AMI映像,但不適用於我使用自己的映像。Terraform AWS user_data不能與自定義AMI映像一起使用
data "template_file" "user_data" {
template = "${file("sample")}"
}
resource "aws_launch_configuration" "test" {
image_id = "ami-xxxxxx"
instance_type = "t2.medium"
security_groups = ["xxxxx", "xxxxxxx"]
key_name = "xxxxxxx"
}
resource "aws_instance" "ZC1" {
ami = "ami-xxxxxxx" #ZC AMI IMAGE
instance_type = "t2.medium"
subnet_id = "subnet-xxxxx"
private_ip = "x.x.x.x"
key_name = "xxxxxx"
vpc_security_group_ids = ["xxxxx", "xxxxxxx"]
user_data = "${data.template_file.user_data.rendered}"
tags {
"Name" = "Terraform Script Test"
}
}
當您在「user_data」部分中說「腳本或內聯代碼」時,是否指'#cloud-config'代碼段?這種配置通常由'cloud-init'軟件包進行處理,並且需要在映像上進行安裝和配置(在大多數流行的AMI上默認可用)。你可以編輯你的問題,提供更多關於AMI是如何構建或來自哪裏以及user_data是什麼樣子的信息? –
試試這個https://stackoverflow.com/questions/33690287/how-to-install-aws-cfn-bootstrap-cfn-init-package-in-redhat-using-cloudformation – Gangaraju