我正在尝试使用terraform创建Google Cloud项目。我正在参考以下链接作为参考...
https://femrtnz.medium.com/automating-gcp-projects-with-terraform-d571f0d94742
我按照介绍的项目创建和IAM角色的步骤进行操作。似乎你需要一个单独的项目和服务账户来使用terraform创建项目。我还参考了谷歌关于此主题的文档...
https://cloud.google.com/community/tutorials/managing-gcp-projects-with-terraform
所以,我在我的main.tf中得到了这个配置。
# This is the provider used to spin up the gcloud instance
provider "google" {
credentials = "/path/to/seed-credentials.json"
}
# Locks the version of Terraform for this particular use case
terraform {
required_version = "0.14.6"
}
resource "random_id" "id" {
byte_length = 4
prefix = var.project_name
}
resource "google_project" "project" {
name = var.project_name
project_id = random_id.id.hex
billing_account = var.billing_account
}
output "project_id" {
value = google_project.project.project_id
}
我创建了一个远程后端。
terraform {
backend "gcs" {
bucket = "seed-bucket"
prefix = "terraform/state"
credentials = "/path/to/seed-credentials.json"
}
}
以下是我的variables.tf文件
variable "project_name" {
type = string
}
variable "billing_account" {
type = string
}
最后但同样重要的是我的terraform.tfvars文件。
project_name = "test-project"
billing_account = "1234-5678-90xxx"
Terraform init会配置远程后端。Terraform plan没有错误。但是,当我运行terraform apply时,出现以下错误:"Error: failed pre-requisites: missing permission on "billingAccounts/1234-5678-9xxx": billing.resourceAssociations.create"。 现在,这个账户没有组织。我猜这就是给我带来的错误? Medium博客文章的作者提到了“首先你需要创建一个基于你的域名的组织”。 我从未在我的Google项目中使用过组织。我进入我的Google控制台,它说我需要域验证才能为我的账户获得组织。这似乎很麻烦。我真的不想为此费力去获取一个新的域名。现在我的代码正确吗?我猜测错误源于我没有“组织”。是否有一种简单的方法可以不进行域验证就获得组织?