terraform-google-modules / terraform-google-project-factory

Creates an opinionated Google Cloud project by using Shared VPC, IAM, and Google Cloud APIs
https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
Apache License 2.0
826 stars 535 forks source link

tag_binding_values not working in "terraform-google-modules/project-factory/google" #929

Open marce1990 opened 1 month ago

marce1990 commented 1 month ago

TL;DR

When adding the variable "tag_binding_values" a list of strings (example - ["test"]) is returning an error: Error: Error creating TagBinding: googleapi: Error 400: com.google.apps.framework.request.StatusException: generic::INVALID_ARGUMENT: Invalid CRM resource name

Expected behavior

Expected behavior is to create the tags to the project but is returning an error, maybe is not documented how to use it properly

Observed behavior

module.avm-project.module.project-factory.google_tags_tag_binding.bindings["test"]: Creating... ╷ │ Error: Error creating TagBinding: googleapi: Error 400: com.google.apps.framework.request.StatusException: generic::INVALID_ARGUMENT: Invalid CRM resource name: 'tagValues/test'. │ │ with module.avm-project.module.project-factory.google_tags_tag_binding.bindings["test"], │ on .terraform/modules/avm-project/modules/core_project_factory/main.tf line 386, in resource "google_tags_tag_binding" "bindings": │ 386: resource "google_tags_tag_binding" "bindings" {

Terraform Configuration

terraform {
  required_version = ">=0.13.0"
  required_providers {
    google = {
      source  = "hashicorp/google"
      version = "~> 5.36"
    }
  }
  backend "gcs" {}
}

Terraform Version

Terraform v1.4.7
on linux_amd64
+ provider registry.terraform.io/hashicorp/google v5.38.0
+ provider registry.terraform.io/hashicorp/google-beta v5.38.0
+ provider registry.terraform.io/hashicorp/null v3.2.2
+ provider registry.terraform.io/hashicorp/random v3.6.2
+ provider registry.terraform.io/hashicorp/time v0.11.2

Additional information

No response

bharathkkb commented 3 weeks ago

Hi @marce1990 could you provide your configuration where you are passing in the tag value? tagValues/test seems like a potentially invalid value. It should be using the numeric generated name from this computed field https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/tags_tag_value#name

marce1990 commented 3 weeks ago

Hi @bharathkkb thanks for the answer, if I use the resources provided by terraform: resource "google_tags_tag_key" + resource "google_tags_tag_value" I'm sure it will work.

What I'm trying to use is the tag option in the module "terraform-google-modules/project-factory/google", that if I'm not wrong there is an example of how to use it here: https://github.com/terraform-google-modules/terraform-google-project-factory/blob/master/examples/tags_project/README.md#project-with-tags

The problem is when I replicate what I see in the main.tf example: https://github.com/terraform-google-modules/terraform-google-project-factory/blob/master/examples/tags_project/main.tf

I'm suppose to add this line to the module:

module "project-factory" {
  source  = "terraform-google-modules/project-factory/google"
  version = "~> 15.0"

  random_project_id       = true
  name                    = "simple-tag-project"
  org_id                  = var.organization_id
  folder_id               = var.folder_id
  billing_account         = var.billing_account
  default_service_account = "deprivilege"
  tag_binding_values      = [var.tag_value]
}

But when I do this, is not working, whatever you write in the tag_value variable, that is supposed to be a string value:

variable "tag_value" {
  description = "value"
  type        = string
}

I just copy and paste here:

image

Once you perform a terraform plan this is how it looks like:

image

And then when you launch the terraform apply (in this case I wrote "testvalue" but same error):

image

So maybe I'm not doing it right and I should provide a different input to the tag variable, but I tried many and none of them are working.