provider/kubernetes: Fix failing tests after upgrading to 1.6

This commit is contained in:
Radek Simko 2017-06-02 14:16:53 +01:00
parent 8a002b937a
commit d0d3f37795
No known key found for this signature in database
GPG Key ID: 6823F3DCCE01BB19
4 changed files with 318 additions and 208 deletions

View File

@ -5,6 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/hashicorp/terraform/builtin/providers/google"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -16,6 +17,7 @@ func init() {
testAccProvider = Provider().(*schema.Provider) testAccProvider = Provider().(*schema.Provider)
testAccProviders = map[string]terraform.ResourceProvider{ testAccProviders = map[string]terraform.ResourceProvider{
"kubernetes": testAccProvider, "kubernetes": testAccProvider,
"google": google.Provider(),
} }
} }
@ -50,4 +52,8 @@ func testAccPreCheck(t *testing.T) {
"KUBE_CLUSTER_CA_CERT_DATA", "KUBE_CLUSTER_CA_CERT_DATA",
}, ", ")) }, ", "))
} }
if os.Getenv("GOOGLE_PROJECT") == "" || os.Getenv("GOOGLE_REGION") == "" || os.Getenv("GOOGLE_ZONE") == "" {
t.Fatal("GOOGLE_PROJECT, GOOGLE_REGION and GOOGLE_ZONE must be set for acceptance tests")
}
} }

View File

