Skip to content

Commit cf0ec26

Browse files
Add Feature Service attachment tunneling config (#14602) (#10730)
[upstream:8059e0b433b96f9d1184c31a4bb4e19ad61ac0a1] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 2c58ee7 commit cf0ec26

File tree

6 files changed

+501
-5
lines changed

6 files changed

+501
-5
lines changed

.changelog/14602.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
compute: added `tunneling_config` field to `google_compute_service_attachment` resource (beta)
3+
```

google-beta/services/compute/resource_compute_service_attachment.go

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,26 @@ If true, update will affect both PENDING and ACCEPTED/REJECTED PSC endpoints. Fo
197197
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
198198
Description: `URL of the region where the resource resides.`,
199199
},
200+
"tunneling_config": {
201+
Type: schema.TypeList,
202+
Optional: true,
203+
Description: `Tunneling configuration for this service attachment.`,
204+
MaxItems: 1,
205+
Elem: &schema.Resource{
206+
Schema: map[string]*schema.Schema{
207+
"encapsulation_profile": {
208+
Type: schema.TypeString,
209+
Optional: true,
210+
Description: `The encapsulation profile for tunneling traffic.`,
211+
},
212+
"routing_mode": {
213+
Type: schema.TypeString,
214+
Optional: true,
215+
Description: `The routing mode for tunneling traffic.`,
216+
},
217+
},
218+
},
219+
},
200220
"connected_endpoints": {
201221
Type: schema.TypeList,
202222
Computed: true,
@@ -239,6 +259,25 @@ this service attachment.`,
239259
Description: `Fingerprint of this resource. This field is used internally during
240260
updates of this resource.`,
241261
},
262+
"psc_service_attachment_id": {
263+
Type: schema.TypeList,
264+
Computed: true,
265+
Description: `An 128-bit global unique ID of the PSC service attachment.`,
266+
Elem: &schema.Resource{
267+
Schema: map[string]*schema.Schema{
268+
"high": {
269+
Type: schema.TypeString,
270+
Computed: true,
271+
Description: `The high 64 bits of the PSC service attachment ID.`,
272+
},
273+
"low": {
274+
Type: schema.TypeString,
275+
Computed: true,
276+
Description: `The low 64 bits of the PSC service attachment ID.`,
277+
},
278+
},
279+
},
280+
},
242281
"send_propagated_connection_limit_if_zero": {
243282
Type: schema.TypeBool,
244283
Optional: true,
@@ -345,6 +384,12 @@ func resourceComputeServiceAttachmentCreate(d *schema.ResourceData, meta interfa
345384
} else if v, ok := d.GetOkExists("domain_names"); !tpgresource.IsEmptyValue(reflect.ValueOf(domainNamesProp)) && (ok || !reflect.DeepEqual(v, domainNamesProp)) {
346385
obj["domainNames"] = domainNamesProp
347386
}
387+
tunnelingConfigProp, err := expandComputeServiceAttachmentTunnelingConfig(d.Get("tunneling_config"), d, config)
388+
if err != nil {
389+
return err
390+
} else if v, ok := d.GetOkExists("tunneling_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(tunnelingConfigProp)) && (ok || !reflect.DeepEqual(v, tunnelingConfigProp)) {
391+
obj["tunnelingConfig"] = tunnelingConfigProp
392+
}
348393
consumerRejectListsProp, err := expandComputeServiceAttachmentConsumerRejectLists(d.Get("consumer_reject_lists"), d, config)
349394
if err != nil {
350395
return err
@@ -502,6 +547,9 @@ func resourceComputeServiceAttachmentRead(d *schema.ResourceData, meta interface
502547
if err := d.Set("fingerprint", flattenComputeServiceAttachmentFingerprint(res["fingerprint"], d, config)); err != nil {
503548
return fmt.Errorf("Error reading ServiceAttachment: %s", err)
504549
}
550+
if err := d.Set("psc_service_attachment_id", flattenComputeServiceAttachmentPscServiceAttachmentId(res["pscServiceAttachmentId"], d, config)); err != nil {
551+
return fmt.Errorf("Error reading ServiceAttachment: %s", err)
552+
}
505553
if err := d.Set("connection_preference", flattenComputeServiceAttachmentConnectionPreference(res["connectionPreference"], d, config)); err != nil {
506554
return fmt.Errorf("Error reading ServiceAttachment: %s", err)
507555
}
@@ -585,6 +633,12 @@ func resourceComputeServiceAttachmentUpdate(d *schema.ResourceData, meta interfa
585633
} else if v, ok := d.GetOkExists("enable_proxy_protocol"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, enableProxyProtocolProp)) {
586634
obj["enableProxyProtocol"] = enableProxyProtocolProp
587635
}
636+
tunnelingConfigProp, err := expandComputeServiceAttachmentTunnelingConfig(d.Get("tunneling_config"), d, config)
637+
if err != nil {
638+
return err
639+
} else if v, ok := d.GetOkExists("tunneling_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tunnelingConfigProp)) {
640+
obj["tunnelingConfig"] = tunnelingConfigProp
641+
}
588642
consumerRejectListsProp, err := expandComputeServiceAttachmentConsumerRejectLists(d.Get("consumer_reject_lists"), d, config)
589643
if err != nil {
590644
return err
@@ -750,6 +804,29 @@ func flattenComputeServiceAttachmentFingerprint(v interface{}, d *schema.Resourc
750804
return v
751805
}
752806

807+
func flattenComputeServiceAttachmentPscServiceAttachmentId(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
808+
if v == nil {
809+
return nil
810+
}
811+
original := v.(map[string]interface{})
812+
if len(original) == 0 {
813+
return nil
814+
}
815+
transformed := make(map[string]interface{})
816+
transformed["high"] =
817+
flattenComputeServiceAttachmentPscServiceAttachmentIdHigh(original["high"], d, config)
818+
transformed["low"] =
819+
flattenComputeServiceAttachmentPscServiceAttachmentIdLow(original["low"], d, config)
820+
return []interface{}{transformed}
821+
}
822+
func flattenComputeServiceAttachmentPscServiceAttachmentIdHigh(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
823+
return v
824+
}
825+
826+
func flattenComputeServiceAttachmentPscServiceAttachmentIdLow(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
827+
return v
828+
}
829+
753830
func flattenComputeServiceAttachmentConnectionPreference(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
754831
return v
755832
}
@@ -947,6 +1024,40 @@ func expandComputeServiceAttachmentDomainNames(v interface{}, d tpgresource.Terr
9471024
return v, nil
9481025
}
9491026

1027+
func expandComputeServiceAttachmentTunnelingConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1028+
l := v.([]interface{})
1029+
if len(l) == 0 || l[0] == nil {
1030+
return nil, nil
1031+
}
1032+
raw := l[0]
1033+
original := raw.(map[string]interface{})
1034+
transformed := make(map[string]interface{})
1035+
1036+
transformedRoutingMode, err := expandComputeServiceAttachmentTunnelingConfigRoutingMode(original["routing_mode"], d, config)
1037+
if err != nil {
1038+
return nil, err
1039+
} else if val := reflect.ValueOf(transformedRoutingMode); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1040+
transformed["routingMode"] = transformedRoutingMode
1041+
}
1042+
1043+
transformedEncapsulationProfile, err := expandComputeServiceAttachmentTunnelingConfigEncapsulationProfile(original["encapsulation_profile"], d, config)
1044+
if err != nil {
1045+
return nil, err
1046+
} else if val := reflect.ValueOf(transformedEncapsulationProfile); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1047+
transformed["encapsulationProfile"] = transformedEncapsulationProfile
1048+
}
1049+
1050+
return transformed, nil
1051+
}
1052+
1053+
func expandComputeServiceAttachmentTunnelingConfigRoutingMode(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1054+
return v, nil
1055+
}
1056+
1057+
func expandComputeServiceAttachmentTunnelingConfigEncapsulationProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1058+
return v, nil
1059+
}
1060+
9501061
func expandComputeServiceAttachmentConsumerRejectLists(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
9511062
return v, nil
9521063
}

