diff --git a/mmv1/products/compute/NetworkFirewallPolicyRule.yaml b/mmv1/products/compute/NetworkFirewallPolicyRule.yaml new file mode 100644 index 000000000000..75455c4d3b33 --- /dev/null +++ b/mmv1/products/compute/NetworkFirewallPolicyRule.yaml @@ -0,0 +1,293 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: 'NetworkFirewallPolicyRule' +kind: 'compute#firewallPolicyRule' +description: | + Represents a rule that describes one or more match conditions along with the action to be taken when traffic matches this condition (allow or deny). +references: + guides: + api: 'https://cloud.google.com/compute/docs/reference/rest/v1/networkFirewallPolicies/addRule' +docs: +id_format: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/rules/{{priority}}' +base_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}' +self_link: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/getRule?priority={{priority}}' +create_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/addRule' +update_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/patchRule?priority={{priority}}' +update_verb: 'POST' +delete_url: 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/removeRule?priority={{priority}}' +delete_verb: 'POST' +legacy_long_form_project: true +import_format: + - 'projects/{{project}}/global/firewallPolicies/{{firewall_policy}}/rules/{{priority}}' + - '{{project}}/{{firewall_policy}}/{{priority}}' + - '{{firewall_policy}}/{{priority}}' +timeouts: + insert_minutes: 20 + update_minutes: 20 + delete_minutes: 20 +async: + actions: ['create', 'delete', 'update'] + type: 'OpAsync' + operation: + base_url: '{{op_id}}' + kind: 'compute#operation' + path: 'name' + wait_ms: 1000 + result: + path: 'targetLink' + resource_inside_response: false + error: + path: 'error/errors' + message: 'message' +examples: + - name: 'network_firewall_policy_rule' + primary_resource_id: 'primary' + vars: + tag_key: 'tagkey' + network: 'network' + fw_policy: 'policy' + address: 'address' + test_env_vars: + project_name: 'PROJECT_NAME' + org_id: 'ORG_ID' + service_acct: 'SERVICE_ACCT' +parameters: + - name: 'firewallPolicy' + type: ResourceRef + description: | + The firewall policy of the resource. + url_param_only: true + required: true + immutable: true + diff_suppress_func: 'tpgresource.CompareResourceNames' + resource: 'NetworkFirewallPolicy' + imports: 'name' +properties: + - name: 'creationTimestamp' + type: String + description: | + Creation timestamp in RFC3339 text format. + output: true + - name: 'kind' + type: String + description: | + Type of the resource. Always `compute#firewallPolicyRule` for firewall policy rules + output: true + - name: 'ruleName' + type: String + description: | + An optional name for the rule. This field is not a unique identifier and can be updated. + - name: 'description' + type: String + description: 'An optional description for this resource.' + - name: 'priority' + type: Integer + immutable: true + description: | + An integer indicating the priority of a rule in the list. + The priority must be a positive value between 0 and 2147483647. + Rules are evaluated from highest to lowest priority where 0 is the highest priority and 2147483647 is the lowest prority. + required: true + - name: 'match' + type: NestedObject + description: | + A match condition that incoming traffic is evaluated against. If it evaluates to true, the corresponding 'action' is enforced. + required: true + properties: + - name: 'srcIpRanges' + type: Array + send_empty_value: true + description: | + CIDR IP address range. Maximum number of source CIDR IP ranges allowed is 5000. + item_type: + type: String + - name: 'destIpRanges' + type: Array + send_empty_value: true + description: | + CIDR IP address range. Maximum number of destination CIDR IP ranges allowed is 5000. + item_type: + type: String + - name: 'layer4Configs' + type: Array + send_empty_value: true + description: | + Pairs of IP protocols and ports that the rule should match. + required: true + item_type: + type: NestedObject + properties: + - name: 'ipProtocol' + type: String + description: | + The IP protocol to which this rule applies. The protocol type is required when creating a firewall rule. + This value can either be one of the following well known protocol strings (tcp, udp, icmp, esp, ah, ipip, sctp), or the IP protocol number. + required: true + - name: 'ports' + type: Array + description: | + An optional list of ports to which this rule applies. This field is only applicable for UDP or TCP protocol. Each entry must be either an integer or a range. If not specified, this rule applies to connections through any port. + Example inputs include: ["22"], ["80","443"], and ["12345-12349"]. + item_type: + type: String + - name: 'srcSecureTags' + type: Array + send_empty_value: true + description: | + List of secure tag values, which should be matched at the source of the traffic. For INGRESS rule, if all the srcSecureTag are INEFFECTIVE, and there is no srcIpRange, this rule will be ignored. Maximum number of source tag values allowed is 256. + item_type: + type: NestedObject + properties: + - name: 'name' + type: String + description: | + Name of the secure tag, created with TagManager's TagValue API. + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + - name: 'state' + type: Enum + description: | + State of the secure tag, either EFFECTIVE or INEFFECTIVE. A secure tag is INEFFECTIVE when it is deleted or its network is deleted. + output: true + enum_values: + - 'EFFECTIVE' + - 'INEFFECTIVE' + - name: 'destAddressGroups' + type: Array + send_empty_value: true + description: | + Address groups which should be matched against the traffic destination. Maximum number of destination address groups is 10. + item_type: + type: String + - name: 'srcAddressGroups' + type: Array + send_empty_value: true + description: | + Address groups which should be matched against the traffic source. Maximum number of source address groups is 10. + item_type: + type: String + - name: 'srcFqdns' + type: Array + send_empty_value: true + description: | + Fully Qualified Domain Name (FQDN) which should be matched against traffic source. Maximum number of source fqdn allowed is 100. + item_type: + type: String + - name: 'destFqdns' + type: Array + send_empty_value: true + description: | + Fully Qualified Domain Name (FQDN) which should be matched against traffic destination. Maximum number of destination fqdn allowed is 100. + item_type: + type: String + - name: 'srcRegionCodes' + type: Array + send_empty_value: true + description: | + Region codes whose IP addresses will be used to match for source of traffic. Should be specified as 2 letter country code defined as per ISO 3166 alpha-2 country codes. ex."US" Maximum number of source region codes allowed is 5000. + item_type: + type: String + - name: 'destRegionCodes' + type: Array + send_empty_value: true + description: | + Region codes whose IP addresses will be used to match for destination of traffic. Should be specified as 2 letter country code defined as per ISO 3166 alpha-2 country codes. ex."US" Maximum number of dest region codes allowed is 5000. + item_type: + type: String + - name: 'destThreatIntelligences' + type: Array + send_empty_value: true + description: | + Names of Network Threat Intelligence lists. The IPs in these lists will be matched against traffic destination. + item_type: + type: String + - name: 'srcThreatIntelligences' + type: Array + send_empty_value: true + description: | + Names of Network Threat Intelligence lists. The IPs in these lists will be matched against traffic source. + item_type: + type: String + - name: 'action' + type: String + description: 'The Action to perform when the client connection triggers the rule. Valid actions are "allow", "deny", "goto_next" and "apply_security_profile_group".' + required: true + - name: 'securityProfileGroup' + type: String + description: | + A fully-qualified URL of a SecurityProfile resource instance. + Example: https://networksecurity.googleapis.com/v1/projects/{project}/locations/{location}/securityProfileGroups/my-security-profile-group + Must be specified if action = 'apply_security_profile_group' and cannot be specified for other actions. + - name: 'tlsInspect' + type: Boolean + description: | + Boolean flag indicating if the traffic should be TLS decrypted. + Can be set only if action = 'apply_security_profile_group' and cannot be set for other actions. + - name: 'direction' + type: Enum + description: | + The direction in which this rule applies. + required: true + enum_values: + - 'INGRESS' + - 'EGRESS' + - name: 'enableLogging' + type: Boolean + send_empty_value: true + description: | + Denotes whether to enable logging for a particular rule. + If logging is enabled, logs will be exported to the configured export destination in Stackdriver. + Logs may be exported to BigQuery or Pub/Sub. + Note: you cannot enable logging on "goto_next" rules. + - name: 'ruleTupleCount' + type: Integer + description: | + Calculation of the complexity of a single firewall policy rule. + output: true + - name: 'targetServiceAccounts' + type: Array + send_empty_value: true + description: | + A list of service accounts indicating the sets of instances that are applied with this rule. + item_type: + type: String + - name: 'targetSecureTags' + type: Array + send_empty_value: true + description: | + A list of secure tags that controls which instances the firewall rule applies to. + If targetSecureTag are specified, then the firewall rule applies only to instances in the VPC network that have one of those EFFECTIVE secure tags, if all the targetSecureTag are in INEFFECTIVE state, then this rule will be ignored. + targetSecureTag may not be set at the same time as targetServiceAccounts. If neither targetServiceAccounts nor targetSecureTag are specified, the firewall rule applies to all instances on the specified network. Maximum number of target label tags allowed is 256. + item_type: + type: NestedObject + properties: + - name: 'name' + type: String + description: | + Name of the secure tag, created with TagManager's TagValue API. + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + - name: 'state' + type: Enum + description: | + State of the secure tag, either EFFECTIVE or INEFFECTIVE. A secure tag is INEFFECTIVE when it is deleted or its network is deleted. + output: true + enum_values: + - 'EFFECTIVE' + - 'INEFFECTIVE' + - name: 'disabled' + type: Boolean + description: | + Denotes whether the firewall policy rule is disabled. + When set to true, the firewall policy rule is not enforced and traffic behaves as if it did not exist. + If this is unspecified, the firewall policy rule will be enabled. diff --git a/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml b/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml new file mode 100644 index 000000000000..06bf26c8ed40 --- /dev/null +++ b/mmv1/products/compute/RegionNetworkFirewallPolicyRule.yaml @@ -0,0 +1,305 @@ +# Copyright 2024 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +name: 'RegionNetworkFirewallPolicyRule' +kind: 'compute#firewallPolicyRule' +description: | + Represents a rule that describes one or more match conditions along with the action to be taken when traffic matches this condition (allow or deny). +references: + guides: + api: 'https://cloud.google.com/compute/docs/reference/rest/v1/regionNetworkFirewallPolicies/addRule' +docs: +id_format: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/{{priority}}' +base_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}' +self_link: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/getRule?priority={{priority}}' +create_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/addRule' +update_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/patchRule?priority={{priority}}' +update_verb: 'POST' +delete_url: 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/removeRule?priority={{priority}}' +delete_verb: 'POST' +legacy_long_form_project: true +import_format: + - 'projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/{{priority}}' + - '{{project}}/{{region}}/{{firewall_policy}}/{{priority}}' + - '{{region}}/{{firewall_policy}}/{{priority}}' + - '{{firewall_policy}}/{{priority}}' +timeouts: + insert_minutes: 20 + update_minutes: 20 + delete_minutes: 20 +async: + actions: ['create', 'delete', 'update'] + type: 'OpAsync' + operation: + base_url: '{{op_id}}' + kind: 'compute#operation' + path: 'name' + wait_ms: 1000 + result: + path: 'targetLink' + resource_inside_response: false + error: + path: 'error/errors' + message: 'message' +custom_diff: + - 'tpgresource.DefaultProviderRegion' +examples: + - name: 'region_network_firewall_policy_rule' + primary_resource_id: 'primary' + vars: + tag_key: 'tagkey' + network: 'network' + fw_policy: 'policy' + address: 'address' + test_env_vars: + project_name: 'PROJECT_NAME' + org_id: 'ORG_ID' + region: 'REGION' + service_acct: 'SERVICE_ACCT' +parameters: + - name: 'firewallPolicy' + type: ResourceRef + description: | + The firewall policy of the resource. + url_param_only: true + required: true + immutable: true + diff_suppress_func: 'tpgresource.CompareResourceNames' + resource: 'RegionNetworkFirewallPolicy' + imports: 'name' + - name: 'region' + type: String + description: 'The location of this resource.' + url_param_only: true + immutable: true + default_from_api: true +properties: + - name: 'creationTimestamp' + type: String + description: | + Creation timestamp in RFC3339 text format. + output: true + - name: 'kind' + type: String + description: | + Type of the resource. Always `compute#firewallPolicyRule` for firewall policy rules + output: true + - name: 'ruleName' + type: String + description: | + An optional name for the rule. This field is not a unique identifier and can be updated. + - name: 'description' + type: String + description: 'An optional description for this resource.' + - name: 'priority' + type: Integer + immutable: true + description: | + An integer indicating the priority of a rule in the list. + The priority must be a positive value between 0 and 2147483647. + Rules are evaluated from highest to lowest priority where 0 is the highest priority and 2147483647 is the lowest prority. + required: true + - name: 'match' + type: NestedObject + description: | + A match condition that incoming traffic is evaluated against. If it evaluates to true, the corresponding 'action' is enforced. + required: true + properties: + - name: 'srcIpRanges' + type: Array + send_empty_value: true + description: | + CIDR IP address range. Maximum number of source CIDR IP ranges allowed is 5000. + item_type: + type: String + - name: 'destIpRanges' + type: Array + send_empty_value: true + description: | + CIDR IP address range. Maximum number of destination CIDR IP ranges allowed is 5000. + item_type: + type: String + - name: 'layer4Configs' + type: Array + send_empty_value: true + description: | + Pairs of IP protocols and ports that the rule should match. + required: true + item_type: + type: NestedObject + properties: + - name: 'ipProtocol' + type: String + description: | + The IP protocol to which this rule applies. The protocol type is required when creating a firewall rule. + This value can either be one of the following well known protocol strings (tcp, udp, icmp, esp, ah, ipip, sctp), or the IP protocol number. + required: true + - name: 'ports' + type: Array + description: | + An optional list of ports to which this rule applies. This field is only applicable for UDP or TCP protocol. Each entry must be either an integer or a range. If not specified, this rule applies to connections through any port. + Example inputs include: ["22"], ["80","443"], and ["12345-12349"]. + item_type: + type: String + - name: 'srcSecureTags' + type: Array + send_empty_value: true + description: | + List of secure tag values, which should be matched at the source of the traffic. For INGRESS rule, if all the srcSecureTag are INEFFECTIVE, and there is no srcIpRange, this rule will be ignored. Maximum number of source tag values allowed is 256. + item_type: + type: NestedObject + properties: + - name: 'name' + type: String + description: | + Name of the secure tag, created with TagManager's TagValue API. + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + - name: 'state' + type: Enum + description: | + State of the secure tag, either EFFECTIVE or INEFFECTIVE. A secure tag is INEFFECTIVE when it is deleted or its network is deleted. + output: true + enum_values: + - 'EFFECTIVE' + - 'INEFFECTIVE' + - name: 'destAddressGroups' + type: Array + send_empty_value: true + description: | + Address groups which should be matched against the traffic destination. Maximum number of destination address groups is 10. + item_type: + type: String + - name: 'srcAddressGroups' + type: Array + send_empty_value: true + description: | + Address groups which should be matched against the traffic source. Maximum number of source address groups is 10. + item_type: + type: String + - name: 'srcFqdns' + type: Array + send_empty_value: true + description: | + Fully Qualified Domain Name (FQDN) which should be matched against traffic source. Maximum number of source fqdn allowed is 100. + item_type: + type: String + - name: 'destFqdns' + type: Array + send_empty_value: true + description: | + Fully Qualified Domain Name (FQDN) which should be matched against traffic destination. Maximum number of destination fqdn allowed is 100. + item_type: + type: String + - name: 'srcRegionCodes' + type: Array + send_empty_value: true + description: | + Region codes whose IP addresses will be used to match for source of traffic. Should be specified as 2 letter country code defined as per ISO 3166 alpha-2 country codes. ex."US" Maximum number of source region codes allowed is 5000. + item_type: + type: String + - name: 'destRegionCodes' + type: Array + send_empty_value: true + description: | + Region codes whose IP addresses will be used to match for destination of traffic. Should be specified as 2 letter country code defined as per ISO 3166 alpha-2 country codes. ex."US" Maximum number of dest region codes allowed is 5000. + item_type: + type: String + - name: 'destThreatIntelligences' + type: Array + send_empty_value: true + description: | + Names of Network Threat Intelligence lists. The IPs in these lists will be matched against traffic destination. + item_type: + type: String + - name: 'srcThreatIntelligences' + type: Array + send_empty_value: true + description: | + Names of Network Threat Intelligence lists. The IPs in these lists will be matched against traffic source. + item_type: + type: String + - name: 'action' + type: String + description: 'The Action to perform when the client connection triggers the rule. Valid actions are "allow", "deny", "goto_next" and "apply_security_profile_group".' + required: true + - name: 'securityProfileGroup' + type: String + description: | + A fully-qualified URL of a SecurityProfile resource instance. + Example: https://networksecurity.googleapis.com/v1/projects/{project}/locations/{location}/securityProfileGroups/my-security-profile-group + Must be specified if action = 'apply_security_profile_group' and cannot be specified for other actions. + + Security Profile Group and Firewall Policy Rule must be in the same scope. + - name: 'tlsInspect' + type: Boolean + description: | + Boolean flag indicating if the traffic should be TLS decrypted. + Can be set only if action = 'apply_security_profile_group' and cannot be set for other actions. + - name: 'direction' + type: Enum + description: | + The direction in which this rule applies. + required: true + enum_values: + - 'INGRESS' + - 'EGRESS' + - name: 'enableLogging' + type: Boolean + send_empty_value: true + description: | + Denotes whether to enable logging for a particular rule. + If logging is enabled, logs will be exported to the configured export destination in Stackdriver. + Logs may be exported to BigQuery or Pub/Sub. + Note: you cannot enable logging on "goto_next" rules. + - name: 'ruleTupleCount' + type: Integer + description: | + Calculation of the complexity of a single firewall policy rule. + output: true + - name: 'targetServiceAccounts' + type: Array + send_empty_value: true + description: | + A list of service accounts indicating the sets of instances that are applied with this rule. + item_type: + type: String + - name: 'targetSecureTags' + type: Array + send_empty_value: true + description: | + A list of secure tags that controls which instances the firewall rule applies to. + If targetSecureTag are specified, then the firewall rule applies only to instances in the VPC network that have one of those EFFECTIVE secure tags, if all the targetSecureTag are in INEFFECTIVE state, then this rule will be ignored. + targetSecureTag may not be set at the same time as targetServiceAccounts. If neither targetServiceAccounts nor targetSecureTag are specified, the firewall rule applies to all instances on the specified network. Maximum number of target label tags allowed is 256. + item_type: + type: NestedObject + properties: + - name: 'name' + type: String + description: | + Name of the secure tag, created with TagManager's TagValue API. + diff_suppress_func: 'tpgresource.CompareSelfLinkOrResourceName' + - name: 'state' + type: Enum + description: | + State of the secure tag, either EFFECTIVE or INEFFECTIVE. A secure tag is INEFFECTIVE when it is deleted or its network is deleted. + output: true + enum_values: + - 'EFFECTIVE' + - 'INEFFECTIVE' + - name: 'disabled' + type: Boolean + description: | + Denotes whether the firewall policy rule is disabled. + When set to true, the firewall policy rule is not enforced and traffic behaves as if it did not exist. + If this is unspecified, the firewall policy rule will be enabled. diff --git a/mmv1/templates/terraform/examples/network_firewall_policy_rule.tf.tmpl b/mmv1/templates/terraform/examples/network_firewall_policy_rule.tf.tmpl new file mode 100644 index 000000000000..861da7425a43 --- /dev/null +++ b/mmv1/templates/terraform/examples/network_firewall_policy_rule.tf.tmpl @@ -0,0 +1,64 @@ +resource "google_network_security_address_group" "basic_global_networksecurity_address_group" { + name = "{{index $.Vars "address"}}" + parent = "projects/{{index $.TestEnvVars "project_name"}}" + description = "Sample global networksecurity_address_group" + location = "global" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" { + name = "{{index $.Vars "fw_policy"}}" + description = "Sample global network firewall policy" + project = "{{index $.TestEnvVars "project_name"}}" +} + +resource "google_compute_network_firewall_policy_rule" "{{$.PrimaryResourceId}}" { + action = "allow" + description = "This is a simple rule description" + direction = "INGRESS" + disabled = false + enable_logging = true + firewall_policy = google_compute_network_firewall_policy.basic_network_firewall_policy.name + priority = 1000 + rule_name = "test-rule" + target_service_accounts = ["{{index $.TestEnvVars "service_acct"}}"] + + match { + src_ip_ranges = ["10.100.0.1/32"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + + src_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } + + layer4_configs { + ip_protocol = "all" + } + + src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id] + } +} + +resource "google_compute_network" "basic_network" { + name = "{{index $.Vars "network"}}" +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/{{index $.TestEnvVars "org_id"}}" + purpose = "GCE_FIREWALL" + short_name = "{{index $.Vars "tag_key"}}" + purpose_data = { + network = "{{index $.TestEnvVars "project_name"}}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tagvalue" +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/region_network_firewall_policy_rule.tf.tmpl b/mmv1/templates/terraform/examples/region_network_firewall_policy_rule.tf.tmpl new file mode 100644 index 000000000000..27a98d5e99e0 --- /dev/null +++ b/mmv1/templates/terraform/examples/region_network_firewall_policy_rule.tf.tmpl @@ -0,0 +1,67 @@ +resource "google_network_security_address_group" "basic_regional_networksecurity_address_group" { + name = "{{index $.Vars "address"}}" + parent = "projects/{{index $.TestEnvVars "project_name"}}" + description = "Sample regional networksecurity_address_group" + location = "{{index $.TestEnvVars "region"}}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy" "basic_regional_network_firewall_policy" { + name = "{{index $.Vars "fw_policy"}}" + description = "Sample regional network firewall policy" + project = "{{index $.TestEnvVars "project_name"}}" + region = "{{index $.TestEnvVars "region"}}" +} + +resource "google_compute_region_network_firewall_policy_rule" "{{$.PrimaryResourceId}}" { + action = "allow" + description = "This is a simple rule description" + direction = "INGRESS" + disabled = false + enable_logging = true + firewall_policy = google_compute_region_network_firewall_policy.basic_regional_network_firewall_policy.name + priority = 1000 + region = "{{index $.TestEnvVars "region"}}" + rule_name = "test-rule" + target_service_accounts = ["{{index $.TestEnvVars "service_acct"}}"] + + match { + src_ip_ranges = ["10.100.0.1/32"] + src_fqdns = ["example.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + + layer4_configs { + ip_protocol = "all" + } + + src_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } + + src_address_groups = [google_network_security_address_group.basic_regional_networksecurity_address_group.id] + } +} + +resource "google_compute_network" "basic_network" { + name = "{{index $.Vars "network"}}" +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/{{index $.TestEnvVars "org_id"}}" + purpose = "GCE_FIREWALL" + short_name = "{{index $.Vars "tag_key"}}" + + purpose_data = { + network = "{{index $.TestEnvVars "project_name"}}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tagvalue" +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_network_firewall_policy_rule_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_network_firewall_policy_rule_test.go.tmpl index cfaaebaa5840..ed0ddf7f3525 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_network_firewall_policy_rule_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_network_firewall_policy_rule_test.go.tmpl @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-provider-google/google/acctest" "github.com/hashicorp/terraform-provider-google/google/envvar" + "github.com/hashicorp/terraform-plugin-testing/plancheck" ) func TestAccComputeNetworkFirewallPolicyRule_update(t *testing.T) { @@ -33,6 +34,11 @@ func TestAccComputeNetworkFirewallPolicyRule_update(t *testing.T) { }, { Config: testAccComputeNetworkFirewallPolicyRule_update(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule1", @@ -43,6 +49,11 @@ func TestAccComputeNetworkFirewallPolicyRule_update(t *testing.T) { }, { Config: testAccComputeNetworkFirewallPolicyRule_removeConfigs(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule1", @@ -53,6 +64,11 @@ func TestAccComputeNetworkFirewallPolicyRule_update(t *testing.T) { }, { Config: testAccComputeNetworkFirewallPolicyRule_start(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule1", @@ -66,8 +82,6 @@ func TestAccComputeNetworkFirewallPolicyRule_update(t *testing.T) { } func TestAccComputeNetworkFirewallPolicyRule_multipleRules(t *testing.T) { - // Currently failing - acctest.SkipIfVcr(t) t.Parallel() context := map[string]interface{}{ @@ -98,6 +112,11 @@ func TestAccComputeNetworkFirewallPolicyRule_multipleRules(t *testing.T) { }, { Config: testAccComputeNetworkFirewallPolicyRule_multipleAdd(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule3", @@ -108,6 +127,13 @@ func TestAccComputeNetworkFirewallPolicyRule_multipleRules(t *testing.T) { }, { Config: testAccComputeNetworkFirewallPolicyRule_multipleRemove(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule2", plancheck.ResourceActionDestroy), + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule3", plancheck.ResourceActionUpdate), + }, + }, }, }, }) @@ -137,6 +163,11 @@ func TestAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(t *test }, { Config: testAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, }, { ResourceName: "google_compute_network_firewall_policy_rule.fw_policy_rule1", @@ -149,6 +180,192 @@ func TestAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(t *test }) } +func TestAccComputeNetworkFirewallPolicyRule_secureTags(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "org_id": envvar.GetTestOrgFromEnv(t), + "project_name": envvar.GetTestProjectFromEnv(), + "service_acct": envvar.GetTestServiceAccountFromEnv(t), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeNetworkFirewallPolicyRuleDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeNetworkFirewallPolicyRule_secureTags(context), + }, + { + ResourceName: "google_compute_network_firewall_policy_rule.primary", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy", "project"}, + }, + { + Config: testAccComputeNetworkFirewallPolicyRule_secureTagsUpdate(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_network_firewall_policy_rule.primary", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_network_firewall_policy_rule.primary", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy", "project"}, + }, + }, + }) +} + +func testAccComputeNetworkFirewallPolicyRule_secureTags(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_network_security_address_group" "basic_global_networksecurity_address_group" { + name = "tf-test-address-%{random_suffix}" + parent = "projects/%{project_name}" + description = "Sample global networksecurity_address_group" + location = "global" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Sample global network firewall policy" + project = "%{project_name}" +} + +resource "google_compute_network_firewall_policy_rule" "primary" { + action = "allow" + description = "This is a simple rule description" + direction = "INGRESS" + disabled = false + enable_logging = true + firewall_policy = google_compute_network_firewall_policy.basic_network_firewall_policy.name + priority = 1000 + tls_inspect = false + rule_name = "tf-test-rule-%{random_suffix}" + project = "projects/%{project_name}" + + match { + src_ip_ranges = ["10.100.0.1/32"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + + src_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } + + layer4_configs { + ip_protocol = "all" + } + + src_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id] + } +} + +resource "google_compute_network" "basic_network" { + name = "tf-test-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/%{org_id}" + purpose = "GCE_FIREWALL" + short_name = "tf-test-tagkey-%{random_suffix}" + purpose_data = { + network = "%{project_name}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tf-test-tagvalue-%{random_suffix}" +} +`, context) +} + +func testAccComputeNetworkFirewallPolicyRule_secureTagsUpdate(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_network_security_address_group" "basic_global_networksecurity_address_group" { + name = "tf-test-address-%{random_suffix}" + parent = "projects/%{project_name}" + description = "Sample global networksecurity_address_group" + location = "global" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_network_firewall_policy" "basic_network_firewall_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Sample global network firewall policy" + project = "%{project_name}" +} + +resource "google_compute_network_firewall_policy_rule" "primary" { + action = "deny" + description = "This is an updated rule description" + direction = "EGRESS" + disabled = true + enable_logging = false + firewall_policy = google_compute_network_firewall_policy.basic_network_firewall_policy.id + priority = 1000 + tls_inspect = false + rule_name = "tf-test-updated-rule-%{random_suffix}" + project = "projects/%{project_name}" + + match { + dest_ip_ranges = ["0.0.0.0/0"] + dest_fqdns = ["example.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + dest_address_groups = [google_network_security_address_group.basic_global_networksecurity_address_group.id] + + layer4_configs { + ip_protocol = "tcp" + ports = ["123"] + } + } + + target_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } +} + +resource "google_compute_network" "basic_network" { + name = "tf-test-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/%{org_id}" + purpose = "GCE_FIREWALL" + short_name = "tf-test-tagkey-%{random_suffix}" + purpose_data = { + network = "%{project_name}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tf-test-tagvalue-%{random_suffix}" +} +`, context) +} + func testAccComputeNetworkFirewallPolicyRule_securityProfileGroup_basic(context map[string]interface{}) string { return acctest.Nprintf(` resource "google_compute_network" "network1" { @@ -204,11 +421,6 @@ resource "google_compute_network_firewall_policy_rule" "fw_policy_rule1" { func testAccComputeNetworkFirewallPolicyRule_securityProfileGroup_update(context map[string]interface{}) string { return acctest.Nprintf(` -resource "google_compute_network" "network1" { - name = "tf-test-%{random_suffix}" - auto_create_subnetworks = false -} - resource "google_network_security_security_profile" "security_profile" { name = "tf-test-my-sp%{random_suffix}" type = "THREAT_PREVENTION" @@ -237,12 +449,6 @@ resource "google_compute_network_firewall_policy" "fw_policy" { description = "Resource created for Terraform acceptance testing" } -resource "google_compute_network_firewall_policy_association" "fw_policy_a" { - name = "tf-test-policy-a-%{random_suffix}" - attachment_target = google_compute_network.network1.id - firewall_policy = google_compute_network_firewall_policy.fw_policy.id -} - resource "google_compute_network_firewall_policy_rule" "fw_policy_rule1" { firewall_policy = google_compute_network_firewall_policy.fw_policy.id description = "Resource created for Terraform acceptance testing" @@ -428,7 +634,7 @@ resource "google_compute_network_firewall_policy_rule" "fw_policy_rule1" { enable_logging = false action = "deny" direction = "INGRESS" - disabled = true + disabled = false target_service_accounts = [ google_service_account.service_account1.email, google_service_account.service_account2.email @@ -527,7 +733,7 @@ func testAccComputeNetworkFirewallPolicyRule_multipleAdd(context map[string]inte return acctest.Nprintf(` resource "google_compute_network_firewall_policy" "fw_policy" { name = "tf-test-policy-%{random_suffix}" - description = "Description Update" + description = "Resource created for Terraform acceptance testing" } resource "google_network_security_address_group" "address_group" { diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_network_firewall_policy_rule_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_network_firewall_policy_rule_test.go.tmpl new file mode 100644 index 000000000000..c6edf183b756 --- /dev/null +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_network_firewall_policy_rule_test.go.tmpl @@ -0,0 +1,762 @@ +package compute_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-google/google/acctest" + "github.com/hashicorp/terraform-provider-google/google/envvar" + "github.com/hashicorp/terraform-plugin-testing/plancheck" +) + +func TestAccComputeRegionNetworkFirewallPolicyRule_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)), + "region": envvar.GetTestRegionFromEnv(), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_start(context), + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule1", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_update(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule1", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_removeConfigs(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule1", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_start(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule1", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + }, + }) +} + +func TestAccComputeRegionNetworkFirewallPolicyRule_multipleRules(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": acctest.RandString(t, 10), + "org_name": fmt.Sprintf("organizations/%s", envvar.GetTestOrgFromEnv(t)), + "region": envvar.GetTestRegionFromEnv(), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_multiple(context), + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule1", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule2", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_multipleAdd(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.fw_policy_rule3", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_multipleRemove(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule1", plancheck.ResourceActionUpdate), + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule2", plancheck.ResourceActionDestroy), + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.fw_policy_rule3", plancheck.ResourceActionUpdate), + }, + }, + }, + }, + }) +} + +func TestAccComputeRegionNetworkFirewallPolicyRule_secureTags(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "org_id": envvar.GetTestOrgFromEnv(t), + "project_name": envvar.GetTestProjectFromEnv(), + "region": envvar.GetTestRegionFromEnv(), + "service_acct": envvar.GetTestServiceAccountFromEnv(t), + "random_suffix": acctest.RandString(t, 10), + } + + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckComputeRegionNetworkFirewallPolicyRuleDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_secureTags(context), + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.primary", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy", "project"}, + }, + { + Config: testAccComputeRegionNetworkFirewallPolicyRule_secureTagsUpdate(context), + ConfigPlanChecks: resource.ConfigPlanChecks{ + PreApply: []plancheck.PlanCheck{ + plancheck.ExpectResourceAction("google_compute_region_network_firewall_policy_rule.primary", plancheck.ResourceActionUpdate), + }, + }, + }, + { + ResourceName: "google_compute_region_network_firewall_policy_rule.primary", + ImportState: true, + ImportStateVerify: true, + // Referencing using ID causes import to fail + ImportStateVerifyIgnore: []string{"firewall_policy", "project"}, + }, + }, + }) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_secureTags(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_network_security_address_group" "basic_regional_networksecurity_address_group" { + name = "tf-test-address-%{random_suffix}" + parent = "projects/%{project_name}" + description = "Sample regional networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy" "basic_regional_network_firewall_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Sample regional network firewall policy" + project = "%{project_name}" + region = "%{region}" +} + +resource "google_compute_region_network_firewall_policy_rule" "primary" { + action = "allow" + description = "This is a simple rule description" + direction = "INGRESS" + disabled = false + enable_logging = true + firewall_policy = google_compute_region_network_firewall_policy.basic_regional_network_firewall_policy.name + priority = 1000 + region = "%{region}" + tls_inspect = false + rule_name = "tf-test-rule-%{random_suffix}" + project = "projects/%{project_name}" + + target_service_accounts = ["%{service_acct}"] + + match { + src_ip_ranges = ["10.100.0.1/32"] + src_fqdns = ["example.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + + layer4_configs { + ip_protocol = "all" + } + + src_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } + + src_address_groups = [google_network_security_address_group.basic_regional_networksecurity_address_group.id] + } +} + +resource "google_compute_network" "basic_network" { + name = "tf-test-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/%{org_id}" + purpose = "GCE_FIREWALL" + short_name = "tf-test-tagkey-%{random_suffix}" + + purpose_data = { + network = "%{project_name}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tf-test-tagvalue-%{random_suffix}" +} + +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_secureTagsUpdate(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_network_security_address_group" "basic_regional_networksecurity_address_group" { + name = "tf-test-address-%{random_suffix}" + parent = "projects/%{project_name}" + description = "Sample regional networksecurity_address_group. Update" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy" "basic_regional_network_firewall_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Sample regional network firewall policy" + project = "%{project_name}" + region = "%{region}" +} + +resource "google_compute_region_network_firewall_policy_rule" "primary" { + action = "deny" + description = "This is an updated rule description" + direction = "EGRESS" + disabled = true + enable_logging = false + firewall_policy = google_compute_region_network_firewall_policy.basic_regional_network_firewall_policy.id + priority = 1000 + region = "%{region}" + tls_inspect = false + rule_name = "tf-test-updated-rule-%{random_suffix}" + project = "projects/%{project_name}" + + match { + dest_ip_ranges = ["0.0.0.0/0"] + dest_fqdns = ["example.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + dest_address_groups = [google_network_security_address_group.basic_regional_networksecurity_address_group.id] + + layer4_configs { + ip_protocol = "tcp" + ports = ["123"] + } + } + + target_secure_tags { + name = "tagValues/${google_tags_tag_value.basic_value.name}" + } +} + +resource "google_compute_network" "basic_network" { + name = "tf-test-network-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_tags_tag_key" "basic_key" { + description = "For keyname resources." + parent = "organizations/%{org_id}" + purpose = "GCE_FIREWALL" + short_name = "tf-test-tagkey-%{random_suffix}" + + purpose_data = { + network = "%{project_name}/${google_compute_network.basic_network.name}" + } +} + +resource "google_tags_tag_value" "basic_value" { + description = "For valuename resources." + parent = "tagKeys/${google_tags_tag_key.basic_key.name}" + short_name = "tf-test-tagvalue-%{random_suffix}" +} + +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_start(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_service_account" "service_account1" { + account_id = "tf-test-sa-%{random_suffix}" +} + +resource "google_service_account" "service_account2" { + account_id = "tf-test-sa2-%{random_suffix}" +} + +resource "google_compute_network" "network1" { + name = "tf-test-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_network" "network2" { + name = "tf-test-2-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9000 + enable_logging = true + action = "allow" + direction = "EGRESS" + disabled = false + tls_inspect = false + region = "%{region}" + + match { + layer4_configs { + ip_protocol = "tcp" + ports = [80, 8080] + } + dest_ip_ranges = ["11.100.0.1/32"] + dest_fqdns = [] + dest_region_codes = [] + dest_threat_intelligences = [] + dest_address_groups = [google_network_security_address_group.address_group.id] + } +} +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_update(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_service_account" "service_account1" { + account_id = "tf-test-sa-%{random_suffix}" +} + +resource "google_service_account" "service_account2" { + account_id = "tf-test-sa2-%{random_suffix}" +} + +resource "google_compute_network" "network1" { + name = "tf-test-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_network" "network2" { + name = "tf-test-2-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9000 + enable_logging = true + action = "allow" + direction = "EGRESS" + disabled = false + target_service_accounts = [google_service_account.service_account1.email] + tls_inspect = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + ports = [8080] + } + layer4_configs { + ip_protocol = "udp" + ports = [22] + } + dest_ip_ranges = ["11.100.0.1/32", "10.0.0.0/24"] + dest_fqdns = ["google.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + src_address_groups = [] + dest_address_groups = [google_network_security_address_group.address_group.id] + } +} +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_removeConfigs(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_service_account" "service_account1" { + account_id = "tf-test-sa-%{random_suffix}" +} + +resource "google_service_account" "service_account2" { + account_id = "tf-test-sa2-%{random_suffix}" +} + +resource "google_compute_network" "network1" { + name = "tf-test-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_network" "network2" { + name = "tf-test-2-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Test description" + priority = 9000 + enable_logging = false + action = "deny" + direction = "INGRESS" + disabled = false + region = "%{region}" + + target_service_accounts = [ + google_service_account.service_account1.email, + google_service_account.service_account2.email + ] + + match { + layer4_configs { + ip_protocol = "udp" + ports = [22] + } + src_ip_ranges = ["11.100.0.1/32", "10.0.0.0/24"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + } +} +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_multiple(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_network" "network1" { + name = "tf-test-%{random_suffix}" + auto_create_subnetworks = false +} + +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_compute_region_network_firewall_policy_association" "fw_policy_a" { + name = "tf-test-policy-a-%{random_suffix}" + attachment_target = google_compute_network.network1.id + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9000 + enable_logging = true + action = "allow" + direction = "EGRESS" + disabled = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + ports = [80, 8080] + } + dest_ip_ranges = ["11.100.0.1/32"] + dest_fqdns = ["google.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + dest_address_groups = [google_network_security_address_group.address_group.id] + } +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule2" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9001 + enable_logging = false + action = "deny" + direction = "INGRESS" + disabled = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + ports = [80, 8080] + } + layer4_configs { + ip_protocol = "all" + } + src_ip_ranges = ["11.100.0.1/32"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + src_address_groups = [google_network_security_address_group.address_group.id] + } +} +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_multipleAdd(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9000 + enable_logging = true + action = "allow" + direction = "EGRESS" + disabled = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + } + dest_ip_ranges = ["11.100.0.1/32"] + dest_fqdns = ["google.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + dest_address_groups = [google_network_security_address_group.address_group.id] + } +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule2" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9001 + enable_logging = false + action = "deny" + direction = "INGRESS" + disabled = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + ports = [80, 8080] + } + layer4_configs { + ip_protocol = "all" + } + src_ip_ranges = ["11.100.0.1/32"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + src_address_groups = [google_network_security_address_group.address_group.id] + } +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule3" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 40 + enable_logging = true + action = "allow" + direction = "INGRESS" + disabled = true + region = "%{region}" + match { + layer4_configs { + ip_protocol = "udp" + ports = [8000] + } + src_ip_ranges = ["11.100.0.1/32", "10.0.0.0/24"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + src_address_groups = [google_network_security_address_group.address_group.id] + } +} +`, context) +} + +func testAccComputeRegionNetworkFirewallPolicyRule_multipleRemove(context map[string]interface{}) string { + return acctest.Nprintf(` +resource "google_compute_region_network_firewall_policy" "fw_policy" { + name = "tf-test-policy-%{random_suffix}" + description = "Resource created for Terraform acceptance testing" + region = "%{region}" +} + +resource "google_network_security_address_group" "address_group" { + name = "tf-test-policy%{random_suffix}" + parent = "%{org_name}" + description = "Sample global networksecurity_address_group" + location = "%{region}" + items = ["208.80.154.224/32"] + type = "IPV4" + capacity = 100 +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule1" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 9000 + enable_logging = true + action = "allow" + direction = "EGRESS" + disabled = false + region = "%{region}" + match { + layer4_configs { + ip_protocol = "tcp" + ports = [80, 8080] + } + dest_ip_ranges = ["11.100.0.1/32"] + dest_fqdns = ["google.com"] + dest_region_codes = ["US"] + dest_threat_intelligences = ["iplist-known-malicious-ips"] + } +} + +resource "google_compute_region_network_firewall_policy_rule" "fw_policy_rule3" { + firewall_policy = google_compute_region_network_firewall_policy.fw_policy.id + description = "Resource created for Terraform acceptance testing" + priority = 40 + enable_logging = true + action = "allow" + direction = "INGRESS" + disabled = true + region = "%{region}" + match { + layer4_configs { + ip_protocol = "udp" + ports = [8000] + } + src_ip_ranges = ["11.100.0.1/32", "10.0.0.0/24"] + src_fqdns = ["google.com"] + src_region_codes = ["US"] + src_threat_intelligences = ["iplist-known-malicious-ips"] + } +} +`, context) +} diff --git a/tpgtools/overrides/compute/beta/network_firewall_policy_rule.yaml b/tpgtools/overrides/compute/beta/network_firewall_policy_rule.yaml deleted file mode 100644 index 4ad5ccbeee34..000000000000 --- a/tpgtools/overrides/compute/beta/network_firewall_policy_rule.yaml +++ /dev/null @@ -1,24 +0,0 @@ -- type: CUSTOM_RESOURCE_NAME - details: - title: region_network_firewall_policy_rule - location: region -- type: EXCLUDE - field: location - location: global -- type: EXCLUDE - field: region - location: region -- type: CUSTOM_NAME - details: - name: region - field: location - location: region -- type: CUSTOM_ID - details: - id: projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/{{priority}} - location: region -- type: CUSTOMIZE_DIFF - details: - functions: - - tpgresource.DefaultProviderProject - - tpgresource.DefaultProviderRegion diff --git a/tpgtools/overrides/compute/network_firewall_policy_rule.yaml b/tpgtools/overrides/compute/network_firewall_policy_rule.yaml deleted file mode 100644 index 4ad5ccbeee34..000000000000 --- a/tpgtools/overrides/compute/network_firewall_policy_rule.yaml +++ /dev/null @@ -1,24 +0,0 @@ -- type: CUSTOM_RESOURCE_NAME - details: - title: region_network_firewall_policy_rule - location: region -- type: EXCLUDE - field: location - location: global -- type: EXCLUDE - field: region - location: region -- type: CUSTOM_NAME - details: - name: region - field: location - location: region -- type: CUSTOM_ID - details: - id: projects/{{project}}/regions/{{region}}/firewallPolicies/{{firewall_policy}}/{{priority}} - location: region -- type: CUSTOMIZE_DIFF - details: - functions: - - tpgresource.DefaultProviderProject - - tpgresource.DefaultProviderRegion