@ -2,6 +2,7 @@ package kubernetes
import ( import (
"fmt" "fmt"
"os"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/acctest"
@ -28,7 +29,10 @@ func TestAccKubernetesPersistentVolumeClaim_basic(t *testing.T) {
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf), testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationOne", "one"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"TestAnnotationOne": "one"}), testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{
"TestAnnotationOne": "one",
"volume.beta.kubernetes.io/storage-provisioner": "kubernetes.io/gce-pd",
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "3"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "3"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelThree", "three"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelThree", "three"),
@ -53,7 +57,11 @@ func TestAccKubernetesPersistentVolumeClaim_basic(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "2"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "2"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationOne", "one"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationTwo", "two"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.TestAnnotationTwo", "two"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"TestAnnotationOne": "one", "TestAnnotationTwo": "two"}), testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{
"TestAnnotationOne": "one",
"TestAnnotationTwo": "two",
"volume.beta.kubernetes.io/storage-provisioner": "kubernetes.io/gce-pd",
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "3"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "3"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelTwo", "two"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.TestLabelTwo", "two"),
@ -79,6 +87,8 @@ func TestAccKubernetesPersistentVolumeClaim_importBasic(t *testing.T) {
resourceName := "kubernetes_persistent_volume_claim.test" resourceName := "kubernetes_persistent_volume_claim.test"
volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
diskName := fmt.Sprintf("tf-acc-test-disk-%s", acctest.RandString(10))
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -86,7 +96,7 @@ func TestAccKubernetesPersistentVolumeClaim_importBasic(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeClaimConfig_import(volumeName, claimName), Config: testAccKubernetesPersistentVolumeClaimConfig_import(volumeName, claimName, diskName, zone),
}, },
{ {
ResourceName: resourceName, ResourceName: resourceName,
@ -104,6 +114,8 @@ func TestAccKubernetesPersistentVolumeClaim_volumeMatch(t *testing.T) {
claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
volumeNameModified := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) volumeNameModified := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
diskName := fmt.Sprintf("tf-acc-test-disk-%s", acctest.RandString(10))
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -112,7 +124,7 @@ func TestAccKubernetesPersistentVolumeClaim_volumeMatch(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeClaimConfig_volumeMatch(volumeName, claimName), Config: testAccKubernetesPersistentVolumeClaimConfig_volumeMatch(volumeName, claimName, diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf), testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
@ -135,7 +147,7 @@ func TestAccKubernetesPersistentVolumeClaim_volumeMatch(t *testing.T) {
), ),
}, },
{ {
Config: testAccKubernetesPersistentVolumeClaimConfig_volumeMatch_modified(volumeNameModified, claimName), Config: testAccKubernetesPersistentVolumeClaimConfig_volumeMatch_modified(volumeNameModified, claimName, diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf), testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
@ -161,86 +173,89 @@ func TestAccKubernetesPersistentVolumeClaim_volumeMatch(t *testing.T) {
}) })
} }
func TestAccKubernetesPersistentVolumeClaim_labelsMatch(t *testing.T) { // Label matching isn't supported on GCE
var conf api.PersistentVolumeClaim // TODO: Re-enable when we build test env for K8S that supports it
claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{ // func TestAccKubernetesPersistentVolumeClaim_labelsMatch(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) }, // var conf api.PersistentVolumeClaim
IDRefreshName: "kubernetes_persistent_volume_claim.test", // claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
Providers: testAccProviders, // volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
Steps: []resource.TestStep{
{
Config: testAccKubernetesPersistentVolumeClaimConfig_labelsMatch(volumeName, claimName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes"}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "0"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.name", claimName),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.resource_version"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.self_link"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.uid"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.%", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.storage", "5Gi"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_labels.%", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_labels.TfAccTestEnvironment", "blablah"),
),
},
},
})
}
func TestAccKubernetesPersistentVolumeClaim_labelsMatchExpression(t *testing.T) { // resource.Test(t, resource.TestCase{
var conf api.PersistentVolumeClaim // PreCheck: func() { testAccPreCheck(t) },
claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) // IDRefreshName: "kubernetes_persistent_volume_claim.test",
volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) // Providers: testAccProviders,
// CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
// Steps: []resource.TestStep{
// {
// Config: testAccKubernetesPersistentVolumeClaimConfig_labelsMatch(volumeName, claimName),
// Check: resource.ComposeAggregateTestCheckFunc(
// testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
// testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes"}),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "0"),
// testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.name", claimName),
// resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.generation"),
// resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.resource_version"),
// resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.self_link"),
// resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.uid"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.#", "1"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.#", "1"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.%", "1"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.storage", "5Gi"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.#", "1"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_labels.%", "1"),
// resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_labels.TfAccTestEnvironment", "blablah"),
// ),
// },
// },
// })
// }
resource.Test(t, resource.TestCase{ // func TestAccKubernetesPersistentVolumeClaim_labelsMatchExpression(t *testing.T) {
PreCheck: func() { testAccPreCheck(t) }, // var conf api.PersistentVolumeClaim
IDRefreshName: "kubernetes_persistent_volume_claim.test", // claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
Providers: testAccProviders, // volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
Steps: []resource.TestStep{ // resource.Test(t, resource.TestCase{
{ // PreCheck: func() { testAccPreCheck(t) },
Config: testAccKubernetesPersistentVolumeClaimConfig_labelsMatchExpression(volumeName, claimName), // IDRefreshName: "kubernetes_persistent_volume_claim.test",
Check: resource.ComposeAggregateTestCheckFunc( // Providers: testAccProviders,
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf), // CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"), // Steps: []resource.TestStep{
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes"}), // {
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "0"), // Config: testAccKubernetesPersistentVolumeClaimConfig_labelsMatchExpression(volumeName, claimName),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}), // Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.name", claimName), // testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &conf),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.generation"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.resource_version"), // testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{"pv.kubernetes.io/bind-completed": "yes", "pv.kubernetes.io/bound-by-controller": "yes"}),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.self_link"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.labels.%", "0"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.uid"), // testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.#", "1"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.name", claimName),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.1254135962", "ReadWriteMany"), // resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.generation"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.#", "1"), // resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.resource_version"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.%", "1"), // resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.self_link"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.storage", "5Gi"), // resource.TestCheckResourceAttrSet("kubernetes_persistent_volume_claim.test", "metadata.0.uid"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.#", "1"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.#", "1"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.key", "TfAccTestEnvironment"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.operator", "In"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.%", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.#", "3"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.resources.0.requests.storage", "5Gi"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.1187371253", "three"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.2053932785", "one"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.298486374", "two"), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.key", "TfAccTestEnvironment"),
), // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.operator", "In"),
}, // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.#", "3"),
}, // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.1187371253", "three"),
}) // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.2053932785", "one"),
} // resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "spec.0.selector.0.match_expressions.0.values.298486374", "two"),
// ),
// },
// },
// })
// }
func TestAccKubernetesPersistentVolumeClaim_volumeUpdate(t *testing.T) { func TestAccKubernetesPersistentVolumeClaim_volumeUpdate(t *testing.T) {
var pvcConf api.PersistentVolumeClaim var pvcConf api.PersistentVolumeClaim
@ -248,6 +263,8 @@ func TestAccKubernetesPersistentVolumeClaim_volumeUpdate(t *testing.T) {
claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) claimName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10)) volumeName := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(10))
diskName := fmt.Sprintf("tf-acc-test-disk-%s", acctest.RandString(10))
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -256,7 +273,7 @@ func TestAccKubernetesPersistentVolumeClaim_volumeUpdate(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeClaimDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, "5Gi"), Config: testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, "5Gi", diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf), testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
@ -280,7 +297,7 @@ func TestAccKubernetesPersistentVolumeClaim_volumeUpdate(t *testing.T) {
), ),
}, },
{ {
Config: testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, "10Gi"), Config: testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, "10Gi", diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf), testAccCheckKubernetesPersistentVolumeClaimExists("kubernetes_persistent_volume_claim.test", &pvcConf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume_claim.test", "metadata.0.annotations.%", "0"),
@ -435,7 +452,7 @@ resource "kubernetes_persistent_volume_claim" "test" {
`, name) `, name)
} }
func testAccKubernetesPersistentVolumeClaimConfig_import(volumeName, claimName string) string { func testAccKubernetesPersistentVolumeClaimConfig_import(volumeName, claimName, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -448,12 +465,20 @@ resource "kubernetes_persistent_volume" "test" {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
} }
} }
} }
} }
resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
resource "kubernetes_persistent_volume_claim" "test" { resource "kubernetes_persistent_volume_claim" "test" {
metadata { metadata {
name = "%s" name = "%s"
@ -468,10 +493,10 @@ resource "kubernetes_persistent_volume_claim" "test" {
volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}" volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}"
} }
} }
`, volumeName, claimName) `, volumeName, diskName, zone, claimName)
} }
func testAccKubernetesPersistentVolumeClaimConfig_volumeMatch(volumeName, claimName string) string { func testAccKubernetesPersistentVolumeClaimConfig_volumeMatch(volumeName, claimName, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -484,12 +509,20 @@ resource "kubernetes_persistent_volume" "test" {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
} }
} }
} }
} }
resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
resource "kubernetes_persistent_volume_claim" "test" { resource "kubernetes_persistent_volume_claim" "test" {
metadata { metadata {
name = "%s" name = "%s"
@ -504,10 +537,10 @@ resource "kubernetes_persistent_volume_claim" "test" {
volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}" volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}"
} }
} }
`, volumeName, claimName) `, volumeName, diskName, zone, claimName)
} }
func testAccKubernetesPersistentVolumeClaimConfig_volumeMatch_modified(volumeName, claimName string) string { func testAccKubernetesPersistentVolumeClaimConfig_volumeMatch_modified(volumeName, claimName, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test2" { resource "kubernetes_persistent_volume" "test2" {
metadata { metadata {
@ -520,12 +553,20 @@ resource "kubernetes_persistent_volume" "test2" {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
} }
} }
} }
} }
resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
resource "kubernetes_persistent_volume_claim" "test" { resource "kubernetes_persistent_volume_claim" "test" {
metadata { metadata {
name = "%s" name = "%s"
@ -540,98 +581,98 @@ resource "kubernetes_persistent_volume_claim" "test" {
volume_name = "${kubernetes_persistent_volume.test2.metadata.0.name}" volume_name = "${kubernetes_persistent_volume.test2.metadata.0.name}"
} }
} }
`, volumeName, claimName) `, volumeName, diskName, zone, claimName)
} }
func testAccKubernetesPersistentVolumeClaimConfig_labelsMatch(volumeName, claimName string) string { // func testAccKubernetesPersistentVolumeClaimConfig_labelsMatch(volumeName, claimName string) string {
return fmt.Sprintf(` // return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { // resource "kubernetes_persistent_volume" "test" {
metadata { // metadata {
labels { // labels {
TfAccTestEnvironment = "blablah" // TfAccTestEnvironment = "blablah"
} // }
name = "%s" // name = "%s"
} // }
spec { // spec {
capacity { // capacity {
storage = "10Gi" // storage = "10Gi"
} // }
access_modes = ["ReadWriteMany"] // access_modes = ["ReadWriteMany"]
persistent_volume_source { // persistent_volume_source {
gce_persistent_disk { // gce_persistent_disk {
pd_name = "test123" // pd_name = "test123"
} // }
} // }
} // }
} // }
resource "kubernetes_persistent_volume_claim" "test" { // resource "kubernetes_persistent_volume_claim" "test" {
metadata { // metadata {
name = "%s" // name = "%s"
} // }
spec { // spec {
access_modes = ["ReadWriteMany"] // access_modes = ["ReadWriteMany"]
resources { // resources {
requests { // requests {
storage = "5Gi" // storage = "5Gi"
} // }
} // }
selector { // selector {
match_labels { // match_labels {
TfAccTestEnvironment = "blablah" // TfAccTestEnvironment = "blablah"
} // }
} // }
} // }
} // }
`, volumeName, claimName) // `, volumeName, claimName)
} // }
func testAccKubernetesPersistentVolumeClaimConfig_labelsMatchExpression(volumeName, claimName string) string { // func testAccKubernetesPersistentVolumeClaimConfig_labelsMatchExpression(volumeName, claimName string) string {
return fmt.Sprintf(` // return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { // resource "kubernetes_persistent_volume" "test" {
metadata { // metadata {
labels { // labels {
TfAccTestEnvironment = "two" // TfAccTestEnvironment = "two"
} // }
name = "%s" // name = "%s"
} // }
spec { // spec {
capacity { // capacity {
storage = "10Gi" // storage = "10Gi"
} // }
access_modes = ["ReadWriteMany"] // access_modes = ["ReadWriteMany"]
persistent_volume_source { // persistent_volume_source {
gce_persistent_disk { // gce_persistent_disk {
pd_name = "test123" // pd_name = "test123"
} // }
} // }
} // }
} // }
resource "kubernetes_persistent_volume_claim" "test" { // resource "kubernetes_persistent_volume_claim" "test" {
metadata { // metadata {
name = "%s" // name = "%s"
} // }
spec { // spec {
access_modes = ["ReadWriteMany"] // access_modes = ["ReadWriteMany"]
resources { // resources {
requests { // requests {
storage = "5Gi" // storage = "5Gi"
} // }
} // }
selector { // selector {
match_expressions { // match_expressions {
key = "TfAccTestEnvironment" // key = "TfAccTestEnvironment"
operator = "In" // operator = "In"
values = ["one", "three", "two"] // values = ["one", "three", "two"]
} // }
} // }
} // }
} // }
`, volumeName, claimName) // `, volumeName, claimName)
} // }
func testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, storage string) string { func testAccKubernetesPersistentVolumeClaimConfig_volumeUpdate(volumeName, claimName, storage, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -644,12 +685,20 @@ resource "kubernetes_persistent_volume" "test" {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
} }
} }
} }
} }
resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
resource "kubernetes_persistent_volume_claim" "test" { resource "kubernetes_persistent_volume_claim" "test" {
metadata { metadata {
name = "%s" name = "%s"
@ -664,5 +713,5 @@ resource "kubernetes_persistent_volume_claim" "test" {
volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}" volume_name = "${kubernetes_persistent_volume.test.metadata.0.name}"
} }
} }
`, volumeName, storage, claimName) `, volumeName, storage, diskName, zone, claimName)
} }

