Skip to content

Commit fa64c75

Browse files
committed
add update cluster handling for gateway api config; extend test cases for gateway api config
1 parent c718126 commit fa64c75

3 files changed

Lines changed: 89 additions & 20 deletions

File tree

mmv1/third_party/terraform/resources/resource_container_cluster.go.erb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1722,10 +1722,9 @@ func resourceContainerCluster() *schema.Resource {
17221722
Schema: map[string]*schema.Schema{
17231723
"channel": {
17241724
Type: schema.TypeString,
1725-
Default: "CHANNEL_UNSPECIFIED",
1725+
Required: true,
17261726
ValidateFunc: validation.StringInSlice([]string{"CHANNEL_UNSPECIFIED", "CHANNEL_DISABLED", "CHANNEL_EXPERIMENTAL", "CHANNEL_STANDARD"}, false),
17271727
Description: `The Gateway API release channel to use for Gateway API.`,
1728-
Optional: true,
17291728
},
17301729
},
17311730
},
@@ -3335,6 +3334,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
33353334
log.Printf("[INFO] GKE cluster %s resource usage export config has been updated", d.Id())
33363335
}
33373336

3337+
if d.HasChange("gateway_api_config") {
3338+
if gac, ok := d.GetOk("gateway_api_config"); ok {
3339+
req := &container.UpdateClusterRequest{
3340+
Update: &container.ClusterUpdate{
3341+
DesiredGatewayApiConfig: expandGatewayApiConfig(gac),
3342+
},
3343+
}
3344+
3345+
updateF := updateFunc(req, "updating GKE Gateway API")
3346+
// Call update serially.
3347+
if err := lockedCall(lockKey, updateF); err != nil {
3348+
return err
3349+
}
3350+
3351+
log.Printf("[INFO] GKE cluster %s Gateway API has been updated", d.Id())
3352+
}
3353+
}
3354+
33383355
if d.HasChange("node_pool_defaults") && d.HasChange("node_pool_defaults.0.node_config_defaults.0.logging_variant") {
33393356
if v, ok := d.GetOk("node_pool_defaults.0.node_config_defaults.0.logging_variant"); ok {
33403357
loggingVariant := v.(string)

mmv1/third_party/terraform/tests/resource_container_cluster_test.go.erb

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3332,20 +3332,63 @@ func TestAccContainerCluster_withDNSConfig(t *testing.T) {
33323332

33333333
func TestAccContainerCluster_withGatewayApiConfig(t *testing.T) {
33343334
t.Parallel()
3335-
33363335
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
33373336
vcrTest(t, resource.TestCase{
33383337
PreCheck: func() { testAccPreCheck(t) },
33393338
Providers: testAccProviders,
33403339
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
33413340
Steps: []resource.TestStep{
3341+
{
3342+
Config: testAccContainerCluster_basic_1_24(clusterName),
3343+
},
3344+
{
3345+
ResourceName: "google_container_cluster.primary",
3346+
ImportState: true,
3347+
ImportStateVerify: true,
3348+
ImportStateVerifyIgnore: []string{"min_master_version"},
3349+
},
33423350
{
33433351
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_STANDARD"),
33443352
},
33453353
{
3346-
ResourceName: "google_container_cluster.with_gateway_api_config",
3354+
ResourceName: "google_container_cluster.primary",
33473355
ImportState: true,
33483356
ImportStateVerify: true,
3357+
ImportStateVerifyIgnore: []string{"min_master_version"},
3358+
},
3359+
{
3360+
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CHANNEL_EXPERIMENTAL"),
3361+
},
3362+
{
3363+
ResourceName: "google_container_cluster.primary",
3364+
ImportState: true,
3365+
ImportStateVerify: true,
3366+
ImportStateVerifyIgnore: []string{"min_master_version"},
3367+
},
3368+
{
3369+
Config: testAccContainerCluster_basic_1_24(clusterName),
3370+
},
3371+
{
3372+
ResourceName: "google_container_cluster.primary",
3373+
ImportState: true,
3374+
ImportStateVerify: true,
3375+
ImportStateVerifyIgnore: []string{"min_master_version"},
3376+
},
3377+
},
3378+
})
3379+
}
3380+
3381+
func TestAccContainerCluster_withInvalidGatewayApiConfigChannel(t *testing.T) {
3382+
t.Parallel()
3383+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
3384+
vcrTest(t, resource.TestCase{
3385+
PreCheck: func() { testAccPreCheck(t) },
3386+
Providers: testAccProviders,
3387+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
3388+
Steps: []resource.TestStep{
3389+
{
3390+
Config: testAccContainerCluster_withGatewayApiConfig(clusterName, "CANARY"),
3391+
ExpectError: regexp.MustCompile(`expected gateway_api_config\.0\.channel to be one of \[CHANNEL_UNSPECIFIED CHANNEL_DISABLED CHANNEL_EXPERIMENTAL CHANNEL_STANDARD\], got CANARY`),
33493392
},
33503393
},
33513394
})
@@ -3537,6 +3580,28 @@ resource "google_container_cluster" "primary" {
35373580
`, name)
35383581
}
35393582

3583+
func testAccContainerCluster_basic_1_23_8(name string) string {
3584+
return fmt.Sprintf(`
3585+
resource "google_container_cluster" "primary" {
3586+
name = "%s"
3587+
location = "us-central1-a"
3588+
initial_node_count = 1
3589+
min_master_version = "1.23.8-gke.1900"
3590+
}
3591+
`, name)
3592+
}
3593+
3594+
func testAccContainerCluster_basic_1_24(name string) string {
3595+
return fmt.Sprintf(`
3596+
resource "google_container_cluster" "primary" {
3597+
name = "%s"
3598+
location = "us-central1-a"
3599+
initial_node_count = 1
3600+
min_master_version = "1.24"
3601+
}
3602+
`, name)
3603+
}
3604+
35403605
func testAccContainerCluster_networkingModeRoutes(name string) string {
35413606
return fmt.Sprintf(`
35423607
resource "google_container_cluster" "primary" {
@@ -6607,13 +6672,11 @@ resource "google_container_cluster" "with_dns_config" {
66076672

66086673
func testAccContainerCluster_withGatewayApiConfig(clusterName string, gatewayApiChannel string) string {
66096674
return fmt.Sprintf(`
6610-
resource "google_container_cluster" "with_gateway_api_config" {
6675+
resource "google_container_cluster" "primary" {
66116676
name = "%s"
66126677
location = "us-central1-f"
66136678
initial_node_count = 1
6614-
release_channel {
6615-
channel = "RAPID"
6616-
}
6679+
min_master_version = "1.24"
66176680
gateway_api_config {
66186681
channel = "%s"
66196682
}
@@ -6694,17 +6757,6 @@ resource "google_container_cluster" "primary" {
66946757
`, name)
66956758
}
66966759

6697-
func testAccContainerCluster_basic_1_23_8(name string) string {
6698-
return fmt.Sprintf(`
6699-
resource "google_container_cluster" "primary" {
6700-
name = "%s"
6701-
location = "us-central1-a"
6702-
initial_node_count = 1
6703-
min_master_version = "1.23.8-gke.1900"
6704-
}
6705-
`, name)
6706-
}
6707-
67086760
func testAccContainerCluster_withMonitoringConfigEnabled(name string) string {
67096761
return fmt.Sprintf(`
67106762
resource "google_container_cluster" "primary" {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ and all pods running on the nodes. Specified as a map from the key, such as
11161116

11171117
<a name="nested_gateway_api_config"></a>The `gateway_api_config` block supports:
11181118

1119-
* `channel` - (Optional) Which in-cluster DNS provider should be used. `CHANNEL_UNSPECIFIED` (default) or `CHANNEL_DISABLED` or `CHANNEL_EXPERIMENTAL` or `CHANNEL_STANDARD`.
1119+
* `channel` - (Required) Which Gateway Api channel should be used. `CHANNEL_UNSPECIFIED` or `CHANNEL_DISABLED` or `CHANNEL_EXPERIMENTAL` or `CHANNEL_STANDARD`.
11201120

11211121
## Attributes Reference
11221122

0 commit comments

Comments
 (0)