Skip to content

Commit

Permalink
Add acc test for attribute type transitioning from object to primitive.
Browse files Browse the repository at this point in the history
Format test configuration files.
  • Loading branch information
alexsomesan committed Sep 20, 2024
1 parent f6cb88c commit 0dbe34c
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,21 @@ func TestKubernetesManifest_CustomResource_x_preserve_unknown_fields(t *testing.
"baz": interface{}("42"),
},
})


tfconfig = loadTerraformConfig(t, "x-kubernetes-preserve-unknown-fields/test-cr-4.tf", tfvars)
step1.SetConfig(ctx, string(tfconfig))
step1.Apply(ctx)

s4, err := step1.State(ctx)
if err != nil {
t.Fatalf("Failed to retrieve terraform state: %q", err)
}
tfstate4 := tfstatehelper.NewHelper(s4)
tfstate4.AssertAttributeValues(t, tfstatehelper.AttributeValues{
"kubernetes_manifest.test.object.metadata.name": name,
"kubernetes_manifest.test.object.metadata.namespace": namespace,
"kubernetes_manifest.test.object.spec.count": json.Number("100"),
"kubernetes_manifest.test.object.spec.resources": false,
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
resource "kubernetes_manifest" "customresourcedefinition_cephrbdmirrors_ceph_rook_io" {
manifest = {
apiVersion = "apiextensions.k8s.io/v1"
kind = "CustomResourceDefinition"
kind = "CustomResourceDefinition"
metadata = {
name = "${var.plural}.${var.group}"
}
spec = {
group = var.group
names = {
kind = var.kind
kind = var.kind
plural = var.plural
}
scope = "Namespaced"
Expand All @@ -24,14 +24,14 @@ resource "kubernetes_manifest" "customresourcedefinition_cephrbdmirrors_ceph_roo
spec = {
properties = {
annotations = {
nullable = true
type = "object"
nullable = true
type = "object"
"x-kubernetes-preserve-unknown-fields" = true
}
count = {
maximum = 100
minimum = 1
type = "integer"
type = "integer"
}
peers = {
properties = {
Expand All @@ -45,30 +45,29 @@ resource "kubernetes_manifest" "customresourcedefinition_cephrbdmirrors_ceph_roo
type = "object"
}
placement = {
nullable = true
type = "object"
nullable = true
type = "object"
"x-kubernetes-preserve-unknown-fields" = true
}
priorityClassName = {
type = "string"
}
resources = {
nullable = true
type = "object"
nullable = true
"x-kubernetes-preserve-unknown-fields" = true
}
}
type = "object"
}
status = {
type = "object"
type = "object"
"x-kubernetes-preserve-unknown-fields" = true
}
}
type = "object"
}
}
served = true
served = true
storage = true
subresources = {
status = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
resource "kubernetes_manifest" "test" {
manifest = {
apiVersion = var.group_version
kind = var.kind
kind = var.kind
metadata = {
name = var.name
name = var.name
namespace = var.namespace
}
spec = {
count = 100
resources = {
foo = "bar"
}
count = 100
resources = {
foo = "bar"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
resource "kubernetes_manifest" "test" {
manifest = {
apiVersion = var.group_version
kind = var.kind
kind = var.kind
metadata = {
name = var.name
name = var.name
namespace = var.namespace
}
spec = {
count = 100
resources = {
foo = "bar"
baz = "42"
}
count = 100
resources = {
foo = "bar"
baz = "42"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
resource "kubernetes_manifest" "test" {
manifest = {
apiVersion = var.group_version
kind = var.kind
kind = var.kind
metadata = {
name = var.name
name = var.name
namespace = var.namespace
}
spec = {
count = 100
resources = {
foo = ["bar"]
baz = "42"
}
count = 100
resources = {
foo = ["bar"]
baz = "42"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0

resource "kubernetes_manifest" "test" {
manifest = {
apiVersion = var.group_version
kind = var.kind
metadata = {
name = var.name
namespace = var.namespace
}
spec = {
count = 100
resources = false
}
}
}

0 comments on commit 0dbe34c

Please sign in to comment.