由于某些身份验证错误,带有gcp提供程序的terraform无法应用

时间:2020-01-23 08:45:00

标签: terraform terraform-provider-gcp

我有一个简单的代码,可以在Google云端上创建VPC,但是当我应用时,它会引发错误oauth2:无法获取令牌: 我已经创建了一个服务帐户,并将其分配给项目,网络,计算引擎,服务帐户令牌和服务帐户admin的编辑者角色。创建了一个密钥并下载了它的json。 我觉得我可能错过了一些我无法弄清的东西。

这是我的代码

  credentials = file("poc-dev-terrafrom-0ea89j6c1fce.json")
  project     = "dev-terrafrom"
  region      = "us-central1"
}
resource "google_compute_network" "vpc_network" {
  name = "GCPvpc"
  project = "dev-terrafrom "
  auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
  name          = "test-subnetwork"
  ip_cidr_range = "10.0.0.0/26"
  region        = "us-central1"
  network       = google_compute_network.vpc_network.self_link
}

upon apply get below error
  Enter a value: yes

google_compute_network.vpc_network: Creating...

Error: Error creating Network: Post https://www.googleapis.com/compute/v1/projects/dev-terrafrom%20/global/networks?alt=json: oauth2: cannot fetch token: Post https://oauth2.googleapis.com/token: x509: certificate signed by unknown authority

  on vpc.tf line 1, in resource "google_compute_network" "vpc_network":
   1: resource "google_compute_network" "vpc_network" {```

1 个答案:

答案 0 :(得分:0)

这是我的Linux机器问题,我更改了环境,然后代码正常工作,这很奇怪,为什么该机器对diff提供程序的作用如此不同。

data.template_file.credfile: Refreshing state...
google_compute_network.vpc_network: Creating...
google_compute_network.vpc_network: Still creating... [10s elapsed]
google_compute_network.vpc_network: Creation complete after 20s [id=projects/development-terrafrom/global/networks/myvpc]
google_compute_subnetwork.network-with-private-secondary-ip-ranges: Creating...
google_compute_subnetwork.network-with-private-secondary-ip-ranges: Still creating... [10s elapsed]
google_compute_subnetwork.network-with-private-secondary-ip-ranges: Creation complete after 17s [id=projects/dev-terrafrom/regions/us-central1/subnetworks/test-subnetwork]

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.