hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.28k stars 1.72k forks source link

`data.google_compute_reservation.share_settings` is `tolist(null)` #18248

Open mr0re1 opened 3 months ago

mr0re1 commented 3 months ago

Community Note

Terraform Version & Provider Version(s)

Terraform v1.4.0 on linux_amd64

Affected Resource(s)

data google_compute_reservation

Terraform Configuration

data "google_compute_reservation" "reservation" {
  name  = "X"
  zone  = "Y"
  project = "Z"
}

output "o" {
  value = data.google_compute_reservation.reservation
}

Debug Output

o = {
  "commitment" = ""
  "creation_timestamp" = "2024-05-24T13:01:33.453-07:00"
  "description" = ""
  "id" = "projects/Z/zones/Y/reservations/X"
  "name" = "X"
  "project" = "Z"
  "self_link" = "https://www.googleapis.com/compute/v1/projects/Z/zones/Y/reservations/X"
  "share_settings" = tolist(null) /* of object */
  "specific_reservation" = tolist([
    {
      "count" = 2
      "in_use_count" = 0
      "instance_properties" = tolist([
        {
          "guest_accelerators" = tolist([])
          "local_ssds" = tolist([])
          "machine_type" = "n2-standard-2"
          "min_cpu_platform" = "Any CPU Platform"
        },
      ])
    },
  ])
  "specific_reservation_required" = true
  "status" = "READY"
  "zone" = "https://www.googleapis.com/compute/v1/projects/Z/zones/Y"
}

Expected Behavior

share_settings contains details of shareSettings API field, such as:

"shareSettings": {
    "shareType": "LOCAL"
},

Or

  "shareSettings": {
    "projectMap": {
      "W": {
        "projectId": "W"
      }
    },
    "shareType": "SPECIFIC_PROJECTS"
  },

Actual Behavior

"share_settings" = tolist(null) /* of object */

Steps to reproduce

  1. terraform apply

Important Factoids

No response

References

No response

b/343772844

ggtisc commented 3 months ago

Hi @mr0re1!

According to the terraform code you are sharing you didn't specify the argument share_settings and for this reason this value was set to null. You may need to check terraform registry to see how to set a value for this argument.

As terraform registry specifies this is an optional value, and you can see the same in the Google Cloud Documentation. Only if you want to create a shared reservation you need to declare it.

In this other link you can check how to create a reservation according to your needs.

Finally I let you this other link to learn how reservations work, requirements, restrictions and so on

mr0re1 commented 3 months ago

Hi @ggtisc ,

In my example I don't create any reservation but fetch the details about existing one:

**data** "google_compute_reservation" "reservation" 

My expectations is that data source would return an accurate and complete information about the entity, including share_settings.

ggtisc commented 3 months ago

Does your existing google_compute_reservation called reservation have the share_settings declared?

In case that this argument isn't declared you need 1st to update it and specify its value, because as the documentation explains it is optional and if you didn't declare a value for it it is going to return always the same.

mr0re1 commented 3 months ago

Hi @ggtisc , to illustrate the problem, I've created two reservations with different (at least one is non-default) shareSettings:

$ gcloud compute reservations describe --project=X --zone=Y Z_SHARED --format=json | jq ".shareSettings"
{
  "projectMap": {
    "333333333333": {
      "projectId": "333333333333"
    }
  },
  "shareType": "SPECIFIC_PROJECTS"
}

$ gcloud compute reservations describe --project=X --zone=Y Z_LOCAL --format=json | jq ".shareSettings"
{
  "shareType": "LOCAL"
}

But data "google_compute_reservation" fails to "describe" the difference:

data "google_compute_reservation" "z_shared" {
  name  = "Z_SHARED"
  zone  = "Y"
  project = "X"
}

data "google_compute_reservation" "z_local" {
  name  = "Z_LOCAL"
  zone  = "Y"
  project = "X"
}

output "z_shared" {
  value = data.google_compute_reservation.z_shared
}

output "z_local" {
  value = data.google_compute_reservation.z_local
}

# Outputs:

z_local = {
  ...
  "share_settings" = tolist(null) /* of object */
  ...
}
z_shared = {
  ...
  "share_settings" = tolist(null) /* of object */
  ...
}
ggtisc commented 3 months ago

Confirmed issue!

For an existing google_compute_reservation resource with share_settings configured, after running a terraform apply it doesn't return the assigned value, and instead of this it just returns "share_settings" = tolist(null)