Doing a terraform import esxi_vswitch.test test followed by terraform plan/apply wants to re-create the vswitch.
To Reproduce
Steps to reproduce the behavior:
terraform import esxi_vswitch.test test
terraform plan/apply
Expected behavior
Expected a noop plan after an import.
Terraform file
resource "esxi_vswitch" "test" {
name = "test"
}
Desktop (please complete the following information):
OS: Ubuntu 20.04
Terraform Version: 1.0.7
This Plugin Version: 1.8.3
Additional context
Here's a transcript:
# see that the vswitch does in fact exist, because it fails to be created by terraform without a previous terraform state.
vagrant@ubuntu:~/test-terraform-esxi$ terraform plan -out=tfplan
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
+ create
Terraform will perform the following actions:
# esxi_vswitch.test will be created
+ resource "esxi_vswitch" "test" {
+ forged_transmits = (known after apply)
+ id = (known after apply)
+ link_discovery_mode = (known after apply)
+ mac_changes = (known after apply)
+ mtu = (known after apply)
+ name = "test"
+ ports = (known after apply)
+ promiscuous_mode = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Saved the plan to: tfplan
To perform exactly these actions, run the following command to apply:
terraform apply "tfplan"
vagrant@ubuntu:~/test-terraform-esxi$ time terraform apply tfplan
esxi_vswitch.test: Creating...
╷
│ Error: Failed to add vswitch: test, it already exists
│
│
│ with esxi_vswitch.test,
│ on main.tf line 20, in resource "esxi_vswitch" "test":
│ 20: resource "esxi_vswitch" "test" {
│
╵
real 0m1.527s
user 0m0.583s
sys 0m0.067s
# now import the existing vswitch.
vagrant@ubuntu:~/test-terraform-esxi$ terraform import esxi_vswitch.test test
esxi_vswitch.test: Importing from ID "test"...
esxi_vswitch.test: Import prepared!
Prepared esxi_vswitch for import
esxi_vswitch.test: Refreshing state... [id=test]
Import successful!
The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.
# plan the changes, and notice it tries to re-create the vswitch, but it shouldn't.
vagrant@ubuntu:~/test-terraform-esxi$ terraform plan -out=tfplan
esxi_vswitch.test: Refreshing state... [id=test]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated
with the following symbols:
-/+ destroy and then create replacement
Terraform will perform the following actions:
# esxi_vswitch.test must be replaced
-/+ resource "esxi_vswitch" "test" {
~ forged_transmits = false -> (known after apply)
~ id = "test" -> (known after apply)
~ link_discovery_mode = "listen" -> (known after apply)
~ mac_changes = false -> (known after apply)
~ mtu = 1500 -> (known after apply)
+ name = "test" # forces replacement
~ ports = 128 -> (known after apply)
~ promiscuous_mode = false -> (known after apply)
}
Plan: 1 to add, 0 to change, 1 to destroy.
It seems the import does not set the vswitch name inside the terraform state:
Describe the bug
Doing a
terraform import esxi_vswitch.test test
followed byterraform plan/apply
wants to re-create the vswitch.To Reproduce
Steps to reproduce the behavior:
terraform import esxi_vswitch.test test
terraform plan/apply
Expected behavior
Expected a noop plan after an import.
Terraform file
Desktop (please complete the following information):
Additional context
Here's a transcript:
It seems the import does not set the vswitch name inside the terraform state: