Skip to content

Commit

Permalink
add TestAccKubernetesPod_config_with_automount_service_account_token
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Dec 26, 2018
1 parent 0dedeca commit 8475a81
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions kubernetes/resource_kubernetes_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,30 @@ func TestAccKubernetesPod_gke_with_nodeSelector(t *testing.T) {
})
}

func TestAccKubernetesPod_config_with_automount_service_account_token(t *testing.T) {
var confPod api.Pod
var confSA api.ServiceAccount

podName := fmt.Sprintf("tf-acc-test-%s", acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum))
imageName := "nginx:1.7.9"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckKubernetesPodDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesPodConfigWithAutomountServiceAccountToken(podName, imageName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPodExists("kubernetes_pod.test", &confPod),
testAccCheckKubernetesServiceAccountExists("kubernetes_service_account.test", &confSA),
resource.TestCheckResourceAttr("kubernetes_pod.test", "spec.0.automount_service_account_token", "true"),
),
},
},
})
}

func testAccCheckKubernetesPodDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*kubernetes.Clientset)

Expand Down Expand Up @@ -1299,3 +1323,35 @@ resource "kubernetes_pod" "test" {
}
`, podName, imageName, val)
}

func testAccKubernetesPodConfigWithAutomountServiceAccountToken(podName, imageName string) string {
return fmt.Sprintf(`
resource "kubernetes_service_account" "test" {
metadata {
name = "foo"
}
}
resource "kubernetes_pod" "test" {
metadata {
labels {
app = "pod_label"
}
name = "%s"
}
spec {
service_account_name = "foo"
automount_service_account_token = true
container {
image = "%s"
name = "containername"
}
}
depends_on = [ "kubernetes_service_account.test" ]
}
`, podName, imageName)
}

0 comments on commit 8475a81

Please sign in to comment.