我正在尝试实现某种机制,让某人可以填写一个变量,该变量定义是要部署 Amazon Linux 机器还是自行创建的打包机。但由于某种原因,它在找到我自己的 AMI 的同时却没有找到 AWS AMI。这是代码:
模块的Main.tf:
data "aws_ami" "latest" {
most_recent = true
owners = [var.owner]
filter {
name = "name"
values = [lookup(var.default_ami, var.ami)]
}
}
resource "aws_instance" "test-ec2deployment" {
ami = data.aws_ami.latest.id
Run Code Online (Sandbox Code Playgroud)
变量.tf:
variable "default_ami" {
type = map
description = "Choose windows 2016 or 2019"
default = {
"2016" = "WIN2016-CUSTOM*"
"2019" = "WIN2019-CUSTOM*"
"linux" = "ami-0fb02dcdd38048fb9"
}
}
#Above are the options, here you need to make a decision.
variable "ami" {
description …Run Code Online (Sandbox Code Playgroud) amazon-web-services terraform terraform-provider-aws terraform0.12+