Error: This object does not have an attribute named "subnetwork_self_links"

34 views Asked by At

I am using the below Terraform code to deploy a managed instance group on GCP. Referencing existing data using data sources, where data sources let you retrieve information from existing Google Cloud resources.

resource "google_compute_instance_template" "this" {
  name_prefix  = var.mig.instance_template_name_prefix
  region       = var.region
  machine_type = var.mig.machine_type
  disk {
    source_image = var.mig.source_image
  }
  network_interface {
    subnetwork = data.terraform_remote_state.foundation.outputs.subnetwork_self_links["iowa"]
    access_config {
      // Ephemeral public IP
    }
  }
  metadata_startup_script = file("startup.sh")
  tags = [
    "allow-iap",
    "allow-health-check"
  ]
  service_account {
    email  = data.terraform_remote_state.foundation.outputs.service_account_email
    scopes = ["cloud-platform"]
  }
  lifecycle {
    create_before_destroy = true
  }
}
resource "google_compute_region_instance_group_manager" "this" {
  name               = var.mig.mig_name
  region             = var.region
  base_instance_name = var.mig.mig_base_instance_name
  target_size        = var.mig.target_size
  version {
    instance_template = google_compute_instance_template.this.id
  }
  named_port {
    name = "http"
    port = 80
  }
  update_policy {
    type            = "PROACTIVE"
    minimal_action  = "REPLACE"
    max_surge_fixed = 3
  }
}

However, I am getting the Unsupported attribute as below. Does anyone have any suggestions?

Plan: 1 to add, 0 to change, 0 to destroy.
╷
│ Error: Unsupported attribute
│ 
│   on mig.tf line 12, in resource "google_compute_instance_template" "this":
│   12:     subnetwork = data.terraform_remote_state.foundation.outputs.subnetwork_self_links["iowa"]
│     ├────────────────
│     │ data.terraform_remote_state.foundation.outputs is object with no attributes
│ 
│ This object does not have an attribute named "subnetwork_self_links".
╵
╷
│ Error: Unsupported attribute
│ 
│   on mig.tf line 25, in resource "google_compute_instance_template" "this":
│   25:     email  = data.terraform_remote_state.foundation.outputs.service_account_email
│     ├────────────────
│     │ data.terraform_remote_state.foundation.outputs is object with no attributes
│ 
│ This object does not have an attribute named "service_account_email".
0

There are 0 answers