Skip to content

Commit

Permalink
nil as unspecified, test for invalid channels
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissng committed Oct 15, 2019
1 parent 5c28425 commit 385925a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -735,9 +735,11 @@ func resourceContainerCluster() *schema.Resource {
Schema: map[string]*schema.Schema{
"channel": {
Type: schema.TypeString,
Default: "UNSPECIFIED",
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"UNSPECIFIED", "RAPID", "REGULAR", "STABLE"}, false),
DiffSuppressFunc: emptyOrDefaultStringSuppress("UNSPECIFIED"),
},
},
},
Expand Down Expand Up @@ -2607,6 +2609,11 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa
result = append(result, map[string]interface{}{
"channel": c.Channel,
})
} else {
// Explicitly set the release channel to the default.
result = append(result, map[string]interface{}{
"channel": "UNSPECIFIED",
})
}
return result
}
Expand Down
31 changes: 31 additions & 0 deletions third_party/terraform/tests/resource_container_cluster_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,27 @@ func TestAccContainerCluster_withReleaseChannelEnabled(t *testing.T) {
})
}

func TestAccContainerCluster_withReleaseChannelDefault(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withReleaseChannelDefault(clusterName),
},
{
ResourceName: "google_container_cluster.with_default_release_channel",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccContainerCluster_withInvalidReleaseChannel(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
Expand Down Expand Up @@ -2049,6 +2070,16 @@ resource "google_container_cluster" "with_release_channel" {
}
}`, clusterName, channel)
}

func testAccContainerCluster_withReleaseChannelDefault(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_default_release_channel" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
release_channel {}
}`, clusterName)
}
<% end -%>

func testAccContainerCluster_removeNetworkPolicy(clusterName string) string {
Expand Down

0 comments on commit 385925a

Please sign in to comment.