【发布时间】:2019-09-20 02:22:22
【问题描述】:
在使用 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"
}
【问题讨论】:
-
当你定义一个没有类型和名称的资源时会发生错误(如错误所暗示的),在它之后用双引号括起来,例如
resource "type" "name"。但是,您提供的代码没有这个问题。你确定那个代码有那个确切的错误吗?aws_opsworks_stack资源在 main.tf 文件的第 2 行吗?
标签: terraform terraform-provider-aws