IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
342 stars 671 forks source link

No 'official' way to get cluster name with data.ibm_container_vpc_cluster or data.ibm_resource_instance #4485

Open vburckhardt opened 1 year ago

vburckhardt commented 1 year ago

Community Note

Terraform CLI and Terraform IBM Provider Version

IBM Cloud Terraform provider version 1.52

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.


data "ibm_container_vpc_cluster" "cluster" {
  name  = "some cluster id" # putting an id here, not a name
  resource_group_id = data.ibm_resource_group.group.id
}

data.ibm_container_vpc_cluster.cluster.name # this returns the id passed as input, not the actual cluster name

Using the deprecated cluster_name_id field.


data "ibm_container_vpc_cluster" "cluster" {
  cluster_name_id = "some cluster id" # putting an id here, not a name
  resource_group_id = data.ibm_resource_group.group.id
}

data.ibm_container_vpc_cluster.cluster.name # this returns 'null'

One may think to use the https://registry.terraform.io/providers/IBM-Cloud/ibm/1.52.0/docs/data-sources/resource_instance data source. But this is the same limitation whereby only the name can be passed as input.

I am using the following hack for now - but this is likely not stable.

  # Ideally data.ibm_container_vpc_cluster.cluster.name would return the cluster name, but it returns the cluster id (!!)
  # So, the following line extracts the cluster name from the ingress hostname. 
  # Ingress hostname seems to follow the pattern <cluster-name>-<random>-<4 digits>.<region>.containers.appdomain.cloud  
  cluster_name                  = regex("(.*)-.*-\\d{4}", data.ibm_container_vpc_cluster.cluster.ingress_hostname)[0]

Debug Output

Panic Output

Expected Behavior

Return the cluster name

Actual Behavior

Returning either the cluster Id or 'null'

Steps to Reproduce

See config above

Important Factoids

Could we get the option to pass an id as a parameter for most data source that take a name. The current provider interface looks hacky where an id is accepted in the field named "name" - and there is no id field.

References

ocofaigh commented 1 year ago

Looks like data.ibm_container_vpc_cluster.cluster.name returns the cluster ID. You have to use data.ibm_container_vpc_cluster.cluster.resource_name to get the cluster name it seems.

vburckhardt commented 1 year ago

Yes @Aashiq-J spotted the field resource_name in https://github.com/terraform-ibm-modules/terraform-ibm-observability-agents/pull/99 - the issue is that resource_name is not documented at https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/container_vpc_cluster, so is there any guarantee that it is going to be maintained in future version. Let's use this tickets to get it officially supported / documented