Skip to content

Commit 1303e90

Browse files
ahmed-laiqrileykarson
authored andcommitted
Add fields to support for configuring Class ALB migration feature. (GoogleCloudPlatform#13926)
Co-authored-by: Riley Karson <[email protected]>
1 parent 88954bc commit 1303e90

File tree

4 files changed

+441
-14
lines changed

4 files changed

+441
-14
lines changed

mmv1/products/compute/BackendService.yaml

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,6 @@ properties:
860860
external load balancing. A backend service created for one type of
861861
load balancing cannot be used with the other. For more information, refer to
862862
[Choosing a load balancer](https://cloud.google.com/load-balancing/docs/backend-service).
863-
immutable: true
864863
default_value: "EXTERNAL"
865864
# If you're modifying this value, it probably means Global ILB is now
866865
# an option. If that's the case, all of the documentation is based on
@@ -870,6 +869,38 @@ properties:
870869
- 'INTERNAL_SELF_MANAGED'
871870
- 'INTERNAL_MANAGED'
872871
- 'EXTERNAL_MANAGED'
872+
- name: 'externalManagedMigrationState'
873+
type: Enum
874+
description: |
875+
Specifies the canary migration state. Possible values are PREPARE, TEST_BY_PERCENTAGE, and
876+
TEST_ALL_TRAFFIC.
877+
878+
To begin the migration from EXTERNAL to EXTERNAL_MANAGED, the state must be changed to
879+
PREPARE. The state must be changed to TEST_ALL_TRAFFIC before the loadBalancingScheme can be
880+
changed to EXTERNAL_MANAGED. Optionally, the TEST_BY_PERCENTAGE state can be used to migrate
881+
traffic by percentage using externalManagedMigrationTestingPercentage.
882+
883+
Rolling back a migration requires the states to be set in reverse order. So changing the
884+
scheme from EXTERNAL_MANAGED to EXTERNAL requires the state to be set to TEST_ALL_TRAFFIC at
885+
the same time. Optionally, the TEST_BY_PERCENTAGE state can be used to migrate some traffic
886+
back to EXTERNAL or PREPARE can be used to migrate all traffic back to EXTERNAL.
887+
enum_values:
888+
- 'PREPARE'
889+
- 'TEST_BY_PERCENTAGE'
890+
- 'TEST_ALL_TRAFFIC'
891+
- name: 'externalManagedMigrationTestingPercentage'
892+
type: Double
893+
description: |
894+
Determines the fraction of requests that should be processed by the Global external
895+
Application Load Balancer.
896+
897+
The value of this field must be in the range [0, 100].
898+
899+
Session affinity options will slightly affect this routing behavior, for more details,
900+
see: Session Affinity.
901+
902+
This value can only be set if the loadBalancingScheme in the backend service is set to
903+
EXTERNAL (when using the Classic ALB) and the migration state is TEST_BY_PERCENTAGE.
873904
- name: 'localityLbPolicy'
874905
type: Enum
875906
description: |

mmv1/products/compute/GlobalForwardingRule.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,8 @@ properties:
318318
- 'EXTERNAL_MANAGED'
319319
- 'INTERNAL_MANAGED'
320320
- 'INTERNAL_SELF_MANAGED'
321+
update_url: 'projects/{{project}}/global/forwardingRules/{{name}}'
322+
update_verb: 'PATCH'
321323
- name: 'metadataFilters'
322324
type: Array
323325
description: |
@@ -500,6 +502,40 @@ properties:
500502
enum_values:
501503
- 'PREMIUM'
502504
- 'STANDARD'
505+
- name: 'externalManagedBackendBucketMigrationState'
506+
type: Enum
507+
description: |
508+
Specifies the canary migration state for the backend buckets attached to this forwarding rule.
509+
Possible values are PREPARE, TEST_BY_PERCENTAGE, and TEST_ALL_TRAFFIC.
510+
511+
To begin the migration from EXTERNAL to EXTERNAL_MANAGED, the state must be changed to
512+
PREPARE. The state must be changed to TEST_ALL_TRAFFIC before the loadBalancingScheme can be
513+
changed to EXTERNAL_MANAGED. Optionally, the TEST_BY_PERCENTAGE state can be used to migrate
514+
traffic to backend buckets attached to this forwarding rule by percentage using
515+
externalManagedBackendBucketMigrationTestingPercentage.
516+
517+
Rolling back a migration requires the states to be set in reverse order. So changing the
518+
scheme from EXTERNAL_MANAGED to EXTERNAL requires the state to be set to TEST_ALL_TRAFFIC at
519+
the same time. Optionally, the TEST_BY_PERCENTAGE state can be used to migrate some traffic
520+
back to EXTERNAL or PREPARE can be used to migrate all traffic back to EXTERNAL.
521+
enum_values:
522+
- 'PREPARE'
523+
- 'TEST_BY_PERCENTAGE'
524+
- 'TEST_ALL_TRAFFIC'
525+
update_url: 'projects/{{project}}/global/forwardingRules/{{name}}'
526+
update_verb: 'PATCH'
527+
- name: 'externalManagedBackendBucketMigrationTestingPercentage'
528+
type: Double
529+
description: |
530+
Determines the fraction of requests to backend buckets that should be processed by the Global
531+
external Application Load Balancer.
532+
533+
The value of this field must be in the range [0, 100].
534+
535+
This value can only be set if the loadBalancingScheme in the forwarding rule is set to
536+
EXTERNAL (when using the Classic ALB) and the migration state is TEST_BY_PERCENTAGE.
537+
update_url: 'projects/{{project}}/global/forwardingRules/{{name}}'
538+
update_verb: 'PATCH'
503539
- name: 'serviceDirectoryRegistrations'
504540
type: Array
505541
description: |

mmv1/third_party/terraform/services/compute/resource_compute_backend_service_test.go.tmpl

Lines changed: 194 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package compute_test
33
import (
44
"fmt"
55
"testing"
6-
"github.com/hashicorp/terraform-provider-google/google/acctest"
76

87
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
9+
"github.com/hashicorp/terraform-provider-google/google/acctest"
910
)
1011

1112
func TestAccComputeBackendService_basic(t *testing.T) {
@@ -146,57 +147,85 @@ func TestAccComputeBackendService_withBackendAndIAP(t *testing.T) {
146147
})
147148
}
148149

149-
func TestAccComputeBackendService_withBackendAndPreference(t *testing.T) {
150+
func TestAccComputeBackendService_withBackendAndPreferenceInternalManaged(t *testing.T) {
150151
t.Parallel()
151152

152-
randomSuffix := acctest.RandString(t, 10)
153+
im_suffix := fmt.Sprintf("im-%s", acctest.RandString(t, 10))
154+
153155
acctest.VcrTest(t, resource.TestCase{
154156
PreCheck: func() { acctest.AccTestPreCheck(t) },
155157
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
156158
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
157159
Steps: []resource.TestStep{
158160
{
159-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "INTERNAL_MANAGED", "DEFAULT", 10),
161+
Config: testAccComputeBackendService_withBackendAndPreference(im_suffix, "INTERNAL_MANAGED", "DEFAULT", 10),
160162
},
161163
{
162164
ResourceName: "google_compute_backend_service.lipsum",
163165
ImportState: true,
164166
ImportStateVerify: true,
165167
},
166168
{
167-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "INTERNAL_MANAGED", "PREFERRED", 20),
169+
Config: testAccComputeBackendService_withBackendAndPreference(im_suffix, "INTERNAL_MANAGED", "PREFERRED", 20),
168170
},
169171
{
170172
ResourceName: "google_compute_backend_service.lipsum",
171173
ImportState: true,
172174
ImportStateVerify: true,
173175
},
176+
},
177+
})
178+
}
179+
180+
func TestAccComputeBackendService_withBackendAndPreferenceInternalSelfManaged(t *testing.T) {
181+
t.Parallel()
182+
183+
ism_suffix := fmt.Sprintf("ism-%s", acctest.RandString(t, 10))
184+
185+
acctest.VcrTest(t, resource.TestCase{
186+
PreCheck: func() { acctest.AccTestPreCheck(t) },
187+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
188+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
189+
Steps: []resource.TestStep{
174190
{
175-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "INTERNAL_SELF_MANAGED", "DEFAULT", 10),
191+
Config: testAccComputeBackendService_withBackendAndPreference(ism_suffix, "INTERNAL_SELF_MANAGED", "DEFAULT", 10),
176192
},
177193
{
178194
ResourceName: "google_compute_backend_service.lipsum",
179195
ImportState: true,
180196
ImportStateVerify: true,
181197
},
182198
{
183-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "INTERNAL_SELF_MANAGED", "PREFERRED", 20),
199+
Config: testAccComputeBackendService_withBackendAndPreference(ism_suffix, "INTERNAL_SELF_MANAGED", "PREFERRED", 20),
184200
},
185201
{
186202
ResourceName: "google_compute_backend_service.lipsum",
187203
ImportState: true,
188204
ImportStateVerify: true,
189205
},
190-
{
191-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "EXTERNAL_MANAGED", "DEFAULT", 10),
206+
},
207+
})
208+
}
209+
210+
func TestAccComputeBackendService_withBackendAndPreferenceExternalManaged(t *testing.T) {
211+
t.Parallel()
212+
em_suffix := fmt.Sprintf("em-%s", acctest.RandString(t, 10))
213+
214+
acctest.VcrTest(t, resource.TestCase{
215+
PreCheck: func() { acctest.AccTestPreCheck(t) },
216+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
217+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
218+
Steps: []resource.TestStep{
219+
{
220+
Config: testAccComputeBackendService_withBackendAndPreference(em_suffix, "EXTERNAL_MANAGED", "DEFAULT", 10),
192221
},
193222
{
194223
ResourceName: "google_compute_backend_service.lipsum",
195224
ImportState: true,
196225
ImportStateVerify: true,
197226
},
198227
{
199-
Config: testAccComputeBackendService_withBackendAndPreference(randomSuffix, "EXTERNAL_MANAGED", "PREFERRED", 20),
228+
Config: testAccComputeBackendService_withBackendAndPreference(em_suffix, "EXTERNAL_MANAGED", "PREFERRED", 20),
200229
},
201230
{
202231
ResourceName: "google_compute_backend_service.lipsum",
@@ -789,16 +818,31 @@ func TestAccComputeBackendService_withLogConfig(t *testing.T) {
789818
ImportState: true,
790819
ImportStateVerify: true,
791820
},
821+
},
822+
})
823+
}
824+
825+
func TestAccComputeBackendService_withLogConfigMode(t *testing.T) {
826+
t.Parallel()
827+
828+
serviceName := fmt.Sprintf("tf-test-lc-%s", acctest.RandString(t, 10))
829+
checkName := fmt.Sprintf("tf-test-lc-%s", acctest.RandString(t, 10))
830+
831+
acctest.VcrTest(t, resource.TestCase{
832+
PreCheck: func() { acctest.AccTestPreCheck(t) },
833+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
834+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
835+
Steps: []resource.TestStep{
792836
{
793-
Config: testAccComputeBackendService_withLogConfig3(serviceName, checkName, "INCLUDE_ALL_OPTIONAL", true),
837+
Config: testAccComputeBackendService_withLogConfigMode(serviceName, checkName, "INCLUDE_ALL_OPTIONAL", true),
794838
},
795839
{
796840
ResourceName: "google_compute_backend_service.foobar",
797841
ImportState: true,
798842
ImportStateVerify: true,
799843
},
800844
{
801-
Config: testAccComputeBackendService_withLogConfig3(serviceName, checkName, "EXCLUDE_ALL_OPTIONAL", true),
845+
Config: testAccComputeBackendService_withLogConfigMode(serviceName, checkName, "EXCLUDE_ALL_OPTIONAL", true),
802846
},
803847
{
804848
ResourceName: "google_compute_backend_service.foobar",
@@ -2232,7 +2276,7 @@ resource "google_compute_http_health_check" "zero" {
22322276
`, serviceName, enabled, checkName)
22332277
}
22342278

2235-
func testAccComputeBackendService_withLogConfig3(serviceName, checkName, mode string, enabled bool) string {
2279+
func testAccComputeBackendService_withLogConfigMode(serviceName, checkName, mode string, enabled bool) string {
22362280
return fmt.Sprintf(`
22372281
resource "google_compute_backend_service" "foobar" {
22382282
name = "%s"
@@ -2686,3 +2730,140 @@ resource "google_compute_health_check" "health_check" {
26862730
}
26872731
`, suffix, timeout, loadBalancingScheme, preference, suffix, suffix, suffix)
26882732
}
2733+
2734+
func TestAccComputeBackendService_updateCanaryMigration(t *testing.T) {
2735+
t.Parallel()
2736+
2737+
serviceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
2738+
checkName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
2739+
2740+
acctest.VcrTest(t, resource.TestCase{
2741+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2742+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2743+
ExternalProviders: map[string]resource.ExternalProvider{
2744+
"time": {},
2745+
},
2746+
CheckDestroy: testAccCheckComputeBackendServiceDestroyProducer(t),
2747+
Steps: []resource.TestStep{
2748+
{
2749+
Config: testAccComputeBackendService_basic(serviceName, checkName),
2750+
},
2751+
{
2752+
ResourceName: "google_compute_backend_service.foobar",
2753+
ImportState: true,
2754+
ImportStateVerify: true,
2755+
},
2756+
{
2757+
Config: testAccComputeBackendService_withCanaryMigration(
2758+
serviceName, checkName, "updated-to-prepare", "PREPARE"),
2759+
ConfigPlanChecks: resource.ConfigPlanChecks{
2760+
PreApply: []plancheck.PlanCheck{
2761+
plancheck.ExpectResourceAction("google_compute_backend_service.foobar", plancheck.ResourceActionUpdate),
2762+
},
2763+
},
2764+
},
2765+
{
2766+
ResourceName: "google_compute_backend_service.foobar",
2767+
ImportState: true,
2768+
ImportStateVerify: true,
2769+
},
2770+
{
2771+
Config: testAccComputeBackendService_withCanaryMigrationPercentage(
2772+
serviceName, checkName, "updated-to-percentage", 50),
2773+
ConfigPlanChecks: resource.ConfigPlanChecks{
2774+
PreApply: []plancheck.PlanCheck{
2775+
plancheck.ExpectResourceAction("google_compute_backend_service.foobar", plancheck.ResourceActionUpdate),
2776+
},
2777+
},
2778+
},
2779+
{
2780+
ResourceName: "google_compute_backend_service.foobar",
2781+
ImportState: true,
2782+
ImportStateVerify: true,
2783+
},
2784+
{
2785+
Config: testAccComputeBackendService_withCanaryMigration(
2786+
serviceName, checkName, "update-to-all", "TEST_ALL_TRAFFIC"),
2787+
ConfigPlanChecks: resource.ConfigPlanChecks{
2788+
PreApply: []plancheck.PlanCheck{
2789+
plancheck.ExpectResourceAction("google_compute_backend_service.foobar", plancheck.ResourceActionUpdate),
2790+
},
2791+
},
2792+
},
2793+
{
2794+
ResourceName: "google_compute_backend_service.foobar",
2795+
ImportState: true,
2796+
ImportStateVerify: true,
2797+
},
2798+
},
2799+
})
2800+
}
2801+
2802+
func testAccComputeBackendService_withCanaryMigration(serviceName, checkName, description, migrationState string) string {
2803+
return fmt.Sprintf(`
2804+
resource "google_compute_backend_service" "foobar" {
2805+
name = "%s"
2806+
description = "%s"
2807+
health_checks = [google_compute_http_health_check.zero.self_link]
2808+
external_managed_migration_state = "%s"
2809+
}
2810+
2811+
resource "google_compute_http_health_check" "zero" {
2812+
name = "%s"
2813+
request_path = "/"
2814+
check_interval_sec = 1
2815+
timeout_sec = 1
2816+
}
2817+
`, serviceName, description, migrationState, checkName)
2818+
}
2819+
2820+
func testAccComputeBackendService_withCanaryMigrationWithWait(serviceName, checkName, description, migrationState string) string {
2821+
return fmt.Sprintf(`
2822+
resource "time_sleep" "six_minutes_delay" {
2823+
create_duration = "370s" # litte more than 6 minutes (360 seconds = 6 minutes)
2824+
}
2825+
2826+
resource "google_compute_backend_service" "foobar" {
2827+
name = "%s"
2828+
description = "%s"
2829+
health_checks = [google_compute_http_health_check.zero.self_link]
2830+
external_managed_migration_state = "%s"
2831+
depends_on = [
2832+
time_sleep.six_minutes_delay
2833+
]
2834+
}
2835+
2836+
resource "google_compute_http_health_check" "zero" {
2837+
name = "%s"
2838+
request_path = "/"
2839+
check_interval_sec = 1
2840+
timeout_sec = 1
2841+
}
2842+
`, serviceName, description, migrationState, checkName)
2843+
}
2844+
2845+
func testAccComputeBackendService_withCanaryMigrationPercentage(serviceName, checkName, description string, percentage int64) string {
2846+
return fmt.Sprintf(`
2847+
resource "time_sleep" "six_minutes_delay" {
2848+
create_duration = "370s" # litte more than 6 minutes (360 seconds = 6 minutes)
2849+
}
2850+
2851+
resource "google_compute_backend_service" "foobar" {
2852+
name = "%s"
2853+
description = "%s"
2854+
health_checks = [google_compute_http_health_check.zero.self_link]
2855+
external_managed_migration_state = "TEST_BY_PERCENTAGE"
2856+
external_managed_migration_testing_percentage = %d
2857+
depends_on = [
2858+
time_sleep.six_minutes_delay
2859+
]
2860+
}
2861+
2862+
resource "google_compute_http_health_check" "zero" {
2863+
name = "%s"
2864+
request_path = "/"
2865+
check_interval_sec = 1
2866+
timeout_sec = 1
2867+
}
2868+
`, serviceName, description, percentage, checkName)
2869+
}

0 commit comments

Comments
 (0)