terraform - 无法使用 terraform 导入 google 日志记录指标

标签 terraform

我在 terraform 中创建了以下日志记录指标资源

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"
  }
}

我还在 Stackdriver 上有一个名为 user/proservices-run 的自定义指标。

但是以下两次导入尝试失败:

$ 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

使用

Terraform v0.11.14

provider.google = 2.11.0
provider.google-beta 2.11.0

编辑:我注意到错误消息中的 project: required field is not set,我在 TF 代码中添加了字段 project ,但结果还是一样。

最佳答案

我在尝试导入基于日志的指标时遇到了同样的问题。

解决方案是设置环境变量 GOOGLE_PROJECT=<your-project-id>运行命令时。

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

关于terraform - 无法使用 terraform 导入 google 日志记录指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60618062/

相关文章:

terraform - Terraform 中的动态 map 创建

amazon-web-services - CodeBuild - 由于缺少 EC2 权限而构建失败

terraform - 如何定义 "azurerm_resource_group_template_deployment" "parameters_content"部分

amazon-web-services - 无法使用 terraform 从自动缩放 Hook 创建 sns

amazon-s3 - 在本地使用 terraform 从 S3 下载文件

azure - Terraform 条件参数 block

amazon-web-services - 如何将 event_api_destination 添加到 AWS 中的 cloudwatch 规则?

networking - 在带有 Terraform/KVM 的 CentOS 7 上使用 Cloud-Init 设置静态 IP

amazon-web-services - 在 Azure DevOps 上使用 Terraform 部署到 AWS 时的 AssumeRole

azure - 在 azure 上通过 Terraform 安装 DC/OS 时无法覆盖提供程序配置错误