Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output value is not found #1406

Closed
zli82016 opened this issue Jan 3, 2025 · 1 comment
Closed

Output value is not found #1406

zli82016 opened this issue Jan 3, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@zli82016
Copy link

zli82016 commented Jan 3, 2025

SDK version

github.com/hashicorp/terraform-plugin-sdk/v2 v2.33.0

Relevant provider source code

https://github.com/hashicorp/terraform-provider-google/blob/main/google/services/compute/data_source_google_compute_instance.go#L18

Terraform Configuration Files

resource "google_compute_instance" "test-vm-1" {
  name         = "test-vm-10111701"
  machine_type = "n2-standard-2"
  zone         = "us-central1-a"

allow_stopping_for_update = true

  metadata = {
    foo = "bar"
  }

  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-2204-lts"
    }
  }

  network_interface {
    network = "default"
    access_config { }
  }

  service_account {
    email = data.google_compute_default_service_account.default.email
    scopes = [
                "https://www.googleapis.com/auth/logging.write",
            "https://www.googleapis.com/auth/monitoring.write",
    ]
  } 
    
metadata_startup_script = <<-EOT
    #!/bin/bash
    # Update and install necessary packages
    sudo su
    sudo apt update && sudo apt upgrade -y
  EOT 
      
}   

data "google_compute_instance" "iavm_node" {
  name = "${google_compute_instance.test-vm-1.name}"
  zone = "${google_compute_instance.test-vm-1.zone}"
}
  
output "instance_id" {
  value = "${data.google_compute_instance.iavm_node.self_link}"
}

Debug Output

Expected Behavior

terraform output instance_id shows the value of self_link

Actual Behavior

terraform output instance_id

│ Warning: No outputs found

But self_link has the value with the command terraform state show data.google_compute_instance.iavm_node

data "google_compute_instance" "iavm_node" {
    self_link                  = "https://www.googleapis.com/compute/v1/projects/xxxx/zones/us-central1-a/instances/test-vm-10111701"
}

Steps to Reproduce

  1. terraform apply

Question

How the output value is evaluated here and what is the reason that the output value doesn't have value?

self_link is an optional field in the data source google_compute_instance. I am not sure if that is the reason.

@zli82016 zli82016 added the bug Something isn't working label Jan 3, 2025
@austinvalle
Copy link
Member

Hey there @zli82016 👋🏻 , thanks for reporting the issue and sorry you're running into trouble here.

I think your issue is more related to how Terraform CLI outputs are evaluated, so the Terraform core repo would be a more appropriate place: https://github.com/hashicorp/terraform/issues .

That being said, it does seem possible that the self_link attribute being Optional and not Optional + Computed could affect how Terraform evaluates the expression (since data.google_compute_instance.iavm_node.self_link is Optional and not defined in configuration, the value really should always be null).

I can't transfer your issue directly, but if you open a new issue at https://github.com/hashicorp/terraform/issues , one of the Terraform core engineers may be to confirm what exactly is occurring with the output evaluation.

@austinvalle austinvalle closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants