对于初学者,我有非常简单的Terraform设置-
main.tf-
provider "aws" {
access_key = var.access_key
secret_key = var.secret_key
region = var.region
version = "~> 2.8"
}
resource "terraform_remote_state" "vpc" {
backend = "s3"
config = {
bucket = var.vpc_bucket
region = var.region
key = var.vpc_bucket_key
}
}
和变量。tf-
variable "access_key" {
default = ""
}
variable "secret_key" {
default = ""
}
variable "vpc_bucket" {
default = "ops-bucket-0708"
}
variable "region" {
default = "ap-south-1"
}
variable "vpc_bucket_key" {
default = "aws/ap-south-1/VPCs/terraform.tfstate"
}
当我运行terraform plan
时,出现以下错误-
Error: Invalid resource type
on main.tf line 8, in resource "terraform_remote_state" "vpc":
8: resource "terraform_remote_state" "vpc" {
The provider provider.terraform does not support resource type
"terraform_remote_state".
我在这里做什么?
答案 0 :(得分:2)
terraform_remote_state是data
,而不是resource
。
因此,您可以尝试以下操作:
data "terraform_remote_state" "vpc" {
backend = "s3"
config = {
bucket = var.vpc_bucket
region = var.region
key = var.vpc_bucket_key
}
}