Skip to content

Commit 8059e0b

Browse files
authored
Add Feature Service attachment tunneling config (#14602)
1 parent 1182f2f commit 8059e0b

File tree

3 files changed

+254
-0
lines changed

3 files changed

+254
-0
lines changed

mmv1/products/compute/ServiceAttachment.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ examples:
9595
producer_forwarding_rule_name: 'producer-forwarding-rule'
9696
consumer_address_name: 'psc-ilb-consumer-address'
9797
consumer_forwarding_rule_name: 'psc-ilb-consumer-forwarding-rule'
98+
- name: 'service_attachment_tunneling_config'
99+
primary_resource_id: 'psc_ilb_service_attachment'
100+
min_version: beta
101+
vars:
102+
service_attachment_name: 'my-psc-ilb'
103+
network_name: 'psc-ilb-network'
104+
nat_subnetwork_name: 'psc-ilb-nat'
105+
producer_subnetwork_name: 'psc-ilb-producer-subnetwork'
106+
producer_health_check_name: 'producer-service-health-check'
107+
producer_service_name: 'producer-service'
108+
producer_forwarding_rule_name: 'producer-forwarding-rule'
98109
- name: 'service_attachment_cross_region_ilb'
99110
primary_resource_id: 'psc_ilb_service_attachment'
100111
vars:
@@ -133,6 +144,22 @@ properties:
133144
Fingerprint of this resource. This field is used internally during
134145
updates of this resource.
135146
output: true
147+
- name: 'pscServiceAttachmentId'
148+
type: NestedObject
149+
description: |
150+
An 128-bit global unique ID of the PSC service attachment.
151+
output: true
152+
properties:
153+
- name: 'high'
154+
type: String
155+
description: |
156+
The high 64 bits of the PSC service attachment ID.
157+
output: true
158+
- name: 'low'
159+
type: String
160+
description: |
161+
The low 64 bits of the PSC service attachment ID.
162+
output: true
136163
- name: 'connectionPreference'
137164
type: String
138165
description: |
@@ -213,6 +240,21 @@ properties:
213240
immutable: true
214241
item_type:
215242
type: String
243+
- name: 'tunnelingConfig'
244+
type: NestedObject
245+
description: |
246+
Tunneling configuration for this service attachment.
247+
min_version: beta
248+
ignore_read: true
249+
properties:
250+
- name: 'routingMode'
251+
type: String
252+
description: |
253+
The routing mode for tunneling traffic.
254+
- name: 'encapsulationProfile'
255+
type: String
256+
description: |
257+
The encapsulation profile for tunneling traffic.
216258
- name: 'consumerRejectLists'
217259
type: Array
218260
description: |
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
provider "google-beta" {
2+
}
3+
4+
resource "google_compute_service_attachment" "{{$.PrimaryResourceId}}" {
5+
provider = google-beta
6+
7+
name = "{{index $.Vars "service_attachment_name"}}"
8+
region = "us-west2"
9+
description = "A service attachment configured with tunneling"
10+
11+
enable_proxy_protocol = false
12+
connection_preference = "ACCEPT_AUTOMATIC"
13+
nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
14+
target_service = google_compute_forwarding_rule.psc_ilb_target_service.id
15+
16+
tunneling_config {
17+
routing_mode = "REGIONAL"
18+
encapsulation_profile = "IPV4"
19+
}
20+
}
21+
22+
resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
23+
provider = google-beta
24+
25+
name = "{{index $.Vars "producer_forwarding_rule_name"}}"
26+
region = "us-west2"
27+
28+
load_balancing_scheme = "INTERNAL"
29+
backend_service = google_compute_region_backend_service.producer_service_backend.id
30+
all_ports = true
31+
network = google_compute_network.psc_ilb_network.name
32+
subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
33+
}
34+
35+
resource "google_compute_region_backend_service" "producer_service_backend" {
36+
provider = google-beta
37+
38+
name = "{{index $.Vars "producer_service_name"}}"
39+
region = "us-west2"
40+
41+
health_checks = [google_compute_health_check.producer_service_health_check.id]
42+
}
43+
44+
resource "google_compute_health_check" "producer_service_health_check" {
45+
provider = google-beta
46+
47+
name = "{{index $.Vars "producer_health_check_name"}}"
48+
49+
check_interval_sec = 1
50+
timeout_sec = 1
51+
tcp_health_check {
52+
port = "80"
53+
}
54+
}
55+
56+
resource "google_compute_network" "psc_ilb_network" {
57+
provider = google-beta
58+
59+
name = "{{index $.Vars "network_name"}}"
60+
auto_create_subnetworks = false
61+
}
62+
63+
resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
64+
provider = google-beta
65+
66+
name = "{{index $.Vars "producer_subnetwork_name"}}"
67+
region = "us-west2"
68+
69+
network = google_compute_network.psc_ilb_network.id
70+
ip_cidr_range = "10.0.0.0/16"
71+
}
72+
73+
resource "google_compute_subnetwork" "psc_ilb_nat" {
74+
provider = google-beta
75+
76+
name = "{{index $.Vars "nat_subnetwork_name"}}"
77+
region = "us-west2"
78+
79+
network = google_compute_network.psc_ilb_network.id
80+
purpose = "PRIVATE_SERVICE_CONNECT"
81+
ip_cidr_range = "10.1.0.0/16"
82+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package compute_test
2+
{{ if ne $.TargetVersionName `ga` -}}
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
7+
"github.com/hashicorp/terraform-provider-google/google/acctest"
8+
)
9+
10+
func TestAccComputeServiceAttachment_tunnelingConfigUpdate(t *testing.T) {
11+
t.Parallel()
12+
13+
context := map[string]interface{}{
14+
"random_suffix": acctest.RandString(t, 10),
15+
}
16+
17+
acctest.VcrTest(t, resource.TestCase{
18+
PreCheck: func() { acctest.AccTestPreCheck(t) },
19+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
20+
CheckDestroy: testAccCheckComputeServiceAttachmentDestroyProducer(t),
21+
Steps: []resource.TestStep{
22+
{
23+
Config: testAccComputeServiceAttachment_tunnelingConfig(context, "REGIONAL", "IPV4"),
24+
},
25+
{
26+
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
27+
ImportState: true,
28+
ImportStateVerify: true,
29+
ImportStateVerifyIgnore: []string{"target_service", "region", "tunneling_config"},
30+
},
31+
{
32+
Config: testAccComputeServiceAttachment_tunnelingConfig(context, "GLOBAL", "IPV6"),
33+
},
34+
{
35+
ResourceName: "google_compute_service_attachment.psc_ilb_service_attachment",
36+
ImportState: true,
37+
ImportStateVerify: true,
38+
ImportStateVerifyIgnore: []string{"target_service", "region", "tunneling_config"},
39+
},
40+
},
41+
})
42+
}
43+
44+
func testAccComputeServiceAttachment_tunnelingConfig(context map[string]interface{}, routingMode, encapsulationProfile string) string {
45+
context["routing_mode"] = routingMode
46+
context["encapsulation_profile"] = encapsulationProfile
47+
48+
return acctest.Nprintf(`
49+
resource "google_compute_service_attachment" "psc_ilb_service_attachment" {
50+
provider = google-beta
51+
52+
name = "tf-test-my-psc-ilb%{random_suffix}"
53+
region = "us-west2"
54+
description = "A service attachment configured with tunneling"
55+
56+
enable_proxy_protocol = false
57+
connection_preference = "ACCEPT_AUTOMATIC"
58+
nat_subnets = [google_compute_subnetwork.psc_ilb_nat.id]
59+
target_service = google_compute_forwarding_rule.psc_ilb_target_service.id
60+
61+
tunneling_config {
62+
routing_mode = "%{routing_mode}"
63+
encapsulation_profile = "%{encapsulation_profile}"
64+
}
65+
}
66+
67+
resource "google_compute_forwarding_rule" "psc_ilb_target_service" {
68+
provider = google-beta
69+
70+
name = "tf-test-producer-forwarding-rule%{random_suffix}"
71+
region = "us-west2"
72+
73+
load_balancing_scheme = "INTERNAL"
74+
backend_service = google_compute_region_backend_service.producer_service_backend.id
75+
all_ports = true
76+
network = google_compute_network.psc_ilb_network.name
77+
subnetwork = google_compute_subnetwork.psc_ilb_producer_subnetwork.name
78+
}
79+
80+
resource "google_compute_region_backend_service" "producer_service_backend" {
81+
provider = google-beta
82+
83+
name = "tf-test-producer-service%{random_suffix}"
84+
region = "us-west2"
85+
86+
health_checks = [google_compute_health_check.producer_service_health_check.id]
87+
}
88+
89+
resource "google_compute_health_check" "producer_service_health_check" {
90+
provider = google-beta
91+
92+
name = "tf-test-producer-service-health-check%{random_suffix}"
93+
94+
check_interval_sec = 1
95+
timeout_sec = 1
96+
tcp_health_check {
97+
port = "80"
98+
}
99+
}
100+
101+
resource "google_compute_network" "psc_ilb_network" {
102+
provider = google-beta
103+
104+
name = "tf-test-psc-ilb-network%{random_suffix}"
105+
auto_create_subnetworks = false
106+
}
107+
108+
resource "google_compute_subnetwork" "psc_ilb_producer_subnetwork" {
109+
provider = google-beta
110+
111+
name = "tf-test-psc-ilb-producer-subnetwork%{random_suffix}"
112+
region = "us-west2"
113+
114+
network = google_compute_network.psc_ilb_network.id
115+
ip_cidr_range = "10.0.0.0/16"
116+
}
117+
118+
resource "google_compute_subnetwork" "psc_ilb_nat" {
119+
provider = google-beta
120+
121+
name = "tf-test-psc-ilb-nat%{random_suffix}"
122+
region = "us-west2"
123+
124+
network = google_compute_network.psc_ilb_network.id
125+
purpose = "PRIVATE_SERVICE_CONNECT"
126+
ip_cidr_range = "10.1.0.0/16"
127+
}
128+
`, context)
129+
}
130+
{{- end }}

0 commit comments

Comments
 (0)