Skip to content

Commit 2cc07c6

Browse files
modular-magicianrileykarson
authored andcommitted
[terraform] Add AuthenticatorGroupsConfig to google_container_cluster (hashicorp#669)
Signed-off-by: Modular Magician <[email protected]>
1 parent c030c9c commit 2cc07c6

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

google-beta/resource_container_cluster.go

+49
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ func resourceContainerCluster() *schema.Resource {
317317
Default: false,
318318
},
319319

320+
"authenticator_groups_config": {
321+
Type: schema.TypeList,
322+
Optional: true,
323+
Computed: true,
324+
ForceNew: true,
325+
MaxItems: 1,
326+
Elem: &schema.Resource{
327+
Schema: map[string]*schema.Schema{
328+
"security_group": {
329+
Type: schema.TypeString,
330+
Required: true,
331+
ForceNew: true,
332+
},
333+
},
334+
},
335+
},
336+
320337
"initial_node_count": {
321338
Type: schema.TypeInt,
322339
Optional: true,
@@ -876,6 +893,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
876893
cluster.NodeConfig = expandNodeConfig(v)
877894
}
878895

896+
if v, ok := d.GetOk("authenticator_groups_config"); ok {
897+
cluster.AuthenticatorGroupsConfig = expandAuthenticatorGroupsConfig(v)
898+
}
899+
879900
if v, ok := d.GetOk("private_cluster_config"); ok {
880901
cluster.PrivateClusterConfig = expandPrivateClusterConfig(v)
881902
}
@@ -1025,6 +1046,9 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
10251046
if cluster.DefaultMaxPodsConstraint != nil {
10261047
d.Set("default_max_pods_per_node", cluster.DefaultMaxPodsConstraint.MaxPodsPerNode)
10271048
}
1049+
if err := d.Set("authenticator_groups_config", flattenAuthenticatorGroupsConfig(cluster.AuthenticatorGroupsConfig)); err != nil {
1050+
return err
1051+
}
10281052
if err := d.Set("node_config", flattenNodeConfig(cluster.NodeConfig)); err != nil {
10291053
return err
10301054
}
@@ -1921,6 +1945,20 @@ func expandClusterAutoscaling(configured interface{}, d *schema.ResourceData) *c
19211945
return r
19221946
}
19231947

