Referencing folder ID from module – 使用 Google Terraform 文件夹模块和项目因子模块。

huangapple go评论54阅读模式
英文:

Referencing folder ID from module - google terraform folders module and project factor module

问题

我使用了terraform模块terraform-google-modules/folders/googleterraform-google-modules/project-factory/google,但我无法弄清楚如何引用一个我需要在项目工厂模块中使用的已创建文件夹。输出似乎也是IDS而不是一个ID。
我想引用共用文件夹ID,以便我创建的项目位于正确的文件夹层次结构中。
我阅读了大量的文档并尝试寻找示例,但我找到的关于文件夹的一切都是文件夹资源而不是文件夹模块。

// 设置GCP中的文件夹结构
module "folders" {
  source  = "terraform-google-modules/folders/google"
  version = "~> 3.0"

  parent  = "folders/60860476666"

  names = [
    "development",
    "staging",
    "production",
    "common",
  ]

  set_roles = true

  prefix = "fldr"
  
  per_folder_admins = {
    dev = "group:gcp-organization-admins@mydomain.me"
    staging = "group:gcp-organization-admins@mydomain.me"
    production = "group:gcp-organization-admins@mydomain.me"
  }

  all_folder_admins = [
    "group:gcp-organization-admins@mydomain.me",
  ]
}

// 设置日志项目
module "project-factory-logging" {
  source                  = "terraform-google-modules/project-factory/google"
  version                 = "~> 14.0"
  random_project_id       = true
  name                    = "shared-logging"
  folder_id               = module.folders.????  // 这里填写你需要引用的文件夹的ID
  org_id                  = var.organization_id
  billing_account         = var.billing_account
  default_service_account = "deprivilege"
}

请注意,在folder_id字段中,你需要替换module.folders.????部分为你想要引用的文件夹的ID。

英文:

I use the terraform modules terraform-google-modules/folders/google and terraform-google-modules/project-factory/google and I cannot figure out how to reference one created folder that I need to use in the project factory module. The output seems to be IDS as well not one ID
https://registry.terraform.io/modules/terraform-google-modules/project-factory/google/latest
https://registry.terraform.io/modules/terraform-google-modules/folders/google/latest

I would like to reference the common folder ID so the project I create sits in the right folder hierarchy.
I read plenty of documentation and tried to find examples but everything I find around folders is the folder resources not folder module.

// setup folder structure in gcp
module "folders" {
  source  = "terraform-google-modules/folders/google"
  version = "~> 3.0"

  parent  = "folders/60860476666"

  names = [
    "development",
    "staging",
    "production",
    "common",
  ]

  set_roles = true

  prefix = "fldr"
  
  per_folder_admins = {
    dev = "group:gcp-organization-admins@mydomain.me"
    staging = "group:gcp-organization-admins@mydomain.me"
    production = "group:gcp-organization-admins@mydomain.me"
  }

  all_folder_admins = [
    "group:gcp-organization-admins@mydomain.me",
  ]
}

// setup logging project 
module "project-factory-logging" {
  source                  = "terraform-google-modules/project-factory/google"
  version                 = "~> 14.0"
  random_project_id       = true
  name                    = "shared-logging"
  folder_id               = module.folder**s.????**
  org_id                  = var.organization_id
  billing_account         = var.billing_account
  default_service_account = "deprivilege"
}

答案1

得分: 1

为了获取 common 文件夹,以下内容应该足够:

folder_id = module.folders.folders_map["common"].name
英文:

To get common folder it, the following should be enough:

folder_id               = module.folders.folders_map["common"].name

huangapple
  • 本文由 发表于 2023年2月19日 19:10:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75499696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定