cloudamqp / terraform-provider-cloudamqp

Terraform Provider for CloudAMQP
https://registry.terraform.io/providers/cloudamqp/cloudamqp
Mozilla Public License 2.0
35 stars 39 forks source link

Allow data source cloudamqp_vpc_info lookup using name #159

Closed muresan closed 2 years ago

muresan commented 2 years ago

Allow data source cloudamqp_vpc_gcp_info and cloudamqp_vpc_info to lookup the vpc_id using the VPC name.

Currenlty if the VPC is created in an infrastructure deploy pipeline there is no way to discover the vpc_id from another pipeline that has access to the same credentials as the ones used to deploy the VPC, the vpc_id needs to be passed in one way or another.

Use case:

dentarg commented 2 years ago

@muresan Thanks for opening the issue. Have you seen cloudamqp_account_vpcs? It was added to address this use-case: https://github.com/cloudamqp/terraform-provider-cloudamqp/blob/v1.18.0/docs/data-sources/account_vpcs.md

muresan commented 2 years ago

@muresan Thanks for opening the issue. Have you seen cloudamqp_account_vpcs? It was added to address this use-case: https://github.com/cloudamqp/terraform-provider-cloudamqp/blob/v1.18.0/docs/data-sources/account_vpcs.md

This indeed exposes the vpc_id and vpc_name and can be used to lookup the vpc_id by knowing the vpc_name, but you have to admit that it's more elegant to just use the vpc_info data sources. The example is a bit misleading vpc_name refers (in my case) to the CloudAMQP internal vpc name (which in most cases you don't know beforehand and try to find out) and what you know is the name attribute.

data "cloudamqp_account_vpcs" "vpc_list" {
    id   = "noId"
    vpcs = [
        {
            id       = 192936
            name     = "bfc-poc-rmq-vpc-peering"
            region   = "google-compute-engine::us-east4"
            subnet   = "10.128.0.0/24"
            tags     = []
            vpc_name = "vpc-zuxvih0r"
        },
    ]
}

resource "cloudamqp_vpc" "this" {
    id       = "192936"
    name     = "bfc-poc-rmq-vpc-peering"
    region   = "google-compute-engine::us-east4"
    subnet   = "10.128.0.0/24"
    tags     = []
    vpc_name = "vpc-zuxvih0r"
}

So IMO the example should be:

locals {
  vpc_name = "bfc-poc-rmq-vpc-peering"
  vpc_id = [for vpc in data.cloudamqp_account_vpcs.vpc_list.vpcs : vpc.id if vpc.name == local.vpc_name][0]
}

or similar.

Thank you for the info anyway, helped me simplify a Terraform module by allowing it to autodetect the vpc_id based on vpc name.

dentarg commented 2 years ago

You're right, the docs could be more clear. I've made https://github.com/cloudamqp/terraform-provider-cloudamqp/pull/160, feel free to give it a review.

muresan commented 2 years ago

LGTM

dentarg commented 2 years ago

Thanks, can we close this issue? Even if there's a more elegant solution to be had, I think it is unlikely we can prioritise that over other things needing to be done.

muresan commented 2 years ago

Sure.