我为初学者提供了非常简单的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".
我在这里干什么?
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
}
}
我也面临类似的问题。我只使用数据。错误是-提供程序hashicorp/aws不支持数据源│ "地形_移动_状态";。我还强调;"地形_移动_状态";可用作地形提供程序,而不是aws。然而,这应该是默认的,不需要任何提供者。