【发布时间】:2021-11-21 08:12:04
【问题描述】:
我正在学习如何使用 Terraform。我的目标是在 GCP 上部署架构,所以到目前为止,这是我的 main.tf:
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "3.85.0"
}
}
}
provider "google" {
credentials = file(var.credentials_file)
region = var.region
zone = var.zone
}
data "google_organization" "org" {
domain = var.organization.display_name
org_id = var.organization.id
directory_customer_id = var.organization.directory_customer_id
}
resource "google_folder" "shared" {
display_name = "Shared"
parent = google_organization.org_id
}
resource "google_folder" "ddm" {
display_name = "Data and Digital Marketing"
parent = google_folder.shared.name
}
resource "google_folder" "dtl" {
display_name = "DTL"
parent = google_folder.ddm.name
}
根据documentation,org_id 在属性参考内
但我收到以下错误:
╷
│ Error: Computed attributes cannot be set
│
│ with data.google_organization.org,
│ on main.tf line 17, in data "google_organization" "org":
│ 17: org_id = var.organization.id
│
│ Computed attributes cannot be set, but a value was set for "org_id".
╵
╷
│ Error: Computed attributes cannot be set
│
│ with data.google_organization.org,
│ on main.tf line 18, in data "google_organization" "org":
│ 18: directory_customer_id = var.organization.directory_customer_id
│
│ Computed attributes cannot be set, but a value was set for "directory_customer_id".
╵
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 22, in resource "google_folder" "shared":
│ 22: parent = google_organization.org_id
│
│ A managed resource "google_organization" "org_id" has not been declared in the root module.
我做错了什么?
【问题讨论】:
-
我猜你可能是在导入一个现有的 org id 到 Terraform 之后?您是在尝试创建一个新组织还是拥有一个现有组织并希望在 Terraform 中创建它?
-
我有一个 terraform 中的现有组织,但我想概述它,以及 main.tf 中的文件夹层次结构
-
@GrzegorzOledzki,老实说,我不确定我是否可以使用服务帐户来做到这一点。也许我需要一个通过超级管理员帐户应用的“引导”terraform,它可以导入组织并创建文件夹结构。另外,我还有另一个通过服务帐户在项目中创建项目和资源...你怎么看?
标签: terraform terraform-provider-gcp