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

project_name Output Incorrect if using random_project_id #731

Closed ikegentz closed 2 years ago

ikegentz commented 2 years ago

TL;DR

The project_name output does not include the random suffix that gets appended if setting random_project_id to true. This means that there is no way to grab the full project's ID from the outputs, since project_id is not set as an output if left blank.

Expected behavior

project_name should include the random 4-character suffix that gets appended when random_project_id is true

Observed behavior

project_name is only set to whatever the name input is set to, and doesn't include the random_project_id suffix

Terraform Configuration

Using Terragrunt:

terraform {
  source = "tfr:///terraform-google-modules/project-factory/google?version=13.0.0"
}

inputs = {
  auto_create_network = false
  name = "${path_relative_to_include("root")}"
  enable_shared_vpc_host_project = true
  folder_id = "${include.root.locals.user_vars.user_folder}"
  random_project_id = true
  org_id = "${include.root.locals.dev_vars.org_id}"
  usage_bucket_name = "${include.root.locals.dev_vars.environment}-tfstate-${include.root.locals.dev_vars.region}-${include.root.locals.user_vars.user_name}"
  usage_bucket_prefix = "${path_relative_to_include("root")}/terraform-new.tfstate"
  billing_account = "${include.root.locals.dev_vars.billing_account_id}"
  activate_apis = [
    "iam.googleapis.com",
    "cloudbilling.googleapis.com",
    "container.googleapis.com"
  ]
}

Terraform Version

1.2.3

Terragrunt version: 0.38.0

Additional information

The workaround is to set project_id to the same thing as name. Is that intended?

bharathkkb commented 2 years ago

@ikegentz I am not sure I follow, there should always be a project_id output even if you don't provide a project_id input.

ikegentz commented 2 years ago

That's correct, it will output but the project_id variable doesn't show the suffix added to the project.

So instead of project_id == name + suffix, it is just name

bharathkkb commented 2 years ago

@ikegentz Could you show a sample without Terragrunt? I have not encountered this. We pass in a local that has a random suffix and use that same attrib as the op. https://github.com/terraform-google-modules/terraform-google-project-factory/blob/b024e5cf2bedb2e1df08baceb837e80c89d68cd8/modules/core_project_factory/main.tf#L32-L36

bharathkkb commented 2 years ago

Feel free to reopen if still an issue