pkaramol
pkaramol

Reputation: 19312

Unable to import google logging metric using terraform

I have created in terraform the following logging metric resource

resource "google_logging_metric" "proservices_run" {
  name   = "user/proservices-run"
  filter = "resource.type=gae_app AND severity>=ERROR"
  project = "${google_project.service.project_id}"
  metric_descriptor {
    metric_kind = "DELTA"
    value_type  = "INT64"
  }
}

I have also on Stackdriver a custom metric named user/proservices-run.

However the following two import attempts fail:

$ terraform import google_logging_metric.proservices_run proservices-run

google_logging_metric.proservices_run: Importing from ID "proservices-run"...
google_logging_metric.proservices_run: Import complete!
  Imported google_logging_metric (ID: proservices-run)
google_logging_metric.proservices_run: Refreshing state... (ID: proservices-run)

Error: google_logging_metric.proservices_run (import id: proservices-run): 1 error occurred:
    * import google_logging_metric.proservices_run result: proservices-run: google_logging_metric.proservices_run: project: required field is not set

$ terraform import google_logging_metric.proservices_run user/proservices-run

google_logging_metric.proservices_run: Importing from ID "user/proservices-run"...
google_logging_metric.proservices_run: Import complete!
  Imported google_logging_metric (ID: user/proservices-run)
google_logging_metric.proservices_run: Refreshing state... (ID: user/proservices-run)

Error: google_logging_metric.proservices_run (import id: user/proservices-run): 1 error occurred:
    * import google_logging_metric.proservices_run result: user/proservices-run: google_logging_metric.proservices_run: project: required field is not set

Using

Terraform v0.11.14

and

provider.google = 2.11.0
provider.google-beta 2.11.0

edit: I noticed the project: required field is not set in the error message, I added the field project in my TF code, however the outcome is still the same.

Upvotes: 2

Views: 1017

Answers (1)

Matthew
Matthew

Reputation: 25743

I ran into the same issue trying to import a log-based metrics.

The solution was to set the env-var GOOGLE_PROJECT=<your-project-id> when running the command.

GOOGLE_PROJECT=MyProjectId \
  terraform import \
  "google_logging_metric.create_user_count" \
  "create_user_count"

Upvotes: 2

Related Questions