Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Tls Inspection Policy resource and update Gateway Security Policy to use the field tlsInspectionPolicy #5615

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .changelog/7880.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:enhancement
`google_network_security_gateway_security_policy`
`google_network_security_tls_inspection_policy`
```
5 changes: 3 additions & 2 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -807,9 +807,9 @@ func Provider() *schema.Provider {
return provider
}

// Generated resources: 338
// Generated resources: 339
// Generated IAM resources: 219
// Total generated resources: 557
// Total generated resources: 558
func ResourceMap() map[string]*schema.Resource {
resourceMap, _ := ResourceMapWithErrors()
return resourceMap
Expand Down Expand Up @@ -1247,6 +1247,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
"google_network_security_client_tls_policy": ResourceNetworkSecurityClientTlsPolicy(),
"google_network_security_gateway_security_policy": ResourceNetworkSecurityGatewaySecurityPolicy(),
"google_network_security_gateway_security_policy_rule": ResourceNetworkSecurityGatewaySecurityPolicyRule(),
"google_network_security_tls_inspection_policy": ResourceNetworkSecurityTlsInspectionPolicy(),
"google_network_security_url_lists": ResourceNetworkSecurityUrlLists(),
"google_network_services_edge_cache_keyset": ResourceNetworkServicesEdgeCacheKeyset(),
"google_network_services_edge_cache_origin": ResourceNetworkServicesEdgeCacheOrigin(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ gatewaySecurityPolicy should match the pattern:(^a-z?$).`,
The default value is 'global'.`,
Default: "global",
},
"tls_inspection_policy": {
Type: schema.TypeString,
Optional: true,
Description: `Name of a TlsInspectionPolicy resource that defines how TLS inspection is performed for any rule that enables it.`,
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -107,6 +112,12 @@ func resourceNetworkSecurityGatewaySecurityPolicyCreate(d *schema.ResourceData,
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
tlsInspectionPolicyProp, err := expandNetworkSecurityGatewaySecurityPolicyTlsInspectionPolicy(d.Get("tls_inspection_policy"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("tls_inspection_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(tlsInspectionPolicyProp)) && (ok || !reflect.DeepEqual(v, tlsInspectionPolicyProp)) {
obj["tlsInspectionPolicy"] = tlsInspectionPolicyProp
}

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

url, err := tpgresource.ReplaceVars(d, config, "{{NetworkSecurityBasePath}}projects/{{project}}/locations/{{location}}/gatewaySecurityPolicies/{{name}}")
if err != nil {
Expand All @@ -238,6 +255,10 @@ func resourceNetworkSecurityGatewaySecurityPolicyUpdate(d *schema.ResourceData,
if d.HasChange("description") {
updateMask = append(updateMask, "description")
}

if d.HasChange("tls_inspection_policy") {
updateMask = append(updateMask, "tlsInspectionPolicy")
}
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
Expand Down Expand Up @@ -353,3 +374,7 @@ func flattenNetworkSecurityGatewaySecurityPolicyDescription(v interface{}, d *sc
func expandNetworkSecurityGatewaySecurityPolicyDescription(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandNetworkSecurityGatewaySecurityPolicyTlsInspectionPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityP
ResourceName: "google_network_security_gateway_security_policy.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"name", "location"},
ImportStateVerifyIgnore: []string{"tls_inspection_policy", "name", "location"},
},
},
})
Expand All @@ -63,6 +63,115 @@ resource "google_network_security_gateway_security_policy" "default" {
`, context)
}

func TestAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": RandString(t, 10),
}

VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckNetworkSecurityGatewaySecurityPolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(context),
},
{
ResourceName: "google_network_security_gateway_security_policy.default",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"tls_inspection_policy", "name", "location"},
},
},
})
}

func testAccNetworkSecurityGatewaySecurityPolicy_networkSecurityGatewaySecurityPolicyTlsInspectionBasicExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_privateca_ca_pool" "default" {
provider = google-beta
name = "tf-test-my-basic-ca-pool%{random_suffix}"
location = "us-central1"
tier = "DEVOPS"
publishing_options {
publish_ca_cert = false
publish_crl = false
}
issuance_policy {
maximum_lifetime = "1209600s"
baseline_values {
ca_options {
is_ca = false
}
key_usage {
base_key_usage {}
extended_key_usage {
server_auth = true
}
}
}
}
}


resource "google_privateca_certificate_authority" "default" {
provider = google-beta
pool = google_privateca_ca_pool.default.name
certificate_authority_id = "tf-test-my-basic-certificate-authority%{random_suffix}"
location = "us-central1"
lifetime = "86400s"
type = "SELF_SIGNED"
deletion_protection = false
skip_grace_period = true
ignore_active_certificates_on_deletion = true
config {
subject_config {
subject {
organization = "Test LLC"
common_name = "my-ca"
}
}
x509_config {
ca_options {
is_ca = true
}
key_usage {
base_key_usage {
cert_sign = true
crl_sign = true
}
extended_key_usage {
server_auth = false
}
}
}
}
key_spec {
algorithm = "RSA_PKCS1_4096_SHA256"
}
}

resource "google_network_security_tls_inspection_policy" "default" {
provider = google-beta
name = "tf-test-my-tls-inspection-policy%{random_suffix}"
location = "us-central1"
ca_pool = google_privateca_ca_pool.default.id
depends_on = [google_privateca_ca_pool.default, google_privateca_certificate_authority.default]
}

resource "google_network_security_gateway_security_policy" "default" {
provider = google-beta
name = "tf-test-my-gateway-security-policy%{random_suffix}"
location = "us-central1"
description = "my description"
tls_inspection_policy = google_network_security_tls_inspection_policy.default.id
depends_on = [google_network_security_tls_inspection_policy.default]
}
`, context)
}

func testAccCheckNetworkSecurityGatewaySecurityPolicyDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
Loading