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.29k stars 1.72k forks source link

List usable subnetworks #3490

Open leg100 opened 5 years ago

leg100 commented 5 years ago

Community Note

Description

I would like a data source that returns a list of 'usable subnets', as returned by the command:

gcloud compute networks subnets list-usable

The command is documented here.

This is particularly useful for a 'service project' in a Shared VPC: a user may want to lookup which subnets are available on which a compute instance can be provisioned for their service project.

New or Affected Resource(s)

Potential Terraform Configuration

data "google_compute_usable_subnetworks" "subnets" {}

resource "google_compute_instance" "default" {
  name         = "test"

  network_interface {
    subnetwork = "${element(data.google_compute_usable_subnets.subnets.*.self_link, 0)}"
  }
}

References

AlfatahB commented 1 year ago

b/262517887

AlfatahB commented 1 year ago

I've looked into this issue and it seems like we need to add support for a new datasource google_compute_usable_subnetworks that lists all the usable subnetworks within a project.

AlfatahB commented 1 year ago

If we don't use any filters, the List Usable Subnetworks API operates without any issues. However, I discovered that the filter query parameter is not working as expected. I've tried using the API explorer to pass the filter query parameter, but instead of receiving a filtered result, I'm getting a list of all usable subnetworks. I attempted to add this datasource, which can provide an aggregated list of all usable subnetworks in the project, however in order to make it function, the filter query parameter in the API has to be fixed. This commit contains my implementation of the datasource file, which might be useful for creating this datasource when the filter problem is fixed.