Skip to content

Commit 15dbde8

Browse files
translucensDawid212
authored andcommitted
add ip_endpoints_config field to google_container_cluster (GoogleCloudPlatform#13364)
1 parent ec5e6b2 commit 15dbde8

File tree

3 files changed

+101
-2
lines changed

3 files changed

+101
-2
lines changed

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

+39-2
Original file line numberDiff line numberDiff line change
@@ -1788,7 +1788,7 @@ func ResourceContainerCluster() *schema.Resource {
17881788
MaxItems: 1,
17891789
Computed: true,
17901790
Optional: true,
1791-
Description: `Configuration for all of the cluster's control plane endpoints. Currently supports only DNS endpoint configuration, IP endpoint configuration is available in private_cluster_config.`,
1791+
Description: `Configuration for all of the cluster's control plane endpoints. Currently supports only DNS endpoint configuration and disable IP endpoint. Other IP endpoint configurations are available in private_cluster_config.`,
17921792
Elem: &schema.Resource{
17931793
Schema: map[string]*schema.Schema{
17941794
"dns_endpoint_config": {
@@ -1813,6 +1813,22 @@ func ResourceContainerCluster() *schema.Resource {
18131813
},
18141814
},
18151815
},
1816+
"ip_endpoints_config": {
1817+
Type: schema.TypeList,
1818+
MaxItems: 1,
1819+
Optional: true,
1820+
Computed: true,
1821+
Description: `IP endpoint configuration.`,
1822+
Elem: &schema.Resource{
1823+
Schema: map[string]*schema.Schema{
1824+
"enabled": {
1825+
Type: schema.TypeBool,
1826+
Optional: true,
1827+
Description: `Controls whether to allow direct IP access.`,
1828+
},
1829+
},
1830+
},
1831+
},
18161832
},
18171833
},
18181834
},
@@ -5644,10 +5660,19 @@ func expandControlPlaneEndpointsConfig(d *schema.ResourceData) *container.Contro
56445660
}
56455661

56465662
ip := &container.IPEndpointsConfig{
5647-
// There isn't yet a config field to disable IP endpoints, so this is hardcoded to be enabled for the time being.
56485663
Enabled: true,
56495664
ForceSendFields: []string{"Enabled"},
56505665
}
5666+
if v := d.Get("control_plane_endpoints_config.0.ip_endpoints_config.#"); v != 0 {
5667+
ip.Enabled = d.Get("control_plane_endpoints_config.0.ip_endpoints_config.0.enabled").(bool)
5668+
5669+
if !ip.Enabled {
5670+
return &container.ControlPlaneEndpointsConfig{
5671+
DnsEndpointConfig: dns,
5672+
IpEndpointsConfig: ip,
5673+
}
5674+
}
5675+
}
56515676
if v := d.Get("private_cluster_config.0.enable_private_endpoint"); v != nil {
56525677
ip.EnablePublicEndpoint = !v.(bool)
56535678
ip.ForceSendFields = append(ip.ForceSendFields, "EnablePublicEndpoint")
@@ -6383,6 +6408,7 @@ func flattenControlPlaneEndpointsConfig(c *container.ControlPlaneEndpointsConfig
63836408
return []map[string]interface{}{
63846409
{
63856410
"dns_endpoint_config": flattenDnsEndpointConfig(c.DnsEndpointConfig),
6411+
"ip_endpoints_config": flattenIpEndpointsConfig(c.IpEndpointsConfig),
63866412
},
63876413
}
63886414
}
@@ -6399,6 +6425,17 @@ func flattenDnsEndpointConfig(dns *container.DNSEndpointConfig) []map[string]int
63996425
}
64006426
}
64016427

