IBM-Cloud / terraform-provider-ibm

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

Resource `ibm_is_vpc_routing_table` returns complex id #4866

Closed smathews closed 8 months ago

smathews commented 11 months ago

Terraform CLI and Terraform IBM Provider Version

Terraform v1.5.4 on linux_amd64

Affected Resource(s)

resource ibm_is_vpc_routing_table

Terraform Configuration Files

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

# Allows VPN Server <=> Transit Gateway traffic
resource "ibm_is_vpc_routing_table" "transit" {
  vpc                              = ibm_is_subnet.subnet.vpc
  name                             = format("%s-%s", var.name, "route-table-vpn-server-transit")
  route_transit_gateway_ingress    = true
  accept_routes_from_resource_type = ["vpn_gateway"]
}

resource "ibm_is_vpc_routing_table_route" "vpn_vsi" {
  count = local.use_vsi_vpn ? length(local.cidr_map) : 0
  vpc   = var.vpc_id

  # KLUDGE: Routing table id includes VPC ID as the first part
  routing_table = split("/", ibm_is_vpc_routing_table.transit.id)[1]

  zone        = var.zone
  name        = format("%s-%s", var.name, "route-vpn-vsi")
  destination = local.cidr_map[count.index]
  action      = "deliver"
  next_hop    = ibm_is_instance.vpn[0].primary_network_interface[0].primary_ip[0].address
}

Debug Output

│ Error: /v1/vpcs/r006-9d782181-337d-41fe-95b8-7e89b85e5547/routing_tables/r006-9d782181-337d-41fe-95b8-7e89b85e5547/r006-82992649-a4c7-412e-8398-1198c406bddf/routes endpoint not found │ │ with module.vpn.ibm_is_vpc_routing_table_route.vpn_vsi[0], │ on modules/vpn/main.tf line 192, in resource "ibm_is_vpc_routing_table_route" "vpn_vsi": │ 192: resource "ibm_is_vpc_routing_table_route" "vpn_vsi" { │

Panic Output

Expected Behavior

ID should be the ID of the routing table, not a complex variable containing the ID for the VPC and the routing table.

Actual Behavior

ibm_is_vpc_routing_table..id == "/

This causes an issue when you use the newly created routing table and want to add routes to it. You need to split the ID apart from the route table before you can use it for a route.

  1. terraform apply

Important Factoids

References

SunithaGudisagarIBM1 commented 11 months ago

Hi @smathews There is field with routing_table which stores the id value, please use ibm_is_vpc_routing_table.test_route_rt.routing_table instead of routing_table = split("/", ibm_is_vpc_routing_table.transit.id)[1] Thank you Sunitha

sumitkumartiwari commented 10 months ago

@smathews Can you please verify as suggested above and confirm us ?

deepaksibm commented 8 months ago

@smathews is this good to close ?

smathews commented 8 months ago

Thanks all. It does work. However, it does not match with the schemas of the other VPC resources.

deepaksibm commented 8 months ago

Child resources have id in the format of / across other resources. Root level resources will have just the id of its own. Thanks for confirming.

deepaksibm commented 8 months ago

@sumitkumartiwari @astha-jain This can be closed now.

sumitkumartiwari commented 8 months ago

Closing based on @deepaksibm comment