google-beta/services/compute/resource_compute_service_attachment_generated_meta.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ fields:
2222
- field: 'name'
2323
- field: 'nat_subnets'
2424
- field: 'propagated_connection_limit'
25+
- field: 'psc_service_attachment_id.high'
26+
- field: 'psc_service_attachment_id.low'
2527
- field: 'reconcile_connections'
2628
- field: 'region'
2729
- field: 'send_propagated_connection_limit_if_zero'
2830
provider_only: true
2931
- field: 'target_service'
32+
- field: 'tunneling_config.encapsulation_profile'
33+
- field: 'tunneling_config.routing_mode'

google-beta/services/compute/resource_compute_service_attachment_generated_test.go

Lines changed: 117 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentBasicExample(t *testing.T)
4949
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
5050
ImportState: true,
5151
ImportStateVerify: true,
52-
ImportStateVerifyIgnore: []string{"region"},
52+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
5353
},
5454
},
5555
})
@@ -158,7 +158,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentExplicitProjectsExample(t
158158
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
159159
ImportState: true,
160160
ImportStateVerify: true,
161-
ImportStateVerifyIgnore: []string{"region"},
161+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
162162
},
163163
},
164164
})
@@ -274,7 +274,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentExplicitNetworksExample(t
274274
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
275275
ImportState: true,
276276
ImportStateVerify: true,
277-
ImportStateVerifyIgnore: []string{"region"},
277+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
278278
},
279279
},
280280
})
@@ -401,7 +401,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentReconcileConnectionsExampl
401401
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
402402
ImportState: true,
403403
ImportStateVerify: true,
404-
ImportStateVerifyIgnore: []string{"region"},
404+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
405405
},
406406
},
407407
})
@@ -482,6 +482,118 @@ resource "google_compute_subnetwork" "psc_ilb_nat" {
482482
`, context)
483483
}
484484

485+
func TestAccComputeServiceAttachment_serviceAttachmentTunnelingConfigExample(t *testing.T) {
486+
t.Parallel()
487+
488+
context := map[string]interface{}{
489+
"random_suffix": acctest.RandString(t, 10),
490+
}
491+
492+
acctest.VcrTest(t, resource.TestCase{
493+
PreCheck: func() { acctest.AccTestPreCheck(t) },
494+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
495+
CheckDestroy: testAccCheckComputeServiceAttachmentDestroyProducer(t),
496+
Steps: []resource.TestStep{
497+
{
498+
Config: testAccComputeServiceAttachment_serviceAttachmentTunnelingConfigExample(context),
499+
},
500+
{
501+
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
502+
ImportState: true,
503+
ImportStateVerify: true,
504+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
505+
},
506+
},
507+
})
508+
}
509+
510+
func testAccComputeServiceAttachment_serviceAttachmentTunnelingConfigExample(context map[string]interface{}) string {
511+
return acctest.Nprintf(`
512+
provider "google-beta" {
513+
}
514+
515+
resource "google_compute_service_attachment" "psc_ilb_service_attachment" {
516+
provider = google-beta
517+
518+
name = "tf-test-my-psc-ilb%{random_suffix}"
519+
region = "us-west2"
520+
description = "A service attachment configured with tunneling"
521+
522+
enable_proxy_protocol = false
523+
connection_preference = "ACCEPT_AUTOMATIC"
524+
nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
525+
target_service = google_compute_forwarding_rule.psc_ilb_target_service.id
526+
527+
tunneling_config {
528+
routing_mode = "REGIONAL"
529+
encapsulation_profile = "IPV4"
530+
}
531+
}
532+
533+
resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
534+
provider = google-beta
535+
536+
name = "tf-test-producer-forwarding-rule%{random_suffix}"
537+
region = "us-west2"
538+
539+
load_balancing_scheme = "INTERNAL"
540+
backend_service = google_compute_region_backend_service.producer_service_backend.id
541+
all_ports = true
542+
network = google_compute_network.psc_ilb_network.name
543+
subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
544+
}
545+
546+
resource "google_compute_region_backend_service" "producer_service_backend" {
547+
provider = google-beta
548+
549+
name = "tf-test-producer-service%{random_suffix}"
550+
region = "us-west2"
551+
552+
health_checks = [google_compute_health_check.producer_service_health_check.id]
553+
}
554+
555+
resource "google_compute_health_check" "producer_service_health_check" {
556+
provider = google-beta
557+
558+
name = "tf-test-producer-service-health-check%{random_suffix}"
559+
560+
check_interval_sec = 1
561+
timeout_sec = 1
562+
tcp_health_check {
563+
port = "80"
564+
}
565+
}
566+
567+
resource "google_compute_network" "psc_ilb_network" {
568+
provider = google-beta
569+
570+
name = "tf-test-psc-ilb-network%{random_suffix}"
571+
auto_create_subnetworks = false
572+
}
573+
574+
resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
575+
provider = google-beta
576+
577+
name = "tf-test-psc-ilb-producer-subnetwork%{random_suffix}"
578+
region = "us-west2"
579+
580+
network = google_compute_network.psc_ilb_network.id
581+
ip_cidr_range = "10.0.0.0/16"
582+
}
583+
584+
resource "google_compute_subnetwork" "psc_ilb_nat" {
585+
provider = google-beta
586+
587+
name = "tf-test-psc-ilb-nat%{random_suffix}"
588+
region = "us-west2"
589+
590+
network = google_compute_network.psc_ilb_network.id
591+
purpose = "PRIVATE_SERVICE_CONNECT"
592+
ip_cidr_range = "10.1.0.0/16"
593+
}
594+
`, context)
595+
}
596+
485597
func TestAccComputeServiceAttachment_serviceAttachmentCrossRegionIlbExample(t *testing.T) {
486598
t.Parallel()
487599

@@ -501,7 +613,7 @@ func TestAccComputeServiceAttachment_serviceAttachmentCrossRegionIlbExample(t *t
501613
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
502614
ImportState: true,
503615
ImportStateVerify: true,
504-
ImportStateVerifyIgnore: []string{"region"},
616+
ImportStateVerifyIgnore: []string{"region", "tunneling_config"},
505617
},
506618
},
507619
})

0 commit comments

Comments
 (0)