Skip to content

Commit

Permalink
removed forceNew (#6282) (#12310)
Browse files Browse the repository at this point in the history
* removed forceNew

* updated a test

* reset security_group with empty

Co-authored-by: Edward Sun <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Aug 15, 2022
1 parent f45a823 commit 26a7743
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .changelog/6282.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: added update support for `authenticator_groups_config` in `google_container_cluster`
```
29 changes: 27 additions & 2 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,13 @@ func resourceContainerCluster() *schema.Resource {
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
MaxItems: 1,
Description: `Configuration for the Google Groups for GKE feature.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"security_group": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The name of the RBAC security group for use with Google security groups in Kubernetes RBAC. Group name must be in format [email protected].`,
},
},
Expand Down Expand Up @@ -2073,6 +2071,21 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
log.Printf("[INFO] GKE cluster %s Private IPv6 Google Access has been updated", d.Id())
}

if d.HasChange("authenticator_groups_config") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
DesiredAuthenticatorGroupsConfig: expandContainerClusterAuthenticatorGroupsConfig(d.Get("authenticator_groups_config")),
},
}
updateF := updateFunc(req, "updating GKE cluster authenticator groups config")
// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s authenticator groups config has been updated", d.Id())
}

if d.HasChange("default_snat_status") {
req := &container.UpdateClusterRequest{
Update: &container.ClusterUpdate{
Expand Down Expand Up @@ -3366,6 +3379,18 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig
return mc
}

func expandContainerClusterAuthenticatorGroupsConfig(configured interface{}) *container.AuthenticatorGroupsConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
return nil
}

config := l[0].(map[string]interface{})
return &container.AuthenticatorGroupsConfig{
SecurityGroup: config["security_group"].(string),
}
}

func flattenNotificationConfig(c *container.NotificationConfig) []map[string]interface{} {
if c == nil {
return nil
Expand Down
90 changes: 50 additions & 40 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,45 @@ func TestAccContainerCluster_withMasterAuthConfig_NoCert(t *testing.T) {
func TestAccContainerCluster_withAuthenticatorGroupsConfig(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
containerNetName := fmt.Sprintf("tf-test-container-net-%s", randString(t, 10))
orgDomain := getTestOrgDomainFromEnv(t)
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAuthenticatorGroupsConfig(containerNetName, clusterName, orgDomain),
Config: testAccContainerCluster_basic(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr("google_container_cluster.primary",
"authenticator_groups_config.0.enabled"),
),
},
{
ResourceName: "google_container_cluster.with_authenticator_groups",
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withAuthenticatorGroupsConfigUpdate(clusterName, orgDomain),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.primary",
"authenticator_groups_config.0.security_group", fmt.Sprintf("gke-security-groups@%s", orgDomain)),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccContainerCluster_withAuthenticatorGroupsConfigUpdate2(clusterName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckNoResourceAttr("google_container_cluster.primary",
"authenticator_groups_config.0.enabled"),
),
},
{
ResourceName: "google_container_cluster.primary",
ImportState: true,
ImportStateVerify: true,
},
Expand Down Expand Up @@ -2728,49 +2755,32 @@ resource "google_container_cluster" "with_network_policy_enabled" {
`, clusterName)
}

func testAccContainerCluster_withAuthenticatorGroupsConfig(containerNetName string, clusterName string, orgDomain string) string {
func testAccContainerCluster_withAuthenticatorGroupsConfigUpdate(name string, orgDomain string) string {
return fmt.Sprintf(`
resource "google_compute_network" "container_network" {
name = "%s"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "container_subnetwork" {
name = google_compute_network.container_network.name
network = google_compute_network.container_network.name
ip_cidr_range = "10.0.36.0/24"
region = "us-central1"
private_ip_google_access = true
secondary_ip_range {
range_name = "pod"
ip_cidr_range = "10.0.0.0/19"
}
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
secondary_ip_range {
range_name = "svc"
ip_cidr_range = "10.0.32.0/22"
}
authenticator_groups_config {
security_group = "gke-security-groups@%s"
}
}
`, name, orgDomain)
}

resource "google_container_cluster" "with_authenticator_groups" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
network = google_compute_network.container_network.name
subnetwork = google_compute_subnetwork.container_subnetwork.name
authenticator_groups_config {
security_group = "gke-security-groups@%s"
}
func testAccContainerCluster_withAuthenticatorGroupsConfigUpdate2(name string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "primary" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
networking_mode = "VPC_NATIVE"
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
}
authenticator_groups_config {
security_group = ""
}
}
`, containerNetName, clusterName, orgDomain)
`, name)
}

func testAccContainerCluster_withMasterAuthorizedNetworksConfig(clusterName string, cidrs []string, emptyValue string) string {
Expand Down

0 comments on commit 26a7743

Please sign in to comment.