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.32k stars 1.73k forks source link

google_logging_metric does not respect project field for imports #4460

Open umairidris opened 5 years ago

umairidris commented 5 years ago

Community Note

Terraform Version

0.12.6 (provider version 2.8.0)

Affected Resource(s)

Terraform Configuration Files

{
   "google_logging_metric": {
      "iam-policy-change-count": {
        "name": "iam-policy-change-count",
        "project": "REDACTED",
        "description": "Count of IAM policy changes.",
        "filter": "protoPayload.methodName=\"SetIamPolicy\" OR protoPayload.methodName:\".setIamPolicy\"",
        "metric_descriptor": {
        "metric_kind": "DELTA",
        "value_type": "INT64",
        "unit": "1",
        "labels": [
         {
          "key": "user",
          "value_type": "STRING",
          "description": "Unexpected user"
         }
        ]
       },
       "label_extractors": {
        "user": "EXTRACT(protoPayload.authenticationInfo.principalEmail)"
       }
      }
    }
}

Debug Output

Panic Output

Expected Behavior

Import should have succeeded.

Actual Behavior

Import raised error:

Error: project: required field is not set

Steps to Reproduce

  1. terraform import google_logging_metric.iam-policy-change-count iam-policy-change-count

Important Factoids

References

b/299443214

umairidris commented 5 years ago

Same for google_monitoring_notification_channel.

slevenick commented 5 years ago

I'm looking at adding import formats for both of these that accept project as well. The import format will change, looking something like terraform import google_logging_metric.iam-policy-change-count my-project/iam-policy-change-count

As a workaround you can set your provider default project to the project these resources live in and import should work

umairidris commented 5 years ago

Thanks Sam. I have already been using the workaround, but thought it's worth filing a bug as it was an unexpected behaviour.

Changing import format SGTM.

tanjinP commented 4 years ago

Any progress on this? The suggested workaround is giving me the same error:

Error: project: required field is not set
sebglon commented 4 years ago

If you set the project and the metric name between double quote and with space, the import work well. Example:

terraform import google_logging_metric.iam-policy-change-count "my-project iam-policy-change-count"
sebglon commented 4 years ago

A good fix can be to add a new import format on this resource like say @slevenick