6428+
func flattenIpEndpointsConfig(ip *container.IPEndpointsConfig) []map[string]interface{} {
6429+
if ip == nil {
6430+
return nil
6431+
}
6432+
return []map[string]interface{}{
6433+
{
6434+
"enabled": ip.Enabled,
6435+
},
6436+
}
6437+
}
6438+
64026439
// Most of PrivateClusterConfig has moved to ControlPlaneEndpointsConfig.
64036440
func flattenPrivateClusterConfig(cpec *container.ControlPlaneEndpointsConfig, pcc *container.PrivateClusterConfig, nc *container.NetworkConfig) []map[string]interface{} {
64046441
if cpec == nil && pcc == nil && nc == nil {

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

+57
Original file line numberDiff line numberDiff line change
@@ -13381,3 +13381,60 @@ resource "google_container_cluster" "with_enterprise_config" {
1338113381
}
1338213382
`, projectID, clusterName, networkName, subnetworkName)
1338313383
}
13384+
13385+
func TestAccContainerCluster_disableControlPlaneIP(t *testing.T) {
13386+
t.Parallel()
13387+
13388+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
13389+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
13390+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
13391+
13392+
acctest.VcrTest(t, resource.TestCase{
13393+
PreCheck: func() { acctest.AccTestPreCheck(t) },
13394+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
13395+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
13396+
Steps: []resource.TestStep{
13397+
{
13398+
Config: testAccContainerCluster_basic(clusterName, networkName, subnetworkName),
13399+
},
13400+
{
13401+
ResourceName: "google_container_cluster.primary",
13402+
ImportState: true,
13403+
ImportStateVerify: true,
13404+
ImportStateVerifyIgnore: []string{"deletion_protection"},
13405+
},
13406+
{
13407+
Config: testAccContainerCluster_ControlPlaneIPdisabled(clusterName, networkName, subnetworkName),
13408+
},
13409+
{
13410+
ResourceName: "google_container_cluster.primary",
13411+
ImportState: true,
13412+
ImportStateVerify: true,
13413+
ImportStateVerifyIgnore: []string{"deletion_protection"},
13414+
},
13415+
},
13416+
})
13417+
}
13418+
13419+
func testAccContainerCluster_ControlPlaneIPdisabled(clusterName, networkName, subnetworkName string) string {
13420+
return fmt.Sprintf(`
13421+
resource "google_container_cluster" "primary" {
13422+
name = "%s"
13423+
location = "us-central1-a"
13424+
initial_node_count = 1
13425+
network = "%s"
13426+
subnetwork = "%s"
13427+
13428+
deletion_protection = false
13429+
13430+
control_plane_endpoints_config {
13431+
ip_endpoints_config {
13432+
enabled = false
13433+
}
13434+
dns_endpoint_config {
13435+
allow_external_traffic = true
13436+
}
13437+
}
13438+
}
13439+
`, clusterName, networkName, subnetworkName)
13440+
}

mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown

+5
Original file line numberDiff line numberDiff line change
@@ -1213,13 +1213,18 @@ notification_config {
12131213
<a name="nested_control_plane_endpoints_config"></a>The `control_plane_endpoints_config` block supports:
12141214

12151215
* `dns_endpoint_config` - (Optional) DNS endpoint configuration.
1216+
* `ip_endpoints_config` - (Optional) IP endpoint configuration.
12161217

12171218
The `control_plane_endpoints_config.dns_endpoint_config` block supports:
12181219

12191220
* `endpoint` - (Output) The cluster's DNS endpoint.
12201221

12211222
* `allow_external_traffic` - (Optional) Controls whether user traffic is allowed over this endpoint. Note that GCP-managed services may still use the endpoint even if this is false.
12221223

1224+
The `control_plane_endpoints_config.ip_endpoints_config` block supports:
1225+
1226+
* `enabled` - (Optional) Controls whether to allow direct IP access. Defaults to `true`.
1227+
12231228
<a name="nested_private_cluster_config"></a>The `private_cluster_config` block supports:
12241229

12251230
* `enable_private_nodes` (Optional) - Enables the private cluster feature,

0 commit comments

Comments
 (0)