Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ForceNew: true to controller field in IngressClass resource #2629

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kubernetes/resource_kubernetes_ingress_class_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func resourceKubernetesIngressClassV1Schema() map[string]*schema.Schema {
Type: schema.TypeString,
Description: docIngressClassSpec["controller"],
Optional: true,
ForceNew: true,
},
"parameters": {
Type: schema.TypeList,
Expand Down
56 changes: 56 additions & 0 deletions kubernetes/resource_kubernetes_ingress_class_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,59 @@ func testAccKubernetesIngressClassV1ConfigParametersApiGroup(name, paramName str
}
`, name, paramName)
}

func TestAccKubernetesIngressClassV1_ControllerImmutable(t *testing.T) {
var conf1, conf2 networking.IngressClass
rName := acctest.RandomWithPrefix("tf-acc-test")
resourceName := "kubernetes_ingress_class_v1.test"
initialControllerValue := "example.com/ingress-controller"
updatedControllerValue := "example.com/new-ingress-controller"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
IDRefreshName: resourceName,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckKubernetesIngressClassV1Destroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesIngressClassV1ConfigBasicWithController(rName, initialControllerValue),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesIngressClassV1Exists(resourceName, &conf1),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", rName),
resource.TestCheckResourceAttr(resourceName, "spec.0.controller", initialControllerValue),
),
},
{
Config: testAccKubernetesIngressClassV1ConfigBasicWithController(rName, updatedControllerValue),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesIngressClassV1Exists(resourceName, &conf2),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", rName),
resource.TestCheckResourceAttr(resourceName, "spec.0.controller", updatedControllerValue),
testAccCheckKubernetesIngressClassForceNew(&conf1, &conf2, true),
),
},
},
})
}

func testAccCheckKubernetesIngressClassForceNew(old, new *networking.IngressClass, wantNew bool) resource.TestCheckFunc {
return func(_ *terraform.State) error {
if (old.UID == new.UID) == wantNew {
return fmt.Errorf("expected force new: %t, but resource was not recreated", wantNew)
}
return nil
}
}

func testAccKubernetesIngressClassV1ConfigBasicWithController(name, controllerValue string) string {
return fmt.Sprintf(`resource "kubernetes_ingress_class_v1" "test" {
metadata {
name = %[1]q
}
spec {
controller = %[2]q
}
}
`, name, controllerValue)
}
Loading