IBM-Cloud / terraform-provider-ibm

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

VPC security group data source does not handle duplicate names #5386

Closed smatzek closed 2 weeks ago

smatzek commented 1 month ago

Community Note

Terraform CLI and Terraform IBM Provider Version

1.63.0

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_is_security_group" "smatzek_vpc_vpc_default_sg" {
  name = "vpc-default"
}

Debug Output

Panic Output

Expected Behavior

I expect to have the ability to correctly use a data source to reference VPC security groups when two groups in different VPCs have the same name.

Actual Behavior

VPC security groups are not required to have universally unique names. They are required to have the same name in a given VPC. When two security groups have the same name in different VPCs the ibm_is_security_group data source can and does lookup and get a reference to the "wrong" security group when trying to work with a specific VPC.

The arguments for the data source only allow "name". They do not allow "vpc": https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/data-sources/is_security_group#argument-reference

Trying to add "vpc" as an input argument gives an error.

Steps to Reproduce

  1. create two VPC security groups with the same name in different VPCs.
  2. Create some HCL with a security group data source
  3. run Terraform plan It will return one of the security groups IDs in the plan output but there is no way to choose WHICH of the conflicting named groups to use.

References

ujjwal-ibm commented 1 month ago

Added an enhancement for this. Thank you for reporting.