Use attr syntax on cluster-specific GKE fields. (#3448)

<!-- This change is generated by MagicModules. -->
Original Author: @rileykarson
This commit is contained in:
The Magician 2019-04-16 16:10:29 -07:00 committed by Riley Karson
parent dc95bd3468
commit 58a58c769f
3 changed files with 55 additions and 9 deletions

View File

@ -493,11 +493,12 @@ func resourceContainerCluster() *schema.Resource {
},
"ip_allocation_policy": {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
MaxItems: 1,
Type: schema.TypeList,
MaxItems: 1,
ForceNew: true,
Optional: true,
Computed: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"use_ip_aliases": {
@ -575,8 +576,8 @@ func resourceContainerCluster() *schema.Resource {
"private_cluster_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Optional: true,
Computed: true,
DiffSuppressFunc: containerClusterPrivateClusterConfigSuppress,
Elem: &schema.Resource{

View File

@ -274,7 +274,7 @@ func TestAccContainerCluster_withMasterAuthorizedNetworksConfig(t *testing.T) {
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{}, "cidr_blocks = []"),
Config: testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName, []string{}, ""),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.with_master_authorized_networks",
"master_authorized_networks_config.#", "1"),
@ -1164,6 +1164,39 @@ func TestAccContainerCluster_withIPAllocationPolicy_createSubnetwork(t *testing.
})
}
// This test will intentionally perform a recreate. Without attr syntax, there's
// no way to go from allocation policy set -> unset without one.
func TestAccContainerCluster_withIPAllocationPolicy_explicitEmpty(t *testing.T) {
t.Parallel()
cluster := 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_withIPAllocationPolicy_createSubnetwork(cluster),
},
{
ResourceName: "google_container_cluster.with_ip_allocation_policy",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withIPAllocationPolicy_explicitEmpty(cluster),
},
{
ResourceName: "google_container_cluster.with_ip_allocation_policy",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccContainerCluster_withResourceLabels(t *testing.T) {
t.Parallel()
@ -2293,6 +2326,17 @@ resource "google_container_cluster" "with_ip_allocation_policy" {
}`, cluster)
}
func testAccContainerCluster_withIPAllocationPolicy_explicitEmpty(cluster string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_ip_allocation_policy" {
name = "%s"
zone = "us-central1-a"
initial_node_count = 1
ip_allocation_policy = []
}`, cluster)
}
func testAccContainerCluster_withPrivateClusterConfig(clusterName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
@ -2331,7 +2375,7 @@ resource "google_container_cluster" "with_private_cluster" {
enable_private_nodes = true
master_ipv4_cidr_block = "10.42.0.0/28"
}
master_authorized_networks_config { cidr_blocks = [] }
master_authorized_networks_config { }
ip_allocation_policy {
cluster_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.0.range_name}"
services_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.1.range_name}"

View File

@ -212,7 +212,8 @@ deprecated in favour of `node_locations`.
* `ip_allocation_policy` - (Optional) Configuration for cluster IP allocation. As of now, only pre-allocated subnetworks (custom type with secondary ranges) are supported.
This will activate IP aliases. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/how-to/ip-aliases)
Structure is documented below.
Structure is documented below. This field is marked to use [Attribute as Block](/docs/configuration/attr-as-blocks.html)
in order to support explicit removal with `ip_allocation_policy = []`.
* `logging_service` - (Optional) The logging service that the cluster should
write logs to. Available options include `logging.googleapis.com`,