Skip to content

Commit 3d8fce7

Browse files
adds NGFW support for google_network_security_tls_inspection_policy resource (#9864) (#7368)
[upstream:ebfd96bd8d7a1f13c352a2645d02407da4317021] Signed-off-by: Modular Magician <[email protected]>
1 parent 19a4049 commit 3d8fce7

File tree

3 files changed

+453
-0
lines changed

3 files changed

+453
-0
lines changed

google-beta/services/networksecurity/resource_network_security_tls_inspection_policy.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
3232
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
33+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
3334
)
3435

3536
func ResourceNetworkSecurityTlsInspectionPolicy() *schema.Resource {
@@ -64,6 +65,14 @@ func ResourceNetworkSecurityTlsInspectionPolicy() *schema.Resource {
6465
Required: true,
6566
Description: `Short name of the TlsInspectionPolicy resource to be created.`,
6667
},
68+
"custom_tls_features": {
69+
Type: schema.TypeList,
70+
Optional: true,
71+
Description: `List of custom TLS cipher suites selected. This field is valid only if the selected tls_feature_profile is CUSTOM. The compute.SslPoliciesService.ListAvailableFeatures method returns the set of features that can be specified in this list. Note that Secure Web Proxy does not yet honor this field.`,
72+
Elem: &schema.Schema{
73+
Type: schema.TypeString,
74+
},
75+
},
6776
"description": {
6877
Type: schema.TypeString,
6978
Optional: true,
@@ -79,6 +88,24 @@ func ResourceNetworkSecurityTlsInspectionPolicy() *schema.Resource {
7988
Optional: true,
8089
Description: `The location of the tls inspection policy.`,
8190
},
91+
"min_tls_version": {
92+
Type: schema.TypeString,
93+
Optional: true,
94+
ValidateFunc: verify.ValidateEnum([]string{"TLS_VERSION_UNSPECIFIED", "TLS_1_0", "TLS_1_1", "TLS_1_2", "TLS_1_3", ""}),
95+
Description: `Minimum TLS version that the firewall should use when negotiating connections with both clients and servers. If this is not set, then the default value is to allow the broadest set of clients and servers (TLS 1.0 or higher). Setting this to more restrictive values may improve security, but may also prevent the firewall from connecting to some clients or servers. Note that Secure Web Proxy does not yet honor this field. Possible values: ["TLS_VERSION_UNSPECIFIED", "TLS_1_0", "TLS_1_1", "TLS_1_2", "TLS_1_3"]`,
96+
},
97+
"tls_feature_profile": {
98+
Type: schema.TypeString,
99+
Optional: true,
100+
ValidateFunc: verify.ValidateEnum([]string{"PROFILE_UNSPECIFIED", "PROFILE_COMPATIBLE", "PROFILE_MODERN", "PROFILE_RESTRICTED", "PROFILE_CUSTOM", ""}),
101+
Description: `The selected Profile. If this is not set, then the default value is to allow the broadest set of clients and servers (\"PROFILE_COMPATIBLE\"). Setting this to more restrictive values may improve security, but may also prevent the TLS inspection proxy from connecting to some clients or servers. Note that Secure Web Proxy does not yet honor this field. Possible values: ["PROFILE_UNSPECIFIED", "PROFILE_COMPATIBLE", "PROFILE_MODERN", "PROFILE_RESTRICTED", "PROFILE_CUSTOM"]`,
102+
},
103+
"trust_config": {
104+
Type: schema.TypeString,
105+
Optional: true,
106+
DiffSuppressFunc: tpgresource.ProjectNumberDiffSuppress,
107+
Description: `A TrustConfig resource used when making a connection to the TLS server. This is a relative resource path following the form \"projects/{project}/locations/{location}/trustConfigs/{trust_config}\". This is necessary to intercept TLS connections to servers with certificates signed by a private CA or self-signed certificates. Trust config and the TLS inspection policy must be in the same region. Note that Secure Web Proxy does not yet honor this field.`,
108+
},
82109
"create_time": {
83110
Type: schema.TypeString,
84111
Computed: true,
@@ -120,6 +147,30 @@ func resourceNetworkSecurityTlsInspectionPolicyCreate(d *schema.ResourceData, me
120147
} else if v, ok := d.GetOkExists("ca_pool"); !tpgresource.IsEmptyValue(reflect.ValueOf(caPoolProp)) && (ok || !reflect.DeepEqual(v, caPoolProp)) {
121148
obj["caPool"] = caPoolProp
122149
}
150+
trustConfigProp, err := expandNetworkSecurityTlsInspectionPolicyTrustConfig(d.Get("trust_config"), d, config)
151+
if err != nil {
152+
return err
153+
} else if v, ok := d.GetOkExists("trust_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(trustConfigProp)) && (ok || !reflect.DeepEqual(v, trustConfigProp)) {
154+
obj["trustConfig"] = trustConfigProp
155+
}
156+
minTlsVersionProp, err := expandNetworkSecurityTlsInspectionPolicyMinTlsVersion(d.Get("min_tls_version"), d, config)
157+
if err != nil {
158+
return err
159+
} else if v, ok := d.GetOkExists("min_tls_version"); !tpgresource.IsEmptyValue(reflect.ValueOf(minTlsVersionProp)) && (ok || !reflect.DeepEqual(v, minTlsVersionProp)) {
160+
obj["minTlsVersion"] = minTlsVersionProp
161+
}
162+
tlsFeatureProfileProp, err := expandNetworkSecurityTlsInspectionPolicyTlsFeatureProfile(d.Get("tls_feature_profile"), d, config)
163+
if err != nil {
164+
return err
165+
} else if v, ok := d.GetOkExists("tls_feature_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(tlsFeatureProfileProp)) && (ok || !reflect.DeepEqual(v, tlsFeatureProfileProp)) {
166+
obj["tlsFeatureProfile"] = tlsFeatureProfileProp
167+
}
168+
customTlsFeaturesProp, err := expandNetworkSecurityTlsInspectionPolicyCustomTlsFeatures(d.Get("custom_tls_features"), d, config)
169+
if err != nil {
170+
return err
171+
} else if v, ok := d.GetOkExists("custom_tls_features"); !tpgresource.IsEmptyValue(reflect.ValueOf(customTlsFeaturesProp)) && (ok || !reflect.DeepEqual(v, customTlsFeaturesProp)) {
172+
obj["customTlsFeatures"] = customTlsFeaturesProp
173+
}
123174
excludePublicCaSetProp, err := expandNetworkSecurityTlsInspectionPolicyExcludePublicCaSet(d.Get("exclude_public_ca_set"), d, config)
124175
if err != nil {
125176
return err
@@ -237,6 +288,18 @@ func resourceNetworkSecurityTlsInspectionPolicyRead(d *schema.ResourceData, meta
237288
if err := d.Set("ca_pool", flattenNetworkSecurityTlsInspectionPolicyCaPool(res["caPool"], d, config)); err != nil {
238289
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
239290
}
291+
if err := d.Set("trust_config", flattenNetworkSecurityTlsInspectionPolicyTrustConfig(res["trustConfig"], d, config)); err != nil {
292+
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
293+
}
294+
if err := d.Set("min_tls_version", flattenNetworkSecurityTlsInspectionPolicyMinTlsVersion(res["minTlsVersion"], d, config)); err != nil {
295+
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
296+
}
297+
if err := d.Set("tls_feature_profile", flattenNetworkSecurityTlsInspectionPolicyTlsFeatureProfile(res["tlsFeatureProfile"], d, config)); err != nil {
298+
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
299+
}
300+
if err := d.Set("custom_tls_features", flattenNetworkSecurityTlsInspectionPolicyCustomTlsFeatures(res["customTlsFeatures"], d, config)); err != nil {
301+
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
302+
}
240303
if err := d.Set("exclude_public_ca_set", flattenNetworkSecurityTlsInspectionPolicyExcludePublicCaSet(res["excludePublicCaSet"], d, config)); err != nil {
241304
return fmt.Errorf("Error reading TlsInspectionPolicy: %s", err)
242305
}
@@ -272,6 +335,30 @@ func resourceNetworkSecurityTlsInspectionPolicyUpdate(d *schema.ResourceData, me
272335
} else if v, ok := d.GetOkExists("ca_pool"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, caPoolProp)) {
273336
obj["caPool"] = caPoolProp
274337
}
338+
trustConfigProp, err := expandNetworkSecurityTlsInspectionPolicyTrustConfig(d.Get("trust_config"), d, config)
339+
if err != nil {
340+
return err
341+
} else if v, ok := d.GetOkExists("trust_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, trustConfigProp)) {
342+
obj["trustConfig"] = trustConfigProp
343+
}
344+
minTlsVersionProp, err := expandNetworkSecurityTlsInspectionPolicyMinTlsVersion(d.Get("min_tls_version"), d, config)
345+
if err != nil {
346+
return err
347+
} else if v, ok := d.GetOkExists("min_tls_version"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, minTlsVersionProp)) {
348+
obj["minTlsVersion"] = minTlsVersionProp
349+
}
350+
tlsFeatureProfileProp, err := expandNetworkSecurityTlsInspectionPolicyTlsFeatureProfile(d.Get("tls_feature_profile"), d, config)
351+
if err != nil {
352+
return err
353+
} else if v, ok := d.GetOkExists("tls_feature_profile"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, tlsFeatureProfileProp)) {
354+
obj["tlsFeatureProfile"] = tlsFeatureProfileProp
355+
}
356+
customTlsFeaturesProp, err := expandNetworkSecurityTlsInspectionPolicyCustomTlsFeatures(d.Get("custom_tls_features"), d, config)
357+
if err != nil {
358+
return err
359+
} else if v, ok := d.GetOkExists("custom_tls_features"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, customTlsFeaturesProp)) {
360+
obj["customTlsFeatures"] = customTlsFeaturesProp
361+
}
275362
excludePublicCaSetProp, err := expandNetworkSecurityTlsInspectionPolicyExcludePublicCaSet(d.Get("exclude_public_ca_set"), d, config)
276363
if err != nil {
277364
return err
@@ -296,6 +383,22 @@ func resourceNetworkSecurityTlsInspectionPolicyUpdate(d *schema.ResourceData, me
296383
updateMask = append(updateMask, "caPool")
297384
}
298385

386+
if d.HasChange("trust_config") {
387+
updateMask = append(updateMask, "trustConfig")
388+
}
389+
390+
if d.HasChange("min_tls_version") {
391+
updateMask = append(updateMask, "minTlsVersion")
392+
}
393+
394+
if d.HasChange("tls_feature_profile") {
395+
updateMask = append(updateMask, "tlsFeatureProfile")
396+
}
397+
398+
if d.HasChange("custom_tls_features") {
399+
updateMask = append(updateMask, "customTlsFeatures")
400+
}
401+
299402
if d.HasChange("exclude_public_ca_set") {
300403
updateMask = append(updateMask, "excludePublicCaSet")
301404
}
@@ -434,6 +537,22 @@ func flattenNetworkSecurityTlsInspectionPolicyCaPool(v interface{}, d *schema.Re
434537
return v
435538
}
436539

540+
func flattenNetworkSecurityTlsInspectionPolicyTrustConfig(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
541+
return v
542+
}
543+
544+
func flattenNetworkSecurityTlsInspectionPolicyMinTlsVersion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
545+
return v
546+
}
547+
548+
func flattenNetworkSecurityTlsInspectionPolicyTlsFeatureProfile(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
549+
return v
550+
}
551+
552+
func flattenNetworkSecurityTlsInspectionPolicyCustomTlsFeatures(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
553+
return v
554+
}
555+
437556
func flattenNetworkSecurityTlsInspectionPolicyExcludePublicCaSet(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
438557
return v
439558
}
@@ -446,6 +565,22 @@ func expandNetworkSecurityTlsInspectionPolicyCaPool(v interface{}, d tpgresource
446565
return v, nil
447566
}
448567

568+
func expandNetworkSecurityTlsInspectionPolicyTrustConfig(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
569+
return v, nil
570+
}
571+
572+
func expandNetworkSecurityTlsInspectionPolicyMinTlsVersion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
573+
return v, nil
574+
}
575+
576+
func expandNetworkSecurityTlsInspectionPolicyTlsFeatureProfile(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
577+
return v, nil
578+
}
579+
580+
func expandNetworkSecurityTlsInspectionPolicyCustomTlsFeatures(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
581+
return v, nil
582+
}
583+
449584
func expandNetworkSecurityTlsInspectionPolicyExcludePublicCaSet(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
450585
return v, nil
451586
}

