hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.33k stars 1.73k forks source link

Allow google_project_service to accept google.project.id #7203

Closed ademariag closed 4 years ago

ademariag commented 4 years ago

Community Note

Terraform Version

Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/google v3.37.0
+ provider registry.terraform.io/hashicorp/google-beta v3.37.0
+ provider registry.terraform.io/hashicorp/random v2.3.0
+ provider registry.terraform.io/hashicorp/template v2.1.2

Affected Resource(s)

Terraform Configuration Files

{
    "resource": {
        "google_project": {
            "project": {
                "billing_account": "008F72-XXXX-XXXXX",
                "name": "Project Name",
                "org_id": "XXXXXX",
                "project_id": "a_project"
            }
        },
        "google_project_service": {
            "enable_cloudbilling_service": {
                "project": "${google_project.project.id}",
                "service": "cloudbilling.googleapis.com"
            }
        }
    }
}

Debug Output

Error: Provider produced inconsistent result after apply                                                                                               

When applying changes to google_project_service.enable_iamcredentials_service,
provider "registry.terraform.io/hashicorp/google" produced an unexpected new                                                                           
value: Root resource was present, but now absent.                                                                                                      

This is a bug in the provider, which should be reported in the provider's own                                                                          
issue tracker.  

Expected Behavior

google_project_service resource created

Actual Behavior

google_project_service resource is not being created

Steps to Reproduce

  1. terraform apply

Important Factoids

References

ademariag commented 4 years ago

I think this is somehow caused by the "project" key in the resource.

if I run it without, it works, e.g.:

{
    "resource": {
        "google_project": {
            "project": {
                "billing_account": "008F72-XXXX-XXXXX",
                "name": "Project Name",
                "org_id": "XXXXXX",
                "project_id": "a_project"
            }
        },
        "google_project_service": {
            "enable_cloudbilling_service": {
                // "project": "${google_project.project.id}",   REMOVE
                "service": "cloudbilling.googleapis.com"
            }
        }
    }
}

if I re-add, I get

  # google_project_service.enable_cloudbilling_service must be replaced
-/+ resource "google_project_service" "enable_cloudbilling_service" {
        disable_on_destroy = true
      ~ id                 = "a_project/cloudbilling.googleapis.com" -> (known after apply)
      ~ project            = "a_project" -> "projects/a_project" # forces replacement
        service            = "cloudbilling.googleapis.com"
    }
ademariag commented 4 years ago

The correct attribute to call is ${google_project.project.project_id} instead of ${google_project.project.id}

This resolves my issue, but I will leave this bug on for someone else to decide whether this behaviour is insane or working as intended.

edwardmedia commented 4 years ago

Below is what google_project provides. The formats of id and project are different. We should let google_project_service to accept both.

resource "google_project" "my_project" {
    id                  = "projects/myproject"
    name                = "myproject"
    project_id          = "myproject"
   .....
}
ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ā³. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error šŸ¤– šŸ™‰ , please reach out to my human friends šŸ‘‰ hashibot-feedback@hashicorp.com. Thanks!