profile
viewpoint

Ask questionsError in Terraform 0.12.0: This object has no argument, nested block, or exported attribute

Terraform Version

0.12.0

Issue

Hi, when I run terraform plan on one of the config files, I get the following error

Error: Unsupported attribute

  on main.tf line 16, in module "project_01":
  16:   folder_id = "${data.terraform_remote_state.folders.folder_shared_id}"

This object has no argument, nested block, or exported attribute named
"folder_shared_id".

make: *** [plan] Error 1

Here is the main.tf file

data "terraform_remote_state" "folders" {
  backend = "local"
  config = {
    path = "../../folders/terraform.tfstate"
  }
}
...
<extraneous-code>
...
module "project_01" {
  source = "<path-to-module>"

  project_name = "network"
  folder_id = "${data.terraform_remote_state.folders.folder_shared_id}"
}

However, that attribute is present in the terraform.tfstate file


$ cat terraform.tfstate
{
  "version": 4,
  "terraform_version": "0.12.0",
  "serial": 9,
  "lineage": "76c68f13-3a49-4db0-2a95-84ef9610cefa",
  "outputs": {
    "folder_test1_id": {
      "value": "folders/***",
      "type": "string"
    },
    "folder_test2_id": {
      "value": "folders/****",
      "type": "string"
    },
    "folder_shared_id": {
      "value": "folders/****",
      "type": "string"
    }

This used to work in Terraform 0.11.13 but broke in Terraform 0.12.0. Any ideas why this is happening?

hashicorp/terraform

Answer questions relgisri

Thank you very much @apparentlymart I had the same problem and your explanation helped me fixing a big chunk of it. It seems tho that the documentation is lacking the new configuration of TF 0.12.

Currently I have a problem created by the terraform_remote_state.

I have one folder where I create my GCP VPC

resource "google_compute_network" "default" {
  provider                = google-beta
  project                 = var.project
  name                    = "${var.name}-net"
  auto_create_subnetworks = "false"
}

resource "google_compute_subnetwork" "subnet_vpc" {
  provider                 = google-beta
  project                  = var.project
  name                     = "${var.name}-subnet-vpc"
  network                  = google_compute_network.default.self_link
  region                   = var.project_region
  ip_cidr_range            = var.cidr
  private_ip_google_access = true

  secondary_ip_range {
    range_name    = "${var.name}-secondary-cidr"
    ip_cidr_range = var.subnet["secondary_cidr"]
  }
}

with the output

output "link" {
  value = "${google_compute_network.default.self_link}"
}

and a folder for my cloudsql with following code:

data "terraform_remote_state" "vpc" {
    backend = "gcs"
    config = {
        bucket  = "tfstate-test-eu"
        prefix  = "test/vpc"
  }
}

resource "google_compute_global_address" "cloudsql_ip_address" {
  provider      = google-beta
  project       = var.project
  name          = "${var.name}-sql-iip"
  purpose       = "VPC_PEERING"
  address_type  = "INTERNAL"
  prefix_length = 16
  network       = "${data.terraform_remote_state.vpc.outputs.link}"
}

resource "google_service_networking_connection" "cloudsql_vpc_connection" {
  provider                = google-beta
  network                 = "${data.terraform_remote_state.vpc.outputs.link}"
  service                 = "servicenetworking.googleapis.com"
  reserved_peering_ranges = [google_compute_global_address.cloudsql_ip_address.name]
}

both folders save the tfstate in the same bucket but with a different prefix:

vpc:

terraform {
  backend "gcs" {
    bucket  = "tfstate-test-eu"
    prefix  = "test/vpc"
  }
}

cloudsql:

terraform {
  backend "gcs" {
    bucket  = "tfstate-test-eu"
    prefix  = "test/sql"
  }
}

now everytime I want to apply my terraform plan for the cloudsql, to add that ip-address to my vpc, my terraform wants to destroy the vpc but add the ip-address

  # google_compute_global_address.cloudsql_ip_address will be created
  + resource "google_compute_global_address" "cloudsql_ip_address" {
      + address            = (known after apply)
      + address_type       = "INTERNAL"
      + creation_timestamp = (known after apply)
      + id                 = (known after apply)
      + label_fingerprint  = (known after apply)
      + name               = "tf-test-sql-iip"
      + network            = "https://www.googleapis.com/compute/v1/projects/example/global/networks/tf-test-net"
      + prefix_length      = 16
      + project            = "example"
      + purpose            = "VPC_PEERING"
      + self_link          = (known after apply)
    }

  # google_compute_network.default will be destroyed
  - resource "google_compute_network" "default" {
      - auto_create_subnetworks         = false -> null
      - delete_default_routes_on_create = false -> null
      - id                              = "tf-test-net" -> null
      - name                            = "tf-test-net" -> null
      - project                         = "example" -> null
      - routing_mode                    = "REGIONAL" -> null
      - self_link                       = "https://www.googleapis.com/compute/v1/projects/example/global/networks/tf-test-net" -> null
    }

is this a problem with my terraform plan / design or something related to a bug ?
My expected behavior would be, that Terraform checks the remote backend and finds my vpc_self_link, which he uses to add the cloudsql ip-address into that vpc.

Plan: 1 to add, 0 to change, 1 to destroy.
useful!
source:https://uonfu.com/
Github User Rank List