google-beta/services/networksecurity/resource_network_security_tls_inspection_policy_generated_test.go

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,166 @@ resource "google_network_security_tls_inspection_policy" "default" {
136136
`, context)
137137
}
138138

139+
func TestAccNetworkSecurityTlsInspectionPolicy_networkSecurityTlsInspectionPolicyCustomExample(t *testing.T) {
140+
t.Parallel()
141+
142+
context := map[string]interface{}{
143+
"random_suffix": acctest.RandString(t, 10),
144+
}
145+
146+
acctest.VcrTest(t, resource.TestCase{
147+
PreCheck: func() { acctest.AccTestPreCheck(t) },
148+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
149+
CheckDestroy: testAccCheckNetworkSecurityTlsInspectionPolicyDestroyProducer(t),
150+
Steps: []resource.TestStep{
151+
{
152+
Config: testAccNetworkSecurityTlsInspectionPolicy_networkSecurityTlsInspectionPolicyCustomExample(context),
153+
},
154+
{
155+
ResourceName: "google_network_security_tls_inspection_policy.default",
156+
ImportState: true,
157+
ImportStateVerify: true,
158+
ImportStateVerifyIgnore: []string{"location", "name"},
159+
},
160+
},
161+
})
162+
}
163+
164+
func testAccNetworkSecurityTlsInspectionPolicy_networkSecurityTlsInspectionPolicyCustomExample(context map[string]interface{}) string {
165+
return acctest.Nprintf(`
166+
resource "google_privateca_ca_pool" "default" {
167+
provider = google-beta
168+
name = "tf-test-my-basic-ca-pool%{random_suffix}"
169+
location = "us-central1"
170+
tier = "DEVOPS"
171+
172+
publishing_options {
173+
publish_ca_cert = false
174+
publish_crl = false
175+
}
176+
177+
issuance_policy {
178+
maximum_lifetime = "1209600s"
179+
baseline_values {
180+
ca_options {
181+
is_ca = false
182+
}
183+
key_usage {
184+
base_key_usage {}
185+
extended_key_usage {
186+
server_auth = true
187+
}
188+
}
189+
}
190+
}
191+
}
192+
193+
resource "google_privateca_certificate_authority" "default" {
194+
provider = google-beta
195+
pool = google_privateca_ca_pool.default.name
196+
197+
certificate_authority_id = "tf-test-my-basic-certificate-authority%{random_suffix}"
198+
location = "us-central1"
199+
lifetime = "86400s"
200+
type = "SELF_SIGNED"
201+
deletion_protection = false
202+
skip_grace_period = true
203+
204+
ignore_active_certificates_on_deletion = true
205+
206+
config {
207+
subject_config {
208+
subject {
209+
organization = "Test LLC"
210+
common_name = "my-ca"
211+
}
212+
}
213+
x509_config {
214+
ca_options {
215+
is_ca = true
216+
}
217+
key_usage {
218+
base_key_usage {
219+
cert_sign = true
220+
crl_sign = true
221+
}
222+
extended_key_usage {
223+
server_auth = false
224+
}
225+
}
226+
}
227+
}
228+
229+
key_spec {
230+
algorithm = "RSA_PKCS1_4096_SHA256"
231+
}
232+
}
233+
234+
resource "google_project_service_identity" "ns_sa" {
235+
provider = google-beta
236+
service = "networksecurity.googleapis.com"
237+
}
238+
239+
resource "google_privateca_ca_pool_iam_member" "default" {
240+
provider = google-beta
241+
ca_pool = google_privateca_ca_pool.default.id
242+
role = "roles/privateca.certificateManager"
243+
member = "serviceAccount:${google_project_service_identity.ns_sa.email}"
244+
}
245+
246+
resource "google_certificate_manager_trust_config" "default" {
247+
provider = google-beta
248+
name = "tf-test-my-trust-config%{random_suffix}"
249+
description = "sample trust config description"
250+
location = "us-central1"
251+
252+
trust_stores {
253+
trust_anchors {
254+
pem_certificate = file("test-fixtures/ca_cert.pem")
255+
}
256+
intermediate_cas {
257+
pem_certificate = file("test-fixtures/ca_cert.pem")
258+
}
259+
}
260+
}
261+
262+
resource "google_network_security_tls_inspection_policy" "default" {
263+
provider = google-beta
264+
name = "tf-test-my-tls-inspection-policy%{random_suffix}"
265+
location = "us-central1"
266+
ca_pool = google_privateca_ca_pool.default.id
267+
268+
exclude_public_ca_set = false
269+
min_tls_version = "TLS_1_0"
270+
trust_config = google_certificate_manager_trust_config.default.id
271+
tls_feature_profile = "PROFILE_CUSTOM"
272+
273+
custom_tls_features = [
274+
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
275+
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256",
276+
"TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA",
277+
"TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
278+
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256",
279+
"TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
280+
"TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256",
281+
"TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
282+
"TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
283+
"TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256",
284+
"TLS_RSA_WITH_3DES_EDE_CBC_SHA",
285+
"TLS_RSA_WITH_AES_128_CBC_SHA",
286+
"TLS_RSA_WITH_AES_128_GCM_SHA256",
287+
"TLS_RSA_WITH_AES_256_CBC_SHA",
288+
"TLS_RSA_WITH_AES_256_GCM_SHA384",
289+
]
290+
291+
depends_on = [
292+
google_privateca_certificate_authority.default,
293+
google_privateca_ca_pool_iam_member.default,
294+
]
295+
}
296+
`, context)
297+
}
298+
139299
func testAccCheckNetworkSecurityTlsInspectionPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error {
140300
return func(s *terraform.State) error {
141301
for name, rs := range s.RootModule().Resources {

0 commit comments

Comments
 (0)