Skip to content

Commit

Permalink
Support empty TLS blocks in ingress_v1
Browse files Browse the repository at this point in the history
  • Loading branch information
andremarianiello committed Nov 18, 2023
1 parent 7798e31 commit 4d5e04a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
53 changes: 53 additions & 0 deletions kubernetes/resource_kubernetes_ingress_v1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,39 @@ func TestAccKubernetesIngressV1_TLS(t *testing.T) {
})
}

func TestAccKubernetesIngressV1_emptyTLS(t *testing.T) {
var conf networking.Ingress
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
resourceName := "kubernetes_ingress_v1.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
skipIfClusterVersionLessThan(t, "1.22.0")
},
IDRefreshName: resourceName,
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckKubernetesIngressV1Destroy,
IDRefreshIgnore: []string{"metadata.0.resource_version"},
Steps: []resource.TestStep{
{
Config: testAccKubernetesIngressV1Config_emptyTLS(name),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesIngressV1Exists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", name),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.generation"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet(resourceName, "metadata.0.uid"),
resource.TestCheckResourceAttr(resourceName, "spec.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.tls.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.tls.0.hosts.#", "0"),
resource.TestCheckResourceAttr(resourceName, "spec.0.tls.0.secret_name", ""),
),
},
},
})
}

func TestAccKubernetesIngressV1_InternalKey(t *testing.T) {
var conf networking.Ingress
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
Expand Down Expand Up @@ -541,6 +574,26 @@ func testAccKubernetesIngressV1Config_TLS_modified(name string) string {
}`, name)
}

func testAccKubernetesIngressV1Config_emptyTLS(name string) string {
return fmt.Sprintf(`resource "kubernetes_ingress_v1" "test" {
metadata {
name = "%s"
}
spec {
default_backend {
service {
name = "app1"
port {
number = 443
}
}
}
tls {
}
}
}`, name)
}

func testAccKubernetesIngressV1Config_internalKey(name string) string {
return fmt.Sprintf(`resource "kubernetes_ingress_v1" "test" {
metadata {
Expand Down
5 changes: 4 additions & 1 deletion kubernetes/structure_ingress_spec_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,15 @@ func expandIngressV1Backend(l []interface{}) *networking.IngressBackend {
}

func expandIngressV1TLS(l []interface{}) []networking.IngressTLS {
if len(l) == 0 || l[0] == nil {
if len(l) == 0 {
return nil
}

tlsList := make([]networking.IngressTLS, len(l))
for i, t := range l {
if t == nil {
t = map[string]interface{}{}
}
in := t.(map[string]interface{})
obj := networking.IngressTLS{}

Expand Down

0 comments on commit 4d5e04a

Please sign in to comment.