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

[ibm_tg_gateway] Error: A gateway with the same name already exists. #4190

Open ocofaigh opened 1 year ago

ocofaigh commented 1 year ago

We intermittently see an issue where transit gateway creation fails with Error: A gateway with the same name already exists. However, we are using a random prefix so this should not be the case.

As you can the plan contains tg name called landing-3156-transit-gateway:

 2022/11/19 17:01:14 Terraform plan |   # module.landing_zone.ibm_tg_gateway.transit_gateway[0] will be created
 2022/11/19 17:01:14 Terraform plan |   + resource "ibm_tg_gateway" "transit_gateway" {
 2022/11/19 17:01:14 Terraform plan |       + created_at              = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + crn                     = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + global                  = false
 2022/11/19 17:01:14 Terraform plan |       + id                      = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + location                = "us-south"
 2022/11/19 17:01:14 Terraform plan |       + name                    = "landing-3156-transit-gateway"
 2022/11/19 17:01:14 Terraform plan |       + resource_controller_url = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + resource_crn            = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + resource_group          = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + resource_group_name     = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + resource_name           = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + resource_status         = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + status                  = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + tags                    = (known after apply)
 2022/11/19 17:01:14 Terraform plan |       + updated_at              = (known after apply)
 2022/11/19 17:01:14 Terraform plan | 
 2022/11/19 17:01:14 Terraform plan |       + timeouts {
 2022/11/19 17:01:14 Terraform plan |           + create = "30m"
 2022/11/19 17:01:14 Terraform plan |           + delete = "30m"
 2022/11/19 17:01:14 Terraform plan |         }
 2022/11/19 17:01:14 Terraform plan |     }

yet the apply fails with:

 2022/11/19 17:08:17 Terraform apply | Error: A gateway with the same name already exists.
 2022/11/19 17:08:17 Terraform apply | 
 2022/11/19 17:08:17 Terraform apply |   with module.landing_zone.ibm_tg_gateway.transit_gateway[0],
 2022/11/19 17:08:17 Terraform apply |   on ../../transit_gateway.tf line 6, in resource "ibm_tg_gateway" "transit_gateway":
 2022/11/19 17:08:17 Terraform apply |    6: resource "ibm_tg_gateway" "transit_gateway" {

After checking manually in the UI, I can see that the test did create the transit gateway:

image

So this seems to be a provider (or backend UI issue) where the resource is actually being created, but perhaps a success response is not coming in time, and perhaps a retry is attempted.

I have not (yet) reproduced with trace logs, but creating to issue to see if this may be a known issue, or incase others have hit it

Community Note

Terraform CLI and Terraform IBM Provider Version

 2022/11/19 17:00:06 Terraform init | Initializing provider plugins...
 2022/11/19 17:00:06 Terraform init | - Finding hashicorp/external versions matching ">= 2.2.2"...
 2022/11/19 17:00:07 Terraform init | - Finding hashicorp/random versions matching ">= 3.4.2"...
 2022/11/19 17:00:07 Terraform init | - Finding ibm-cloud/ibm versions matching ">= 1.44.3, >= 1.45.0, 1.45.1"...
 2022/11/19 17:00:07 Terraform init | - Installing hashicorp/external v2.2.3...
 2022/11/19 17:00:08 Terraform init | - Installed hashicorp/external v2.2.3 (signed by HashiCorp)
 2022/11/19 17:00:08 Terraform init | - Installing hashicorp/random v3.4.3...
 2022/11/19 17:00:09 Terraform init | - Installed hashicorp/random v3.4.3 (signed by HashiCorp)
 2022/11/19 17:00:10 Terraform init | - Installing ibm-cloud/ibm v1.45.1...
 2022/11/19 17:00:15 Terraform init | - Installed ibm-cloud/ibm v1.45.1 (self-signed, key ID AAD3B791C49CC253)

Affected Resource(s)

Terraform Configuration Files

https://github.com/terraform-ibm-modules/terraform-ibm-landing-zone/tree/main/patterns/vsi

Debug Output

Panic Output

Expected Behavior

Actual Behavior

Steps to Reproduce

  1. terraform apply

Important Factoids

References

ocofaigh commented 2 months ago

This is still an issue in 1.66.0:

│ Error: A gateway with the same name already exists.
│ 
│   with module.landing_zone.module.landing_zone.ibm_tg_gateway.transit_gateway[0],
│   on ../../transit_gateway.tf line 6, in resource "ibm_tg_gateway" "transit_gateway":
│    6: resource "ibm_tg_gateway" "transit_gateway" {
│ 
│ ---
│ id: terraform-1e84d8d2
│ summary: A gateway with the same name already exists.
│ severity: error
│ resource: ibm_tg_gateway
│ operation: create
│ component:
│   name: github.com/IBM-Cloud/terraform-provider-ibm
│   version: 1.66.0
│ ---