Skip to content

Commit 6f2fbc0

Browse files
Create Tls Inspection Policy resource and update Gateway Security Policy to use the field tlsInspectionPolicy (#7880) (#5615)
* adding the resources, the examples and the tests * updates in the tsl resource, added fix in the tests files, but not creating the tls resource, just the ca pool * adding a todo for certificate authority * adding the resource of certificate, need to fix the error while deleting * fixed the creation of ca and capool, receiving error 13 for tls creation * removing advanced example, adding capool fields for tests, failing in tls creation * updating the ca_pool to add into the tls, not working * fix the tests, concurrency problem, solved with depends_on field * updating the gateway security policy to use tls inpection policy * fixing the test scenario for tls_inspection basic * fix a typo in documentation for tls resource and the name of file test * adding a new field in the resource and in the test scenario, adding a todo for a field with a resource not implemented Signed-off-by: Modular Magician <[email protected]>
1 parent ec6bab3 commit 6f2fbc0

10 files changed

+1294
-4
lines changed

.changelog/7880.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
```release-note:enhancement
2+
`google_network_security_gateway_security_policy`
3+
`google_network_security_tls_inspection_policy`
4+
```

google-beta/provider.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,9 @@ func Provider() *schema.Provider {
807807
return provider
808808
}
809809

810-
// Generated resources: 338
810+
// Generated resources: 339
811811
// Generated IAM resources: 219
812-
// Total generated resources: 557
812+
// Total generated resources: 558
813813
func ResourceMap() map[string]*schema.Resource {
814814
resourceMap, _ := ResourceMapWithErrors()
815815
return resourceMap
@@ -1247,6 +1247,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12471247
"google_network_security_client_tls_policy": ResourceNetworkSecurityClientTlsPolicy(),
12481248
"google_network_security_gateway_security_policy": ResourceNetworkSecurityGatewaySecurityPolicy(),
12491249
"google_network_security_gateway_security_policy_rule": ResourceNetworkSecurityGatewaySecurityPolicyRule(),
1250+
"google_network_security_tls_inspection_policy": ResourceNetworkSecurityTlsInspectionPolicy(),
12501251
"google_network_security_url_lists": ResourceNetworkSecurityUrlLists(),
12511252
"google_network_services_edge_cache_keyset": ResourceNetworkServicesEdgeCacheKeyset(),
12521253
"google_network_services_edge_cache_origin": ResourceNetworkServicesEdgeCacheOrigin(),

google-beta/resource_network_security_gateway_security_policy.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ gatewaySecurityPolicy should match the pattern:(^a-z?$).`,
6363
The default value is 'global'.`,
6464
Default: "global",
6565
},
66+
"tls_inspection_policy": {
67+
Type: schema.TypeString,
68+
Optional: true,
69+
Description: `Name of a TlsInspectionPolicy resource that defines how TLS inspection is performed for any rule that enables it.`,
70+
},
6671
"create_time": {
6772
Type: schema.TypeString,
6873
Computed: true,
@@ -107,6 +112,12 @@ func resourceNetworkSecurityGatewaySecurityPolicyCreate(d *schema.ResourceData,
107112
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
108113
obj["description"] = descriptionProp
109114
}
115+
tlsInspectionPolicyProp, err := expandNetworkSecurityGatewaySecurityPolicyTlsInspectionPolicy(d.Get("tls_inspection_policy"), d, config)
116+
if err != nil {
117+
return err
118+
} else if v, ok := d.GetOkExists("tls_inspection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(tlsInspectionPolicyProp)) && (ok || !reflect.DeepEqual(v, tlsInspectionPolicyProp)) {
119+
obj["tlsInspectionPolicy"] = tlsInspectionPolicyProp
120+
}
110121

111122
url, err := tpgresource.ReplaceVars(d, config, "{{NetworkSecurityBasePath}}projects/{{project}}/locations/{{location}}/gatewaySecurityPolicies?gatewaySecurityPolicyId={{name}}")
112123
if err != nil {
@@ -226,6 +237,12 @@ func resourceNetworkSecurityGatewaySecurityPolicyUpdate(d *schema.ResourceData,
226237
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
227238
obj["description"] = descriptionProp
228239
}
240+
tlsInspectionPolicyProp, err := expandNetworkSecurityGatewaySecurityPolicyTlsInspectionPolicy(d.Get("tls_inspection_policy"), d, config)
241+
if err != nil {
242+
return err
243+
} else if v, ok := d.GetOkExists("tls_inspection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tlsInspectionPolicyProp)) {
244+
obj["tlsInspectionPolicy"] = tlsInspectionPolicyProp
245+
}
229246

230247
url, err := tpgresource.ReplaceVars(d, config, "{{NetworkSecurityBasePath}}projects/{{project}}/locations/{{location}}/gatewaySecurityPolicies/{{name}}")
231248
if err != nil {
@@ -238,6 +255,10 @@ func resourceNetworkSecurityGatewaySecurityPolicyUpdate(d *schema.ResourceData,
238255
if d.HasChange("description") {
239256
updateMask = append(updateMask, "description")
240257
}
258+
259+
if d.HasChange("tls_inspection_policy") {
260+
updateMask = append(updateMask, "tlsInspectionPolicy")
261+
}
241262
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
242263
// won't set it
243264
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -353,3 +374,7 @@ func flattenNetworkSecurityGatewaySecurityPolicyDescription(v interface{}, d *sc
353374
func expandNetworkSecurityGatewaySecurityPolicyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
354375
return v, nil
355376
}
377+
378+
func expandNetworkSecurityGatewaySecurityPolicyTlsInspectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
379+
return v, nil
380+
}

google-beta/resource_network_security_gateway_security_policy_generated_test.go

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityP
4646
ResourceName: "google_network_security_gateway_security_policy.default",
4747
ImportState: true,
4848
ImportStateVerify: true,
49-
ImportStateVerifyIgnore: []string{"name", "location"},
49+
ImportStateVerifyIgnore: []string{"tls_inspection_policy", "name", "location"},
5050
},
5151
},
5252
})
@@ -63,6 +63,115 @@ resource "google_network_security_gateway_security_policy" "default" {
6363
`, context)
6464
}
6565

66+
func TestAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(t *testing.T) {
67+
t.Parallel()
68+
69+
context := map[string]interface{}{
70+
"random_suffix": RandString(t, 10),
71+
}
72+
73+
VcrTest(t, resource.TestCase{
74+
PreCheck: func() { acctest.AccTestPreCheck(t) },
75+
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
76+
CheckDestroy: testAccCheckNetworkSecurityGatewaySecurityPolicyDestroyProducer(t),
77+
Steps: []resource.TestStep{
78+
{
79+
Config: testAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(context),
80+
},
81+
{
82+
ResourceName: "google_network_security_gateway_security_policy.default",
83+
ImportState: true,
84+
ImportStateVerify: true,
85+
ImportStateVerifyIgnore: []string{"tls_inspection_policy", "name", "location"},
86+
},
87+
},
88+
})
89+
}
90+
91+
func testAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(context map[string]interface{}) string {
92+
return Nprintf(`
93+
resource "google_privateca_ca_pool" "default" {
94+
provider = google-beta
95+
name = "tf-test-my-basic-ca-pool%{random_suffix}"
96+
location = "us-central1"
97+
tier = "DEVOPS"
98+
publishing_options {
99+
publish_ca_cert = false
100+
publish_crl = false
101+
}
102+
issuance_policy {
103+
maximum_lifetime = "1209600s"
104+
baseline_values {
105+
ca_options {
106+
is_ca = false
107+
}
108+
key_usage {
109+
base_key_usage {}
110+
extended_key_usage {
111+
server_auth = true
112+
}
113+
}
114+
}
115+
}
116+
}
117+
118+
119+
resource "google_privateca_certificate_authority" "default" {
120+
provider = google-beta
121+
pool = google_privateca_ca_pool.default.name
122+
certificate_authority_id = "tf-test-my-basic-certificate-authority%{random_suffix}"
123+
location = "us-central1"
124+
lifetime = "86400s"
125+
type = "SELF_SIGNED"
126+
deletion_protection = false
127+
skip_grace_period = true
128+
ignore_active_certificates_on_deletion = true
129+
config {
130+
subject_config {
131+
subject {
132+
organization = "Test LLC"
133+
common_name = "my-ca"
134+
}
135+
}
136+
x509_config {
137+
ca_options {
138+
is_ca = true
139+
}
140+
key_usage {
141+
base_key_usage {
142+
cert_sign = true
143+
crl_sign = true
144+
}
145+
extended_key_usage {
146+
server_auth = false
147+
}
148+
}
149+
}
150+
}
151+
key_spec {
152+
algorithm = "RSA_PKCS1_4096_SHA256"
153+
}
154+
}
155+
156+
resource "google_network_security_tls_inspection_policy" "default" {
157+
provider = google-beta
158+
name = "tf-test-my-tls-inspection-policy%{random_suffix}"
159+
location = "us-central1"
160+
ca_pool = google_privateca_ca_pool.default.id
161+
depends_on = [google_privateca_ca_pool.default, google_privateca_certificate_authority.default]
162+
}
163+
164+
resource "google_network_security_gateway_security_policy" "default" {
165+
provider = google-beta
166+
name = "tf-test-my-gateway-security-policy%{random_suffix}"
167+
location = "us-central1"
168+
description = "my description"
169+
tls_inspection_policy = google_network_security_tls_inspection_policy.default.id
170+
depends_on = [google_network_security_tls_inspection_policy.default]
171+
}
172+
`, context)
173+
}
174+
66175
func testAccCheckNetworkSecurityGatewaySecurityPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error {
67176
return func(s *terraform.State) error {
68177
for name, rs := range s.RootModule().Resources {

0 commit comments

Comments
 (0)