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

error with google_tags_location_tag_binding #14932

Closed ghost closed 1 year ago

ghost commented 1 year ago

Community Note

Terraform Version

1.3.4

Affected Resource(s)

Terraform Configuration Files

resource "google_tags_location_tag_binding" "dataset" {
  for_each = local.tag_bind_dataset

  parent    = "//bigquery.googleapis.com/projects/${data.google_project.default.id}/datasets/${each.value.dataset_id}"
  tag_value = google_tags_tag_value.default[each.value.tag_value].id
  location  = each.value.location
}

resource "google_tags_location_tag_binding" "bucket" {
  for_each = local.tag_bind_bucket

  parent    = "//storage.googleapis.com/projects/_/buckets/${each.bucket}"
  tag_value = google_tags_tag_value.default[each.value.tag_value].id
  location  = each.value.location
}

Debug Output

β”‚ Error: Error when reading or editing TagsLocationTagBinding "asia-northeast1/tagBindings/<dataset or bucket full resource name>/tagValues/12345567890": googleapi: Error 400: Request contains an invalid argument.
β”‚ Details:
β”‚ [
β”‚   {
β”‚     "@type": "type.googleapis.com/google.rpc.BadRequest",
β”‚     "fieldViolations": [
β”‚       {
β”‚         "description": "Must be a valid One Platform resource name of a tag compatible regional resource",
β”‚         "field": "binding.resource"
β”‚       },
β”‚       {
β”‚         "description": "Resource type not supported in location asia-northeast1",
β”‚         "field": "binding.resource"
β”‚       }
β”‚     ]
β”‚   }
β”‚ ]

Panic Output

Expected Behavior

terraform plan exits without error

Actual Behavior

end with error in terraform plan

Steps to Reproduce

  1. terraform plan

Important Factoids

i had imported google_tags_location_tag_binding with terraform import and tried terraform plan to check if the import was successful the result was an error, so when I checked the log with TF_LOG=DEBUG, i had found that provider had accessed to the url https://asia-northeast1-cloudresourcemanager.googleapis.com//v3/tagBindings/?alt=json&pageSize=300&parent=

upon careful checking the url, I got that the parent was not set (parent set in terraform resource does not seem to be set)

References

edwardmedia commented 1 year ago

@lpqI can you see if below docs are helpful?

https://cloud.google.com/resource-manager/docs/tags/tags-supported-services

https://cloud.google.com/iam/docs/full-resource-names

For me, it works with below config. Make sure the dataset resides at the same region as what the location was given

resource "google_tags_location_tag_binding" "binding" {
    parent    = "//bigquery.googleapis.com/projects/myproject/datasets/issue14932"
    tag_value = "tagValues/${google_tags_tag_value.value.name}"
    location  = "us-central1"
}

For import, below command works for me

terraform import google_tags_location_tag_binding.binding us-central1/tagBindings/%2F%2Fbigquery.googleapis.com%2Fprojects%2Fmyproject%2Fdatasets%2Fissue14932/tagValues/281475794261234
ghost commented 1 year ago

@edwardmedia thanks for your reply

unfortunately, the link you suggested didn't work

i could successfully import the resource but I got the above error when I ran terraform plan to make sure it was imported correctly

edwardmedia commented 1 year ago

@lpqI how did you create the resource? Can you share the state of the imported one? Can you share the config for your terraform plan?

ghost commented 1 year ago

@edwardmedia thanks for your reply

how did you create the resource?

i created these resources manually import is executed after creating

Can you share the state of the imported one?

Can you share the config for your terraform plan ?

i didn't use option for terraform plan

edwardmedia commented 1 year ago

@lpqI have you tried updating the config with all the attributes you got from the imported and then run plan? The states look fine with me.

ghost commented 1 year ago

@edwardmedia thanks for your reply

i guess i am doing what you told me to do i had configure all parameters shown URL below, run import and plan https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/google_tags_location_tag_binding

ghost commented 1 year ago

@edwardmedia i had tried remove tfstate and import again, but i got same errors i used provider with version 4.69.1

provider "registry.terraform.io/hashicorp/google" {
  version = "4.69.1"
}
edwardmedia commented 1 year ago

@lpqI I assume you have updated the config before you run terraform plan, right? Can you share the debug log for both import and plan?

ghost commented 1 year ago

@edwardmedia log files are here logs.zip

please check it

edwardmedia commented 1 year ago

@lpqI it looks like the provider was failing on finding the parent. As I mentioned earlier, did you update the config before you run terraform plan?

resource "google_tags_location_tag_binding" "dataset" {
  parent    = <---- did you provide a value here when you run plan
....
}
ghost commented 1 year ago

@edwardmedia

did you update the config before you run terraform plan ?

yes, i am using csv to set the value specific values are

resource "google_tags_location_tag_binding" "dataset" {
  parent    = "//bigquery.googleapis.com/projects/test-project/datasets/all_c"
  tag_value = "tagValues/1234567890"
  location  = "asia-northeast1"
}
edwardmedia commented 1 year ago

@lpqI I don't understand what you meant below. Your config is is similar to what I provided which works for me. I have no clue why it doesn't work for you. Keep in mind, the error appears to complain about the value of parent. I would suggest you hardcode the config to see it works

yes, i am using csv to set the value
ghost commented 1 year ago

@edwardmedia

I would suggest you hardcode the config to see it works

i will try

ghost commented 1 year ago

@edwardmedia thanks for your advice

however, the cause of the error was not the for_each using CSV, but the import performed by another worker it seems that an error occurred because a tag that does not exist was imported with tag_bind β†’it worked fine after removing wrongs from tfstate file

edwardmedia commented 1 year ago

@lpqI cool. Glad you have seen where is the problem. Any more issues (questions)?

ghost commented 1 year ago

@edwardmedia thanks for your asking me

i guess this is the root cause of this issue that it was able to import tag_bind that does not exist

for example, if dataset as all_c with tag_value tv1 is correct pairs, but pair of all_c and tv2 that does not exist was able to import (i got type.googleapis.com/google.rpc.BadRequest errors after importing)

i want error message with wrong pair, but i ended up importing successfully

edwardmedia commented 1 year ago

@lpqI Cool, closing the issue now. Thanks

github-actions[bot] commented 1 year 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.