首页 > 解决方案 > 使用 Terraform 创建 AWS-OPSWORK-STACK 时出错

问题描述

在使用 terraform 和以下代码创建堆栈时出现此错误

错误:加载 /root/terraform-stack-creation/main.tf 时出错:位置 2:10:资源必须紧跟两个字符串,一个类型和一个名称

resource "aws_opsworks_stack" "stack" {
  name = "${var.name}"
  region = "${var.region}"
  service_role_arn = "${var.service_role_arn}"
  default_instance_profile_arn = "${var.instance_profile_arn}"
  default_os = "Amazon Linux 2018.03"
  configuration_manager_version = "11.10"
  manage_berkshelf = false
  default_root_device_type = "ebs"
  use_opsworks_security_groups = false
  vpc_id = "vpc-******************"
  default_subnet_id = "subnet-*****************"
  custom_json = "{}"
}

variable "name" {
    type = "string"
    description = "Name (Your required stack name)"
    }
variable "region" {
    type = list(string)
    default = ["us-west-1a"]
    description = "us-east-1,ap-south-1,ap-southeast-2,eu-central-1 (Give your region)"
    }
variable "service_role_arn" {
    type = list(string)
    default = ["*********************"]
    description = "Default IAM role"
    }
variable "default_instance_profile_arn"{
    type = list(string)
    default = ["*************************"]
    description = "Default IAM instance profile"
    }
variable "default_availability_zone" {
    type = "string"
    description = "Give your availabity zone"
    }

标签: terraformterraform-provider-aws

解决方案


该变量name未设置为任何值。

您需要:

a) 设置默认值name

b)name通过环境变量命令行TF_INPUT=falseor-input=false、或其他方法设置变量


推荐阅读