terraform变量不适用于apply

时间:2018-02-01 08:40:46

标签: terraform

当运行terraform对以下内容应用时,它一直要求我在CLI上输入变量而不是从文件中接受,如果我从.tf文件中删除变量并且只留下第一个用于ami的变量一些按摩。有任何想法吗?

dev.tf的内容:

variable "aws_region" {}
variable "instance_type" {}
variable "key_name" {}
variable "vpc_security_group_ids" {}
variable "subnet_id" {}
variable "iam_instance_profile" {}
variable "tag_env" {}

provider "aws" {
  region = "${var.aws_region}"
}

data "aws_ami" "amazon_linux" {
  most_recent = true

  filter {
    name = "name"

    values = [
      "amzn-ami-hvm-*-x86_64-gp2",
    ]
  }

  filter {
    name = "owner-alias"

    values = [
      "amazon",
    ]
  }
}

resource "aws_instance" "kafka" {
  ami              = "${data.aws_ami.amazon_linux.id}"
  instance_type          = "${var.instance_type}"
  subnet_id              = "${var.subnet_id}"
  key_name               = "${var.key_name}"
  vpc_security_group_ids = ["${var.vpc_security_group_ids}"]
  iam_instance_profile   = "${var.iam_instance_profile}"



  user_data = <<-EOF
              #!/bin/bash
              sudo yum -y install telnet  
              EOF



  tags {
    ProductCode = "id"
    InventoryCode = "id"
    Environment = "${var.tag_env}"
  }
}

dev.tfvars的内容:

aws_region = "us-east-1"
tag_env = "dev"
instance_type = "t2.large"
subnet_id = "subnet-id"
vpc_security_group_ids = "sg-id , sg-id"
key_name = "id"
iam_instance_profile = "id"

1 个答案:

答案 0 :(得分:1)

Ah good catch, changed the filename to terraform.tfvars and it now works.