Skip to content

Commit

Permalink
[TF] Fix container cluster private cluster diff suppress/validation
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
emilymye authored and modular-magician committed Feb 25, 2019
1 parent 9119654 commit 3ef8ded
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,28 +547,31 @@ func resourceContainerCluster() *schema.Resource {
},

"private_cluster_config": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
ConflictsWith: []string{"private_cluster", "master_ipv4_cidr_block"},
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Computed: true,
DiffSuppressFunc: containerClusterPrivateClusterConfigSuppress,
ConflictsWith: []string{"private_cluster", "master_ipv4_cidr_block"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enable_private_endpoint": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
DiffSuppressFunc: containerClusterPrivateClusterConfigSuppress,
},
"enable_private_nodes": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
DiffSuppressFunc: containerClusterPrivateClusterConfigSuppress,
},
"master_ipv4_cidr_block": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.CIDRNetwork(28, 28),
ValidateFunc: orEmpty(validation.CIDRNetwork(28, 28)),
},
"private_endpoint": {
Type: schema.TypeString,
Expand Down Expand Up @@ -1823,3 +1826,21 @@ func masterAuthClientCertCfgSuppress(k, old, new string, r *schema.ResourceData)

return strings.HasSuffix(k, ".issue_client_certificate") && old == "" && new == "true"
}

// We want to suppress diffs for empty/disabled private cluster config.
func containerClusterPrivateClusterConfigSuppress(k, old, new string, d *schema.ResourceData) bool {
o, n := d.GetChange("private_cluster_config.0.enable_private_endpoint")
suppressEndpoint := !o.(bool) && !n.(bool)

o, n = d.GetChange("private_cluster_config.0.enable_private_nodes")
suppressNodes := !o.(bool) && !n.(bool)

if k == "private_cluster_config.0.enable_private_endpoint" {
return suppressEndpoint
} else if k == "private_cluster_config.0.enable_private_nodes" {
return suppressNodes
} else if k == "private_cluster_config.#" {
return suppressEndpoint && suppressNodes
}
return false
}

0 comments on commit 3ef8ded

Please sign in to comment.