1948+
func expandAuthenticatorGroupsConfig(configured interface{}) *containerBeta.AuthenticatorGroupsConfig {
1949+
l := configured.([]interface{})
1950+
if len(l) == 0 {
1951+
return nil
1952+
}
1953+
result := &containerBeta.AuthenticatorGroupsConfig{}
1954+
config := l[0].(map[string]interface{})
1955+
if securityGroup, ok := config["security_group"]; ok {
1956+
result.Enabled = true
1957+
result.SecurityGroup = securityGroup.(string)
1958+
}
1959+
return result
1960+
}
1961+
19241962
func expandMasterAuth(configured interface{}) *containerBeta.MasterAuth {
19251963
l := configured.([]interface{})
19261964
if len(l) == 0 || l[0] == nil {
@@ -2130,6 +2168,17 @@ func flattenClusterNodePools(d *schema.ResourceData, config *Config, c []*contai
21302168
return nodePools, nil
21312169
}
21322170

2171+
func flattenAuthenticatorGroupsConfig(c *containerBeta.AuthenticatorGroupsConfig) []map[string]interface{} {
2172+
if c == nil {
2173+
return nil
2174+
}
2175+
return []map[string]interface{}{
2176+
{
2177+
"security_group": c.SecurityGroup,
2178+
},
2179+
}
2180+
}
2181+
21332182
func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[string]interface{} {
21342183
if c == nil {
21352184
return nil

google-beta/resource_container_cluster_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,27 @@ func TestAccContainerCluster_withCloudRunEnabled(t *testing.T) {
316316
})
317317
}
318318

319+
func TestAccContainerCluster_withAuthenticatorGroupsConfig(t *testing.T) {
320+
t.Parallel()
321+
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
322+
resource.Test(t, resource.TestCase{
323+
PreCheck: func() { testAccPreCheck(t) },
324+
Providers: testAccProviders,
325+
CheckDestroy: testAccCheckContainerClusterDestroy,
326+
Steps: []resource.TestStep{
327+
{
328+
Config: testAccContainerCluster_withAuthenticatorGroupsConfig(clusterName),
329+
},
330+
{
331+
ResourceName: "google_container_cluster.with_authenticator_groups",
332+
ImportStateIdPrefix: "us-central1-a/",
333+
ImportState: true,
334+
ImportStateVerify: true,
335+
},
336+
},
337+
})
338+
}
339+
319340
func TestAccContainerCluster_withNetworkPolicyEnabled(t *testing.T) {
320341
t.Parallel()
321342

@@ -2102,6 +2123,50 @@ resource "google_container_cluster" "with_cloudrun_enabled" {
21022123
}`, clusterName)
21032124
}
21042125

2126+
func testAccContainerCluster_withAuthenticatorGroupsConfig(clusterName string) string {
2127+
return fmt.Sprintf(`
2128+
resource "google_compute_network" "container_network" {
2129+
name = "container-net-%s"
2130+
auto_create_subnetworks = false
2131+
}
2132+
2133+
resource "google_compute_subnetwork" "container_subnetwork" {
2134+
name = "${google_compute_network.container_network.name}"
2135+
network = "${google_compute_network.container_network.name}"
2136+
ip_cidr_range = "10.0.36.0/24"
2137+
region = "us-central1"
2138+
private_ip_google_access = true
2139+
2140+
secondary_ip_range {
2141+
range_name = "pod"
2142+
ip_cidr_range = "10.0.0.0/19"
2143+
}
2144+
2145+
secondary_ip_range {
2146+
range_name = "svc"
2147+
ip_cidr_range = "10.0.32.0/22"
2148+
}
2149+
}
2150+
2151+
resource "google_container_cluster" "with_authenticator_groups" {
2152+
name = "%s"
2153+
zone = "us-central1-a"
2154+
initial_node_count = 1
2155+
network = "${google_compute_network.container_network.name}"
2156+
subnetwork = "${google_compute_subnetwork.container_subnetwork.name}"
2157+
2158+
authenticator_groups_config {
2159+
security_group = "[email protected]"
2160+
}
2161+
2162+
ip_allocation_policy {
2163+
cluster_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.0.range_name}"
2164+
services_secondary_range_name = "${google_compute_subnetwork.container_subnetwork.secondary_ip_range.1.range_name}"
2165+
}
2166+
}
2167+
`, clusterName, clusterName)
2168+
}
2169+
21052170
func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName string, cidrs []string, emptyValue string) string {
21062171

21072172
cidrBlocks := emptyValue

website/docs/r/container_cluster.html.markdown

+8
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ to the datasource. A `region` can have a different set of supported versions tha
267267
[PodSecurityPolicy](https://cloud.google.com/kubernetes-engine/docs/how-to/pod-security-policies) feature.
268268
Structure is documented below.
269269

270+
* `authenticator_groups_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) Configuration for the
271+
[Google Groups for GKE](https://cloud.google.com/kubernetes-engine/docs/how-to/role-based-access-control#groups-setup-gsuite) feature.
272+
Structure is documented below.
273+
270274
* `private_cluster_config` - (Optional) A set of options for creating
271275
a private cluster. Structure is documented below.
272276

@@ -361,6 +365,10 @@ The `resource_limits` block supports:
361365

362366
* `maximum` - (Optional) The maximum value for the resource type specified.
363367

368+
The `authenticator_groups_config` block supports:
369+
370+
* `security_group` - (Required) The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format `[email protected]`.
371+
364372
The `maintenance_policy` block supports:
365373

366374
* `daily_maintenance_window` - (Required) Time window specified for daily maintenance operations.

0 commit comments

Comments
 (0)