@@ -3,9 +3,10 @@ package compute_test
33import (
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
1112func 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 (`
22372281resource "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