View File

@ -2,6 +2,7 @@ package kubernetes
import ( import (
"fmt" "fmt"
"os"
"testing" "testing"
"github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/acctest"
@ -16,6 +17,10 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
var conf api.PersistentVolume var conf api.PersistentVolume
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString) name := fmt.Sprintf("tf-acc-test-%s", randString)
diskName := fmt.Sprintf("tf-acc-test-disk-%s", randString)
region := os.Getenv("GOOGLE_REGION")
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -24,7 +29,7 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeConfig_basic(name), Config: testAccKubernetesPersistentVolumeConfig_basic(name, diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf), testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "2"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "2"),
@ -35,7 +40,13 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelTwo", "two"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelTwo", "two"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelThree", "three"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelThree", "three"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{"TestLabelOne": "one", "TestLabelTwo": "two", "TestLabelThree": "three"}), testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{
"TestLabelOne": "one",
"TestLabelTwo": "two",
"TestLabelThree": "three",
"failure-domain.beta.kubernetes.io/region": region,
"failure-domain.beta.kubernetes.io/zone": zone,
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"),
@ -46,11 +57,11 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.#", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.#", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.pd_name", "test123"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.pd_name", diskName),
), ),
}, },
{ {
Config: testAccKubernetesPersistentVolumeConfig_modified(name), Config: testAccKubernetesPersistentVolumeConfig_modified(name, diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf), testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "2"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "2"),
@ -61,7 +72,13 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelOne", "one"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelOne", "one"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelTwo", "two"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelTwo", "two"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelThree", "three"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.TestLabelThree", "three"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{"TestLabelOne": "one", "TestLabelTwo": "two", "TestLabelThree": "three"}), testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{
"TestLabelOne": "one",
"TestLabelTwo": "two",
"TestLabelThree": "three",
"failure-domain.beta.kubernetes.io/region": region,
"failure-domain.beta.kubernetes.io/zone": zone,
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"),
@ -74,7 +91,7 @@ func TestAccKubernetesPersistentVolume_basic(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.#", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.fs_type", "ntfs"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.fs_type", "ntfs"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.pd_name", "test123"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.pd_name", diskName),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.read_only", "true"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.read_only", "true"),
), ),
}, },
@ -86,6 +103,9 @@ func TestAccKubernetesPersistentVolume_importBasic(t *testing.T) {
resourceName := "kubernetes_persistent_volume.test" resourceName := "kubernetes_persistent_volume.test"
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-import-%s", randString) name := fmt.Sprintf("tf-acc-test-import-%s", randString)
diskName := fmt.Sprintf("tf-acc-test-disk-%s", randString)
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -93,7 +113,7 @@ func TestAccKubernetesPersistentVolume_importBasic(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeConfig_basic(name), Config: testAccKubernetesPersistentVolumeConfig_basic(name, diskName, zone),
}, },
{ {
ResourceName: resourceName, ResourceName: resourceName,
@ -108,6 +128,10 @@ func TestAccKubernetesPersistentVolume_volumeSource(t *testing.T) {
var conf api.PersistentVolume var conf api.PersistentVolume
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum)
name := fmt.Sprintf("tf-acc-test-%s", randString) name := fmt.Sprintf("tf-acc-test-%s", randString)
diskName := fmt.Sprintf("tf-acc-test-disk-%s", randString)
region := os.Getenv("GOOGLE_REGION")
zone := os.Getenv("GOOGLE_ZONE")
resource.Test(t, resource.TestCase{ resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) }, PreCheck: func() { testAccPreCheck(t) },
@ -116,13 +140,16 @@ func TestAccKubernetesPersistentVolume_volumeSource(t *testing.T) {
CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy, CheckDestroy: testAccCheckKubernetesPersistentVolumeDestroy,
Steps: []resource.TestStep{ Steps: []resource.TestStep{
{ {
Config: testAccKubernetesPersistentVolumeConfig_volumeSource(name), Config: testAccKubernetesPersistentVolumeConfig_volumeSource(name, diskName, zone),
Check: resource.ComposeAggregateTestCheckFunc( Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf), testAccCheckKubernetesPersistentVolumeExists("kubernetes_persistent_volume.test", &conf),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "0"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{}), testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.%", "0"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}), testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{
"failure-domain.beta.kubernetes.io/region": region,
"failure-domain.beta.kubernetes.io/zone": zone,
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"),
@ -132,11 +159,8 @@ func TestAccKubernetesPersistentVolume_volumeSource(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.capacity.storage", "123Gi"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.capacity.storage", "123Gi"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.#", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.access_modes.1254135962", "ReadWriteMany"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.aws_elastic_block_store.#", "1"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.#", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.aws_elastic_block_store.0.volume_id", "vol-12345678"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.gce_persistent_disk.0.pd_name"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.aws_elastic_block_store.0.fs_type", "ntfs"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.aws_elastic_block_store.0.partition", "1"),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "spec.0.persistent_volume_source.0.aws_elastic_block_store.0.read_only", "true"),
), ),
}, },
{ {
@ -146,7 +170,10 @@ func TestAccKubernetesPersistentVolume_volumeSource(t *testing.T) {
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.annotations.%", "0"),
testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{}), testAccCheckMetaAnnotations(&conf.ObjectMeta, map[string]string{}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.%", "0"), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.labels.%", "0"),
testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{}), testAccCheckMetaLabels(&conf.ObjectMeta, map[string]string{
"failure-domain.beta.kubernetes.io/region": region,
"failure-domain.beta.kubernetes.io/zone": zone,
}),
resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name), resource.TestCheckResourceAttr("kubernetes_persistent_volume.test", "metadata.0.name", name),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.generation"),
resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"), resource.TestCheckResourceAttrSet("kubernetes_persistent_volume.test", "metadata.0.resource_version"),
@ -242,7 +269,7 @@ func testAccCheckKubernetesPersistentVolumeExists(n string, obj *api.PersistentV
} }
} }
func testAccKubernetesPersistentVolumeConfig_basic(name string) string { func testAccKubernetesPersistentVolumeConfig_basic(name, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -264,14 +291,23 @@ resource "kubernetes_persistent_volume" "test" {
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
} }
} }
} }
}`, name)
} }
func testAccKubernetesPersistentVolumeConfig_modified(name string) string { resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
`, name, diskName, zone)
}
func testAccKubernetesPersistentVolumeConfig_modified(name, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -294,15 +330,24 @@ resource "kubernetes_persistent_volume" "test" {
persistent_volume_source { persistent_volume_source {
gce_persistent_disk { gce_persistent_disk {
fs_type = "ntfs" fs_type = "ntfs"
pd_name = "test123" pd_name = "${google_compute_disk.test.name}"
read_only = true read_only = true
} }
} }
} }
}`, name)
} }
func testAccKubernetesPersistentVolumeConfig_volumeSource(name string) string { resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 10
}
`, name, diskName, zone)
}
func testAccKubernetesPersistentVolumeConfig_volumeSource(name, diskName, zone string) string {
return fmt.Sprintf(` return fmt.Sprintf(`
resource "kubernetes_persistent_volume" "test" { resource "kubernetes_persistent_volume" "test" {
metadata { metadata {
@ -314,15 +359,21 @@ resource "kubernetes_persistent_volume" "test" {
} }
access_modes = ["ReadWriteMany"] access_modes = ["ReadWriteMany"]
persistent_volume_source { persistent_volume_source {
aws_elastic_block_store { gce_persistent_disk {
volume_id = "vol-12345678" pd_name = "${google_compute_disk.test.name}"
fs_type = "ntfs"
partition = 1
read_only = true
} }
} }
} }
}`, name) }
resource "google_compute_disk" "test" {
name = "%s"
type = "pd-ssd"
zone = "%s"
image = "debian-8-jessie-v20170523"
size = 12
}
`, name, diskName, zone)
} }
func testAccKubernetesPersistentVolumeConfig_volumeSource_modified(name string) string { func testAccKubernetesPersistentVolumeConfig_volumeSource_modified(name string) string {

View File

@ -38,6 +38,10 @@ resource "google_container_cluster" "primary" {
} }
} }
output "zone" {
value = "${data.google_compute_zones.available.names[0]}"
}
output "endpoint" { output "endpoint" {
value = "${google_container_cluster.primary.endpoint}" value = "${google_container_cluster.primary.endpoint}"
} }