Skip to content

Commit

Permalink
Allow deleting volume_mount from kubernetes_deployment (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored May 13, 2021
1 parent 9e96653 commit e338cc8
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 9 deletions.
78 changes: 70 additions & 8 deletions kubernetes/resource_kubernetes_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func TestAccKubernetesDeployment_with_volume_mount(t *testing.T) {

deploymentName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
secretName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))

resourceName := "kubernetes_deployment.test"
imageName := nginxImageVersion

resource.Test(t, resource.TestCase{
Expand All @@ -558,13 +558,21 @@ func TestAccKubernetesDeployment_with_volume_mount(t *testing.T) {
{
Config: testAccKubernetesDeploymentConfigWithVolumeMounts(secretName, deploymentName, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesDeploymentExists("kubernetes_deployment.test", &conf),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.volume_mount.#", "1"),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.volume_mount.0.mount_path", "/tmp/my_path"),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.volume_mount.0.name", "db"),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.volume_mount.0.read_only", "false"),
resource.TestCheckResourceAttr("kubernetes_deployment.test", "spec.0.template.0.spec.0.container.0.volume_mount.0.sub_path", ""),
testAccCheckKubernetesDeploymentExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.#", "1"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.mount_path", "/tmp/my_path"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.name", "db"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.read_only", "false"),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.0.sub_path", ""),
),
},
{
Config: testAccKubernetesDeploymentConfigWithVolumeMountsNone(secretName, deploymentName, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesDeploymentExists(resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.image", imageName),
resource.TestCheckResourceAttr(resourceName, "spec.0.template.0.spec.0.container.0.volume_mount.#", "0"),
),
},
},
Expand Down Expand Up @@ -2078,6 +2086,60 @@ resource "kubernetes_deployment" "test" {
`, secretName, deploymentName, imageName)
}

func testAccKubernetesDeploymentConfigWithVolumeMountsNone(secretName, deploymentName, imageName string) string {
return fmt.Sprintf(`resource "kubernetes_secret" "test" {
metadata {
name = "%s"
}
data = {
one = "first"
}
}
resource "kubernetes_deployment" "test" {
metadata {
name = "%s"
labels = {
Test = "TfAcceptanceTest"
}
}
spec {
selector {
match_labels = {
Test = "TfAcceptanceTest"
}
}
template {
metadata {
labels = {
Test = "TfAcceptanceTest"
}
}
spec {
container {
image = "%s"
name = "containername"
}
volume {
name = "db"
secret {
secret_name = "${kubernetes_secret.test.metadata.0.name}"
}
}
}
}
}
}
`, secretName, deploymentName, imageName)
}

func testAccKubernetesDeploymentConfigWithResourceRequirements(deploymentName, imageName string) string {
return fmt.Sprintf(`resource "kubernetes_deployment" "test" {
metadata {
Expand Down
1 change: 0 additions & 1 deletion kubernetes/schema_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ func containerFields(isUpdatable bool) map[string]*schema.Schema {
Type: schema.TypeList,
Optional: true,
ForceNew: !isUpdatable,
Computed: true,
Description: "Pod volumes to mount into the container's filesystem. Cannot be updated.",
Elem: &schema.Resource{
Schema: volumeMountFields(),
Expand Down

0 comments on commit e338cc8

Please sign in to comment.