From 12aa4572d7e76a986ae973557d5f5128db8c8831 Mon Sep 17 00:00:00 2001 From: Nat Henderson Date: Tue, 7 Sep 2021 23:26:45 -0700 Subject: [PATCH] Global forwarding rule and forwarding rule DCL conversion. (#5138) * Add forwarding rule to tpgtools. --- mmv1/products/compute/terraform.yaml | 22 + mmv1/third_party/terraform/go.mod.erb | 2 +- mmv1/third_party/terraform/go.sum | 6 + ...rce_google_compute_forwarding_rule_test.go | 2 +- ...gle_global_compute_forwarding_rule_test.go | 2 +- ...compute_global_forwarding_rule_test.go.erb | 7 + .../api/compute/beta/forwarding_rule.yaml | 417 ++++++++++++++++++ tpgtools/api/compute/forwarding_rule.yaml | 417 ++++++++++++++++++ tpgtools/go.mod | 2 +- tpgtools/go.sum | 4 +- tpgtools/override.go | 3 + tpgtools/override_details.go | 16 + .../compute/beta/forwarding_rule.yaml | 125 ++++++ .../overrides/compute/forwarding_rule.yaml | 125 ++++++ tpgtools/property.go | 49 +- tpgtools/serialization.go | 410 +++++++++++++++++ tpgtools/templates/resource.go.tmpl | 6 + 17 files changed, 1604 insertions(+), 11 deletions(-) create mode 100755 tpgtools/api/compute/beta/forwarding_rule.yaml create mode 100755 tpgtools/api/compute/forwarding_rule.yaml create mode 100644 tpgtools/overrides/compute/beta/forwarding_rule.yaml create mode 100644 tpgtools/overrides/compute/forwarding_rule.yaml diff --git a/mmv1/products/compute/terraform.yaml b/mmv1/products/compute/terraform.yaml index 7eecf7af2112..f574c4f21f58 100644 --- a/mmv1/products/compute/terraform.yaml +++ b/mmv1/products/compute/terraform.yaml @@ -729,6 +729,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides fw_allow_ilb_to_backends_name: "l7-ilb-fw-allow-ilb-to-backends" vm_test_name: "l7-ilb-test-vm" min_version: beta + ignore_read_extra: + - "port_range" + - "target" - !ruby/object:Provider::Terraform::Examples name: "internal_tcp_udp_lb_with_mig_backend" primary_resource_id: "google_compute_forwarding_rule" @@ -753,6 +756,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides backend_name: "website-backend" network_name: "website-net" min_version: beta + ignore_read_extra: + - "port_range" - !ruby/object:Provider::Terraform::Examples name: "forwarding_rule_global_internallb" primary_resource_id: "default" @@ -766,6 +771,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides vars: forwarding_rule_name: "website-forwarding-rule" target_pool_name: "website-target-pool" + ignore_read_extra: + - "port_range" + - "target" - !ruby/object:Provider::Terraform::Examples name: "forwarding_rule_l3_default" primary_resource_id: "fwd_rule" @@ -781,6 +789,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides forwarding_rule_name: "website-forwarding-rule" backend_name: "website-backend" network_name: "website-net" + ignore_read_extra: + - "port_range" + - "target" - !ruby/object:Provider::Terraform::Examples name: "forwarding_rule_http_lb" min_version: 'beta' @@ -794,6 +805,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides rigm_name: "website-rigm" network_name: "website-net" fw_name: "website-fw" + ignore_read_extra: + - "port_range" + - "target" custom_code: !ruby/object:Provider::Terraform::CustomCode post_create: templates/terraform/post_create/labels.erb properties: @@ -872,6 +886,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides forwarding_rule_name: "global-rule" http_proxy_name: "target-proxy" backend_service_name: "backend" + ignore_read_extra: + - "port_range" + - "target" - !ruby/object:Provider::Terraform::Examples name: "global_forwarding_rule_internal" min_version: beta @@ -881,6 +898,9 @@ overrides: !ruby/object:Overrides::ResourceOverrides http_proxy_name: "target-proxy" backend_service_name: "backend" igm_name: "igm-internal" + ignore_read_extra: + - "port_range" + - "target" - !ruby/object:Provider::Terraform::Examples name: "private_service_connect_google_apis" min_version: beta @@ -892,6 +912,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides forwarding_rule_name: "globalrule" test_env_vars: project: :PROJECT_NAME + ignore_read_extra: + - "ip_address" properties: creationTimestamp: !ruby/object:Overrides::Terraform::PropertyOverride exclude: true diff --git a/mmv1/third_party/terraform/go.mod.erb b/mmv1/third_party/terraform/go.mod.erb index adebcca50bba..d9fc0a9558b6 100644 --- a/mmv1/third_party/terraform/go.mod.erb +++ b/mmv1/third_party/terraform/go.mod.erb @@ -3,7 +3,7 @@ module github.com/hashicorp/terraform-provider-google<%= "-" + version unless ve require ( cloud.google.com/go/bigtable v1.10.1 - github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a + github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9 github.com/apparentlymart/go-cidr v1.1.0 github.com/client9/misspell v0.3.4 github.com/davecgh/go-spew v1.1.1 diff --git a/mmv1/third_party/terraform/go.sum b/mmv1/third_party/terraform/go.sum index 7fc3f73e5e8a..1f336365d288 100644 --- a/mmv1/third_party/terraform/go.sum +++ b/mmv1/third_party/terraform/go.sum @@ -67,6 +67,12 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOC github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24 h1:sHglBQTwgx+rWPdisA5ynNEsoARbiCBOyGcJM4/OzsM= github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24/go.mod h1:4UJr5HIiMZrwgkSPdsjy2uOQExX/WEILpIrO9UPGuXs= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9 h1:b4+4SWkgDcBSTpKYvl+SaUDZ/PwEMfnuI1z41qPy+z8= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210830202814-90d607e5aba1 h1:Cq6wsP8cz8yoyIqVe9qXiuLv6myB3jY5aCobrvTN5WQ= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210830202814-90d607e5aba1/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210828005957-5e300a425b22 h1:r1uW7IkHP90/jxMW8Br+DzEK2wuZQs0JFYC6T5foazk= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210828005957-5e300a425b22/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a h1:k71tcjN3d1+YrSB1cN2d9T787JjbwbfNFM6HarBrn2o= github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210623224421-7f5af5003bbb h1:9HBI5n77Z2ReBlOFk1h2JFLpY/HobH9Xaq90E7IjCpw= diff --git a/mmv1/third_party/terraform/tests/data_source_google_compute_forwarding_rule_test.go b/mmv1/third_party/terraform/tests/data_source_google_compute_forwarding_rule_test.go index 2538ac1c7277..03966829c6b2 100644 --- a/mmv1/third_party/terraform/tests/data_source_google_compute_forwarding_rule_test.go +++ b/mmv1/third_party/terraform/tests/data_source_google_compute_forwarding_rule_test.go @@ -19,7 +19,7 @@ func TestAccDataSourceGoogleForwardingRule(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccDataSourceGoogleForwardingRuleConfig(poolName, ruleName), - Check: checkDataSourceStateMatchesResourceState("data.google_compute_forwarding_rule.my_forwarding_rule", "google_compute_forwarding_rule.foobar-fr"), + Check: checkDataSourceStateMatchesResourceStateWithIgnores("data.google_compute_forwarding_rule.my_forwarding_rule", "google_compute_forwarding_rule.foobar-fr", map[string]struct{}{"port_range": {}, "target": {}}), }, }, }) diff --git a/mmv1/third_party/terraform/tests/data_source_google_global_compute_forwarding_rule_test.go b/mmv1/third_party/terraform/tests/data_source_google_global_compute_forwarding_rule_test.go index ec276b52c534..79768efa5d5c 100644 --- a/mmv1/third_party/terraform/tests/data_source_google_global_compute_forwarding_rule_test.go +++ b/mmv1/third_party/terraform/tests/data_source_google_global_compute_forwarding_rule_test.go @@ -19,7 +19,7 @@ func TestAccDataSourceGoogleGlobalForwardingRule(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccDataSourceGoogleGlobalForwardingRuleConfig(poolName, ruleName), - Check: checkDataSourceStateMatchesResourceState("data.google_compute_global_forwarding_rule.my_forwarding_rule", "google_compute_global_forwarding_rule.foobar-fr"), + Check: checkDataSourceStateMatchesResourceStateWithIgnores("data.google_compute_global_forwarding_rule.my_forwarding_rule", "google_compute_global_forwarding_rule.foobar-fr", map[string]struct{}{"port_range": {}, "target": {}}), }, }, }) diff --git a/mmv1/third_party/terraform/tests/resource_compute_global_forwarding_rule_test.go.erb b/mmv1/third_party/terraform/tests/resource_compute_global_forwarding_rule_test.go.erb index 2d098c253305..948952677331 100644 --- a/mmv1/third_party/terraform/tests/resource_compute_global_forwarding_rule_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_compute_global_forwarding_rule_test.go.erb @@ -35,6 +35,7 @@ func TestAccComputeGlobalForwardingRule_updateTarget(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, { Config: testAccComputeGlobalForwardingRule_httpProxy(fr, "proxy2", proxy, proxyUpdated, backend, hc, urlmap), @@ -47,6 +48,7 @@ func TestAccComputeGlobalForwardingRule_updateTarget(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, }, }) @@ -77,6 +79,7 @@ func TestAccComputeGlobalForwardingRule_ipv6(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, }, }) @@ -104,6 +107,7 @@ func TestAccComputeGlobalForwardingRule_labels(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, { Config: testAccComputeGlobalForwardingRule_labelsUpdated(fr, proxy, backend, hc, urlmap), @@ -112,6 +116,7 @@ func TestAccComputeGlobalForwardingRule_labels(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, }, }) @@ -142,6 +147,7 @@ func TestAccComputeGlobalForwardingRule_internalLoadBalancing(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, { Config: testAccComputeGlobalForwardingRule_internalLoadBalancingUpdate(fr, proxy, backend, hc, urlmap, igm, it), @@ -150,6 +156,7 @@ func TestAccComputeGlobalForwardingRule_internalLoadBalancing(t *testing.T) { ResourceName: "google_compute_global_forwarding_rule.forwarding_rule", ImportState: true, ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"port_range", "target"}, }, }, }) diff --git a/tpgtools/api/compute/beta/forwarding_rule.yaml b/tpgtools/api/compute/beta/forwarding_rule.yaml new file mode 100755 index 000000000000..839af3272ffd --- /dev/null +++ b/tpgtools/api/compute/beta/forwarding_rule.yaml @@ -0,0 +1,417 @@ +# Copyright 2021 Google LLC. All Rights Reserved. +# +# 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. +info: + title: Compute/ForwardingRule + description: DCL Specification for the Compute ForwardingRule resource + x-dcl-has-iam: false +paths: + get: + description: The function used to get information about a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + apply: + description: The function used to apply information about a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + delete: + description: The function used to delete a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + deleteAll: + description: The function used to delete all ForwardingRule + parameters: + - name: project + required: true + schema: + type: string + - name: location + required: true + schema: + type: string + list: + description: The function used to list information about many ForwardingRule + parameters: + - name: project + required: true + schema: + type: string + - name: location + required: true + schema: + type: string +components: + schemas: + ForwardingRule: + title: ForwardingRule + x-dcl-id: projects/{{project}}/global/forwardingRules/{{name}} + x-dcl-locations: + - region + - global + x-dcl-parent-container: project + x-dcl-labels: labels + type: object + required: + - name + - project + properties: + allPorts: + type: boolean + x-dcl-go-name: AllPorts + description: This field is used along with the `backend_service` field for + internal load balancing or with the `target` field for internal TargetInstance. + This field cannot be used with `port` or `portRange` fields. When the + load balancing scheme is `INTERNAL` and protocol is TCP/UDP, specify this + field to allow packets addressed to any ports will be forwarded to the + backends configured with this forwarding rule. + x-kubernetes-immutable: true + allowGlobalAccess: + type: boolean + x-dcl-go-name: AllowGlobalAccess + description: This field is used along with the `backend_service` field for + internal load balancing or with the `target` field for internal TargetInstance. + If the field is set to `TRUE`, clients can access ILB from all regions. + Otherwise only allows access from clients in the same region as the internal + load balancer. + backendService: + type: string + x-dcl-go-name: BackendService + description: This field is only used for `INTERNAL` load balancing. For + internal load balancing, this field identifies the BackendService resource + to receive the matched traffic. + x-kubernetes-immutable: true + creationTimestamp: + type: string + x-dcl-go-name: CreationTimestamp + readOnly: true + description: '[Output Only] Creation timestamp in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) + text format.' + x-kubernetes-immutable: true + description: + type: string + x-dcl-go-name: Description + description: An optional description of this resource. Provide this property + when you create the resource. + x-kubernetes-immutable: true + ipAddress: + type: string + x-dcl-go-name: IPAddress + description: 'IP address that this forwarding rule serves. When a client + sends traffic to this IP address, the forwarding rule directs the traffic + to the target that you specify in the forwarding rule. If you don''t specify + a reserved IP address, an ephemeral IP address is assigned. Methods for + specifying an IP address: * IPv4 dotted decimal, as in `100.1.2.3` * Full + URL, as in `https://www.googleapis.com/compute/v1/projects/project_id/regions/region/addresses/address-name` + * Partial URL or by name, as in: * `projects/project_id/regions/region/addresses/address-name` + * `regions/region/addresses/address-name` * `global/addresses/address-name` + * `address-name` The loadBalancingScheme and the forwarding rule''s target + determine the type of IP address that you can use. For detailed information, + refer to [IP address specifications](/load-balancing/docs/forwarding-rule-concepts#ip_address_specifications).' + x-kubernetes-immutable: true + x-dcl-server-default: true + ipProtocol: + type: string + x-dcl-go-name: IPProtocol + x-dcl-go-type: ForwardingRuleIPProtocolEnum + description: The IP protocol to which this rule applies. For protocol forwarding, + valid options are `TCP`, `UDP`, `ESP`, `AH`, `SCTP` or `ICMP`. For Internal + TCP/UDP Load Balancing, the load balancing scheme is `INTERNAL`, and one + of `TCP` or `UDP` are valid. For Traffic Director, the load balancing + scheme is `INTERNAL_SELF_MANAGED`, and only `TCP`is valid. For Internal + HTTP(S) Load Balancing, the load balancing scheme is `INTERNAL_MANAGED`, + and only `TCP` is valid. For HTTP(S), SSL Proxy, and TCP Proxy Load Balancing, + the load balancing scheme is `EXTERNAL` and only `TCP` is valid. For Network + TCP/UDP Load Balancing, the load balancing scheme is `EXTERNAL`, and one + of `TCP` or `UDP` is valid. + x-kubernetes-immutable: true + x-dcl-server-default: true + enum: + - TCP + - UDP + - ESP + - AH + - SCTP + - ICMP + - L3_DEFAULT + ipVersion: + type: string + x-dcl-go-name: IPVersion + x-dcl-go-type: ForwardingRuleIPVersionEnum + description: 'The IP Version that will be used by this forwarding rule. + Valid options are `IPV4` or `IPV6`. This can only be specified for an + external global forwarding rule. Possible values: UNSPECIFIED_VERSION, + IPV4, IPV6' + x-kubernetes-immutable: true + enum: + - UNSPECIFIED_VERSION + - IPV4 + - IPV6 + isMirroringCollector: + type: boolean + x-dcl-go-name: IsMirroringCollector + description: Indicates whether or not this load balancer can be used as + a collector for packet mirroring. To prevent mirroring loops, instances + behind this load balancer will not have their traffic mirrored even if + a `PacketMirroring` rule applies to them. This can only be set to true + for load balancers that have their `loadBalancingScheme` set to `INTERNAL`. + x-kubernetes-immutable: true + labelFingerprint: + type: string + x-dcl-go-name: LabelFingerprint + readOnly: true + description: Used internally during label updates. + x-kubernetes-immutable: true + labels: + type: object + additionalProperties: + type: string + x-dcl-go-name: Labels + description: Labels to apply to this rule. + loadBalancingScheme: + type: string + x-dcl-go-name: LoadBalancingScheme + x-dcl-go-type: ForwardingRuleLoadBalancingSchemeEnum + description: |- + Specifies the forwarding rule type. + + * `EXTERNAL` is used for: + * Classic Cloud VPN gateways + * Protocol forwarding to VMs from an external IP address + * The following load balancers: HTTP(S), SSL Proxy, TCP Proxy, and Network TCP/UDP + * `INTERNAL` is used for: + * Protocol forwarding to VMs from an internal IP address + * Internal TCP/UDP load balancers + * `INTERNAL_MANAGED` is used for: + * Internal HTTP(S) load balancers + * `INTERNAL_SELF_MANAGED` is used for: + * Traffic Director + + For more information about forwarding rules, refer to [Forwarding rule concepts](/load-balancing/docs/forwarding-rule-concepts). Possible values: INVALID, INTERNAL, INTERNAL_MANAGED, INTERNAL_SELF_MANAGED, EXTERNAL + x-kubernetes-immutable: true + enum: + - INVALID + - INTERNAL + - INTERNAL_MANAGED + - INTERNAL_SELF_MANAGED + - EXTERNAL + location: + type: string + x-dcl-go-name: Location + description: The location of this resource. + x-kubernetes-immutable: true + metadataFilter: + type: array + x-dcl-go-name: MetadataFilter + description: |- + Opaque filter criteria used by Loadbalancer to restrict routing configuration to a limited set of [xDS](https://github.com/envoyproxy/data-plane-api/blob/master/XDS_PROTOCOL.md) compliant clients. In their xDS requests to Loadbalancer, xDS clients present [node metadata](https://github.com/envoyproxy/data-plane-api/search?q=%22message+Node%22+in%3A%2Fenvoy%2Fapi%2Fv2%2Fcore%2Fbase.proto&). If a match takes place, the relevant configuration is made available to those proxies. Otherwise, all the resources (e.g. `TargetHttpProxy`, `UrlMap`) referenced by the `ForwardingRule` will not be visible to those proxies. + + For each `metadataFilter` in this list, if its `filterMatchCriteria` is set to MATCH_ANY, at least one of the `filterLabel`s must match the corresponding label provided in the metadata. If its `filterMatchCriteria` is set to MATCH_ALL, then all of its `filterLabel`s must match with corresponding labels provided in the metadata. + + `metadataFilters` specified here will be applifed before those specified in the `UrlMap` that this `ForwardingRule` references. + + `metadataFilters` only applies to Loadbalancers that have their loadBalancingScheme set to `INTERNAL_SELF_MANAGED`. + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: list + items: + type: object + x-dcl-go-type: ForwardingRuleMetadataFilter + required: + - filterMatchCriteria + - filterLabel + properties: + filterLabel: + type: array + x-dcl-go-name: FilterLabel + description: |- + The list of label value pairs that must match labels in the provided metadata based on `filterMatchCriteria` + + This list must not be empty and can have at the most 64 entries. + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: list + items: + type: object + x-dcl-go-type: ForwardingRuleMetadataFilterFilterLabel + required: + - name + - value + properties: + name: + type: string + x-dcl-go-name: Name + description: |- + Name of metadata label. + + The name can have a maximum length of 1024 characters and must be at least 1 character long. + x-kubernetes-immutable: true + value: + type: string + x-dcl-go-name: Value + description: |- + The value of the label must match the specified value. + + value can have a maximum length of 1024 characters. + x-kubernetes-immutable: true + filterMatchCriteria: + type: string + x-dcl-go-name: FilterMatchCriteria + x-dcl-go-type: ForwardingRuleMetadataFilterFilterMatchCriteriaEnum + description: |- + Specifies how individual `filterLabel` matches within the list of `filterLabel`s contribute towards the overall `metadataFilter` match. + + Supported values are: + + * MATCH_ANY: At least one of the `filterLabels` must have a matching label in the provided metadata. + * MATCH_ALL: All `filterLabels` must have matching labels in the provided metadata. Possible values: NOT_SET, MATCH_ALL, MATCH_ANY + x-kubernetes-immutable: true + enum: + - NOT_SET + - MATCH_ALL + - MATCH_ANY + name: + type: string + x-dcl-go-name: Name + description: Name of the resource; provided by the client when the resource + is created. The name must be 1-63 characters long, and comply with [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). + Specifically, the name must be 1-63 characters long and match the regular + expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character + must be a lowercase letter, and all following characters must be a dash, + lowercase letter, or digit, except the last character, which cannot be + a dash. + x-kubernetes-immutable: true + network: + type: string + x-dcl-go-name: Network + description: This field is not used for external load balancing. For `INTERNAL` + and `INTERNAL_SELF_MANAGED` load balancing, this field identifies the + network that the load balanced IP should belong to for this Forwarding + Rule. If this field is not specified, the default network will be used. + x-kubernetes-immutable: true + x-dcl-server-default: true + networkTier: + type: string + x-dcl-go-name: NetworkTier + x-dcl-go-type: ForwardingRuleNetworkTierEnum + description: 'This signifies the networking tier used for configuring this + load balancer and can only take the following values: `PREMIUM`, `STANDARD`. + For regional ForwardingRule, the valid values are `PREMIUM` and `STANDARD`. + For GlobalForwardingRule, the valid value is `PREMIUM`. If this field + is not specified, it is assumed to be `PREMIUM`. If `IPAddress` is specified, + this value must be equal to the networkTier of the Address.' + x-kubernetes-immutable: true + x-dcl-server-default: true + enum: + - PREMIUM + - STANDARD + portRange: + type: string + x-dcl-go-name: PortRange + description: |- + When the load balancing scheme is `EXTERNAL`, `INTERNAL_SELF_MANAGED` and `INTERNAL_MANAGED`, you can specify a `port_range`. Use with a forwarding rule that points to a target proxy or a target pool. Do not use with a forwarding rule that points to a backend service. This field is used along with the `target` field for TargetHttpProxy, TargetHttpsProxy, TargetSslProxy, TargetTcpProxy, TargetVpnGateway, TargetPool, TargetInstance. Applicable only when `IPProtocol` is `TCP`, `UDP`, or `SCTP`, only packets addressed to ports in the specified range will be forwarded to `target`. Forwarding rules with the same `[IPAddress, IPProtocol]` pair must have disjoint port ranges. Some types of forwarding target have constraints on the acceptable ports: + + * TargetHttpProxy: 80, 8080 + * TargetHttpsProxy: 443 + * TargetTcpProxy: 25, 43, 110, 143, 195, 443, 465, 587, 700, 993, 995, 1688, 1883, 5222 + * TargetSslProxy: 25, 43, 110, 143, 195, 443, 465, 587, 700, 993, 995, 1688, 1883, 5222 + * TargetVpnGateway: 500, 4500 + + @pattern: d+(?:-d+)? + x-kubernetes-immutable: true + ports: + type: array + x-dcl-go-name: Ports + description: 'This field is used along with the `backend_service` field + for internal load balancing. When the load balancing scheme is `INTERNAL`, + a list of ports can be configured, for example, [''80''], [''8000'',''9000'']. + Only packets addressed to these ports are forwarded to the backends configured + with the forwarding rule. If the forwarding rule''s loadBalancingScheme + is INTERNAL, you can specify ports in one of the following ways: * A list + of up to five ports, which can be non-contiguous * Keyword `ALL`, which + causes the forwarding rule to forward traffic on any port of the forwarding + rule''s protocol. @pattern: d+(?:-d+)? For more information, refer to + [Port specifications](/load-balancing/docs/forwarding-rule-concepts#port_specifications).' + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: set + items: + type: string + x-dcl-go-type: string + project: + type: string + x-dcl-go-name: Project + description: The project this resource belongs in. + x-kubernetes-immutable: true + x-dcl-references: + - resource: Cloudresourcemanager/Project + field: name + parent: true + region: + type: string + x-dcl-go-name: Region + description: '[Output Only] URL of the region where the regional forwarding + rule resides. This field is not applicable to global forwarding rules. + You must specify this field as part of the HTTP request URL. It is not + settable as a field in the request body.' + x-kubernetes-immutable: true + selfLink: + type: string + x-dcl-go-name: SelfLink + readOnly: true + description: '[Output Only] Server-defined URL for the resource.' + x-kubernetes-immutable: true + serviceLabel: + type: string + x-dcl-go-name: ServiceLabel + description: An optional prefix to the service name for this Forwarding + Rule. If specified, the prefix is the first label of the fully qualified + service name. The label must be 1-63 characters long, and comply with + [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). Specifically, the label + must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` + which means the first character must be a lowercase letter, and all following + characters must be a dash, lowercase letter, or digit, except the last + character, which cannot be a dash. This field is only used for internal + load balancing. + x-kubernetes-immutable: true + serviceName: + type: string + x-dcl-go-name: ServiceName + readOnly: true + description: '[Output Only] The internal fully qualified service name for + this Forwarding Rule. This field is only used for internal load balancing.' + x-kubernetes-immutable: true + subnetwork: + type: string + x-dcl-go-name: Subnetwork + description: This field is only used for `INTERNAL` load balancing. For + internal load balancing, this field identifies the subnetwork that the + load balanced IP should belong to for this Forwarding Rule. If the network + specified is in auto subnet mode, this field is optional. However, if + the network is in custom subnet mode, a subnetwork must be specified. + x-kubernetes-immutable: true + x-dcl-server-default: true + target: + type: string + x-dcl-go-name: Target + description: The URL of the target resource to receive the matched traffic. + For regional forwarding rules, this target must live in the same region + as the forwarding rule. For global forwarding rules, this target must + be a global load balancing resource. The forwarded traffic must be of + a type appropriate to the target object. For `INTERNAL_SELF_MANAGED` load + balancing, only `targetHttpProxy` is valid, not `targetHttpsProxy`. diff --git a/tpgtools/api/compute/forwarding_rule.yaml b/tpgtools/api/compute/forwarding_rule.yaml new file mode 100755 index 000000000000..839af3272ffd --- /dev/null +++ b/tpgtools/api/compute/forwarding_rule.yaml @@ -0,0 +1,417 @@ +# Copyright 2021 Google LLC. All Rights Reserved. +# +# 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. +info: + title: Compute/ForwardingRule + description: DCL Specification for the Compute ForwardingRule resource + x-dcl-has-iam: false +paths: + get: + description: The function used to get information about a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + apply: + description: The function used to apply information about a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + delete: + description: The function used to delete a ForwardingRule + parameters: + - name: ForwardingRule + required: true + description: A full instance of a ForwardingRule + deleteAll: + description: The function used to delete all ForwardingRule + parameters: + - name: project + required: true + schema: + type: string + - name: location + required: true + schema: + type: string + list: + description: The function used to list information about many ForwardingRule + parameters: + - name: project + required: true + schema: + type: string + - name: location + required: true + schema: + type: string +components: + schemas: + ForwardingRule: + title: ForwardingRule + x-dcl-id: projects/{{project}}/global/forwardingRules/{{name}} + x-dcl-locations: + - region + - global + x-dcl-parent-container: project + x-dcl-labels: labels + type: object + required: + - name + - project + properties: + allPorts: + type: boolean + x-dcl-go-name: AllPorts + description: This field is used along with the `backend_service` field for + internal load balancing or with the `target` field for internal TargetInstance. + This field cannot be used with `port` or `portRange` fields. When the + load balancing scheme is `INTERNAL` and protocol is TCP/UDP, specify this + field to allow packets addressed to any ports will be forwarded to the + backends configured with this forwarding rule. + x-kubernetes-immutable: true + allowGlobalAccess: + type: boolean + x-dcl-go-name: AllowGlobalAccess + description: This field is used along with the `backend_service` field for + internal load balancing or with the `target` field for internal TargetInstance. + If the field is set to `TRUE`, clients can access ILB from all regions. + Otherwise only allows access from clients in the same region as the internal + load balancer. + backendService: + type: string + x-dcl-go-name: BackendService + description: This field is only used for `INTERNAL` load balancing. For + internal load balancing, this field identifies the BackendService resource + to receive the matched traffic. + x-kubernetes-immutable: true + creationTimestamp: + type: string + x-dcl-go-name: CreationTimestamp + readOnly: true + description: '[Output Only] Creation timestamp in [RFC3339](https://www.ietf.org/rfc/rfc3339.txt) + text format.' + x-kubernetes-immutable: true + description: + type: string + x-dcl-go-name: Description + description: An optional description of this resource. Provide this property + when you create the resource. + x-kubernetes-immutable: true + ipAddress: + type: string + x-dcl-go-name: IPAddress + description: 'IP address that this forwarding rule serves. When a client + sends traffic to this IP address, the forwarding rule directs the traffic + to the target that you specify in the forwarding rule. If you don''t specify + a reserved IP address, an ephemeral IP address is assigned. Methods for + specifying an IP address: * IPv4 dotted decimal, as in `100.1.2.3` * Full + URL, as in `https://www.googleapis.com/compute/v1/projects/project_id/regions/region/addresses/address-name` + * Partial URL or by name, as in: * `projects/project_id/regions/region/addresses/address-name` + * `regions/region/addresses/address-name` * `global/addresses/address-name` + * `address-name` The loadBalancingScheme and the forwarding rule''s target + determine the type of IP address that you can use. For detailed information, + refer to [IP address specifications](/load-balancing/docs/forwarding-rule-concepts#ip_address_specifications).' + x-kubernetes-immutable: true + x-dcl-server-default: true + ipProtocol: + type: string + x-dcl-go-name: IPProtocol + x-dcl-go-type: ForwardingRuleIPProtocolEnum + description: The IP protocol to which this rule applies. For protocol forwarding, + valid options are `TCP`, `UDP`, `ESP`, `AH`, `SCTP` or `ICMP`. For Internal + TCP/UDP Load Balancing, the load balancing scheme is `INTERNAL`, and one + of `TCP` or `UDP` are valid. For Traffic Director, the load balancing + scheme is `INTERNAL_SELF_MANAGED`, and only `TCP`is valid. For Internal + HTTP(S) Load Balancing, the load balancing scheme is `INTERNAL_MANAGED`, + and only `TCP` is valid. For HTTP(S), SSL Proxy, and TCP Proxy Load Balancing, + the load balancing scheme is `EXTERNAL` and only `TCP` is valid. For Network + TCP/UDP Load Balancing, the load balancing scheme is `EXTERNAL`, and one + of `TCP` or `UDP` is valid. + x-kubernetes-immutable: true + x-dcl-server-default: true + enum: + - TCP + - UDP + - ESP + - AH + - SCTP + - ICMP + - L3_DEFAULT + ipVersion: + type: string + x-dcl-go-name: IPVersion + x-dcl-go-type: ForwardingRuleIPVersionEnum + description: 'The IP Version that will be used by this forwarding rule. + Valid options are `IPV4` or `IPV6`. This can only be specified for an + external global forwarding rule. Possible values: UNSPECIFIED_VERSION, + IPV4, IPV6' + x-kubernetes-immutable: true + enum: + - UNSPECIFIED_VERSION + - IPV4 + - IPV6 + isMirroringCollector: + type: boolean + x-dcl-go-name: IsMirroringCollector + description: Indicates whether or not this load balancer can be used as + a collector for packet mirroring. To prevent mirroring loops, instances + behind this load balancer will not have their traffic mirrored even if + a `PacketMirroring` rule applies to them. This can only be set to true + for load balancers that have their `loadBalancingScheme` set to `INTERNAL`. + x-kubernetes-immutable: true + labelFingerprint: + type: string + x-dcl-go-name: LabelFingerprint + readOnly: true + description: Used internally during label updates. + x-kubernetes-immutable: true + labels: + type: object + additionalProperties: + type: string + x-dcl-go-name: Labels + description: Labels to apply to this rule. + loadBalancingScheme: + type: string + x-dcl-go-name: LoadBalancingScheme + x-dcl-go-type: ForwardingRuleLoadBalancingSchemeEnum + description: |- + Specifies the forwarding rule type. + + * `EXTERNAL` is used for: + * Classic Cloud VPN gateways + * Protocol forwarding to VMs from an external IP address + * The following load balancers: HTTP(S), SSL Proxy, TCP Proxy, and Network TCP/UDP + * `INTERNAL` is used for: + * Protocol forwarding to VMs from an internal IP address + * Internal TCP/UDP load balancers + * `INTERNAL_MANAGED` is used for: + * Internal HTTP(S) load balancers + * `INTERNAL_SELF_MANAGED` is used for: + * Traffic Director + + For more information about forwarding rules, refer to [Forwarding rule concepts](/load-balancing/docs/forwarding-rule-concepts). Possible values: INVALID, INTERNAL, INTERNAL_MANAGED, INTERNAL_SELF_MANAGED, EXTERNAL + x-kubernetes-immutable: true + enum: + - INVALID + - INTERNAL + - INTERNAL_MANAGED + - INTERNAL_SELF_MANAGED + - EXTERNAL + location: + type: string + x-dcl-go-name: Location + description: The location of this resource. + x-kubernetes-immutable: true + metadataFilter: + type: array + x-dcl-go-name: MetadataFilter + description: |- + Opaque filter criteria used by Loadbalancer to restrict routing configuration to a limited set of [xDS](https://github.com/envoyproxy/data-plane-api/blob/master/XDS_PROTOCOL.md) compliant clients. In their xDS requests to Loadbalancer, xDS clients present [node metadata](https://github.com/envoyproxy/data-plane-api/search?q=%22message+Node%22+in%3A%2Fenvoy%2Fapi%2Fv2%2Fcore%2Fbase.proto&). If a match takes place, the relevant configuration is made available to those proxies. Otherwise, all the resources (e.g. `TargetHttpProxy`, `UrlMap`) referenced by the `ForwardingRule` will not be visible to those proxies. + + For each `metadataFilter` in this list, if its `filterMatchCriteria` is set to MATCH_ANY, at least one of the `filterLabel`s must match the corresponding label provided in the metadata. If its `filterMatchCriteria` is set to MATCH_ALL, then all of its `filterLabel`s must match with corresponding labels provided in the metadata. + + `metadataFilters` specified here will be applifed before those specified in the `UrlMap` that this `ForwardingRule` references. + + `metadataFilters` only applies to Loadbalancers that have their loadBalancingScheme set to `INTERNAL_SELF_MANAGED`. + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: list + items: + type: object + x-dcl-go-type: ForwardingRuleMetadataFilter + required: + - filterMatchCriteria + - filterLabel + properties: + filterLabel: + type: array + x-dcl-go-name: FilterLabel + description: |- + The list of label value pairs that must match labels in the provided metadata based on `filterMatchCriteria` + + This list must not be empty and can have at the most 64 entries. + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: list + items: + type: object + x-dcl-go-type: ForwardingRuleMetadataFilterFilterLabel + required: + - name + - value + properties: + name: + type: string + x-dcl-go-name: Name + description: |- + Name of metadata label. + + The name can have a maximum length of 1024 characters and must be at least 1 character long. + x-kubernetes-immutable: true + value: + type: string + x-dcl-go-name: Value + description: |- + The value of the label must match the specified value. + + value can have a maximum length of 1024 characters. + x-kubernetes-immutable: true + filterMatchCriteria: + type: string + x-dcl-go-name: FilterMatchCriteria + x-dcl-go-type: ForwardingRuleMetadataFilterFilterMatchCriteriaEnum + description: |- + Specifies how individual `filterLabel` matches within the list of `filterLabel`s contribute towards the overall `metadataFilter` match. + + Supported values are: + + * MATCH_ANY: At least one of the `filterLabels` must have a matching label in the provided metadata. + * MATCH_ALL: All `filterLabels` must have matching labels in the provided metadata. Possible values: NOT_SET, MATCH_ALL, MATCH_ANY + x-kubernetes-immutable: true + enum: + - NOT_SET + - MATCH_ALL + - MATCH_ANY + name: + type: string + x-dcl-go-name: Name + description: Name of the resource; provided by the client when the resource + is created. The name must be 1-63 characters long, and comply with [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). + Specifically, the name must be 1-63 characters long and match the regular + expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character + must be a lowercase letter, and all following characters must be a dash, + lowercase letter, or digit, except the last character, which cannot be + a dash. + x-kubernetes-immutable: true + network: + type: string + x-dcl-go-name: Network + description: This field is not used for external load balancing. For `INTERNAL` + and `INTERNAL_SELF_MANAGED` load balancing, this field identifies the + network that the load balanced IP should belong to for this Forwarding + Rule. If this field is not specified, the default network will be used. + x-kubernetes-immutable: true + x-dcl-server-default: true + networkTier: + type: string + x-dcl-go-name: NetworkTier + x-dcl-go-type: ForwardingRuleNetworkTierEnum + description: 'This signifies the networking tier used for configuring this + load balancer and can only take the following values: `PREMIUM`, `STANDARD`. + For regional ForwardingRule, the valid values are `PREMIUM` and `STANDARD`. + For GlobalForwardingRule, the valid value is `PREMIUM`. If this field + is not specified, it is assumed to be `PREMIUM`. If `IPAddress` is specified, + this value must be equal to the networkTier of the Address.' + x-kubernetes-immutable: true + x-dcl-server-default: true + enum: + - PREMIUM + - STANDARD + portRange: + type: string + x-dcl-go-name: PortRange + description: |- + When the load balancing scheme is `EXTERNAL`, `INTERNAL_SELF_MANAGED` and `INTERNAL_MANAGED`, you can specify a `port_range`. Use with a forwarding rule that points to a target proxy or a target pool. Do not use with a forwarding rule that points to a backend service. This field is used along with the `target` field for TargetHttpProxy, TargetHttpsProxy, TargetSslProxy, TargetTcpProxy, TargetVpnGateway, TargetPool, TargetInstance. Applicable only when `IPProtocol` is `TCP`, `UDP`, or `SCTP`, only packets addressed to ports in the specified range will be forwarded to `target`. Forwarding rules with the same `[IPAddress, IPProtocol]` pair must have disjoint port ranges. Some types of forwarding target have constraints on the acceptable ports: + + * TargetHttpProxy: 80, 8080 + * TargetHttpsProxy: 443 + * TargetTcpProxy: 25, 43, 110, 143, 195, 443, 465, 587, 700, 993, 995, 1688, 1883, 5222 + * TargetSslProxy: 25, 43, 110, 143, 195, 443, 465, 587, 700, 993, 995, 1688, 1883, 5222 + * TargetVpnGateway: 500, 4500 + + @pattern: d+(?:-d+)? + x-kubernetes-immutable: true + ports: + type: array + x-dcl-go-name: Ports + description: 'This field is used along with the `backend_service` field + for internal load balancing. When the load balancing scheme is `INTERNAL`, + a list of ports can be configured, for example, [''80''], [''8000'',''9000'']. + Only packets addressed to these ports are forwarded to the backends configured + with the forwarding rule. If the forwarding rule''s loadBalancingScheme + is INTERNAL, you can specify ports in one of the following ways: * A list + of up to five ports, which can be non-contiguous * Keyword `ALL`, which + causes the forwarding rule to forward traffic on any port of the forwarding + rule''s protocol. @pattern: d+(?:-d+)? For more information, refer to + [Port specifications](/load-balancing/docs/forwarding-rule-concepts#port_specifications).' + x-kubernetes-immutable: true + x-dcl-send-empty: true + x-dcl-list-type: set + items: + type: string + x-dcl-go-type: string + project: + type: string + x-dcl-go-name: Project + description: The project this resource belongs in. + x-kubernetes-immutable: true + x-dcl-references: + - resource: Cloudresourcemanager/Project + field: name + parent: true + region: + type: string + x-dcl-go-name: Region + description: '[Output Only] URL of the region where the regional forwarding + rule resides. This field is not applicable to global forwarding rules. + You must specify this field as part of the HTTP request URL. It is not + settable as a field in the request body.' + x-kubernetes-immutable: true + selfLink: + type: string + x-dcl-go-name: SelfLink + readOnly: true + description: '[Output Only] Server-defined URL for the resource.' + x-kubernetes-immutable: true + serviceLabel: + type: string + x-dcl-go-name: ServiceLabel + description: An optional prefix to the service name for this Forwarding + Rule. If specified, the prefix is the first label of the fully qualified + service name. The label must be 1-63 characters long, and comply with + [RFC1035](https://www.ietf.org/rfc/rfc1035.txt). Specifically, the label + must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` + which means the first character must be a lowercase letter, and all following + characters must be a dash, lowercase letter, or digit, except the last + character, which cannot be a dash. This field is only used for internal + load balancing. + x-kubernetes-immutable: true + serviceName: + type: string + x-dcl-go-name: ServiceName + readOnly: true + description: '[Output Only] The internal fully qualified service name for + this Forwarding Rule. This field is only used for internal load balancing.' + x-kubernetes-immutable: true + subnetwork: + type: string + x-dcl-go-name: Subnetwork + description: This field is only used for `INTERNAL` load balancing. For + internal load balancing, this field identifies the subnetwork that the + load balanced IP should belong to for this Forwarding Rule. If the network + specified is in auto subnet mode, this field is optional. However, if + the network is in custom subnet mode, a subnetwork must be specified. + x-kubernetes-immutable: true + x-dcl-server-default: true + target: + type: string + x-dcl-go-name: Target + description: The URL of the target resource to receive the matched traffic. + For regional forwarding rules, this target must live in the same region + as the forwarding rule. For global forwarding rules, this target must + be a global load balancing resource. The forwarded traffic must be of + a type appropriate to the target object. For `INTERNAL_SELF_MANAGED` load + balancing, only `targetHttpProxy` is valid, not `targetHttpsProxy`. diff --git a/tpgtools/go.mod b/tpgtools/go.mod index a322af932f7d..99926aabd313 100644 --- a/tpgtools/go.mod +++ b/tpgtools/go.mod @@ -4,7 +4,7 @@ go 1.16 require ( bitbucket.org/creachadair/stringset v0.0.9 - github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a + github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/hashicorp/hcl v1.0.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0 diff --git a/tpgtools/go.sum b/tpgtools/go.sum index daa8c10be418..f6f679a6a079 100644 --- a/tpgtools/go.sum +++ b/tpgtools/go.sum @@ -36,8 +36,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= -github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a h1:k71tcjN3d1+YrSB1cN2d9T787JjbwbfNFM6HarBrn2o= -github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210824221031-bbef03d2748a/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9 h1:b4+4SWkgDcBSTpKYvl+SaUDZ/PwEMfnuI1z41qPy+z8= +github.com/GoogleCloudPlatform/declarative-resource-client-library v0.0.0-20210901222754-f6c1204eeae9/go.mod h1:oEeBHikdF/NrnUy0ornVaY1OT+jGvTqm+LQS0+ZDKzU= github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/agext/levenshtein v1.2.2 h1:0S/Yg6LYmFJ5stwQeRp6EeOcCbj7xiqQSdNelsXvaqE= github.com/agext/levenshtein v1.2.2/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= diff --git a/tpgtools/override.go b/tpgtools/override.go index 2619baad8509..0e86ec4f8117 100644 --- a/tpgtools/override.go +++ b/tpgtools/override.go @@ -68,6 +68,9 @@ const ( CollapsedObject = "COLLAPSED_OBJECT" IgnoreRead = "IGNORE_READ" GenerateIfNotSet = "GENERATE_IF_NOT_SET" + CustomListSize = "CUSTOM_LIST_SIZE_CONSTRAINT" + CustomDefault = "CUSTOM_DEFAULT" + CustomRequired = "REQUIRED_OVERRIDE" ) // Overrides represents the type a resource's override file can be marshalled diff --git a/tpgtools/override_details.go b/tpgtools/override_details.go index 3a454f030b77..2c709e659ae4 100644 --- a/tpgtools/override_details.go +++ b/tpgtools/override_details.go @@ -126,6 +126,22 @@ type CustomIdentityGetterDetails struct { Function string } +type CustomDefaultDetails struct { + Default string +} + +type CustomListSizeConstraintDetails struct { + Min int64 + Max int64 +} + +type CustomRequiredDetails struct { + Required bool + Optional bool + Computed bool + ForceNew bool +} + type ImportFormatDetails struct { // List of import format pattern strings Formats []string diff --git a/tpgtools/overrides/compute/beta/forwarding_rule.yaml b/tpgtools/overrides/compute/beta/forwarding_rule.yaml new file mode 100644 index 000000000000..a6bf76f6ec8c --- /dev/null +++ b/tpgtools/overrides/compute/beta/forwarding_rule.yaml @@ -0,0 +1,125 @@ +# TODO(ndmckinley): This one should be upstreamed to the DCL. +- type: CUSTOM_ID + details: + id: projects/{{project}}/regions/{{region}}/forwardingRules/{{name}} + location: region +- type: EXCLUDE + field: id +- type: CUSTOM_RESOURCE_NAME + details: + title: forwarding_rule + location: region +- type: REQUIRED_OVERRIDE + location: global + field: target + details: + required: true + optional: false + computed: false +- type: CUSTOM_DEFAULT + field: load_balancing_scheme + details: + default: "EXTERNAL" +- type: CUSTOM_LIST_SIZE_CONSTRAINT + field: ports + details: + max: 5 + location: region +- type: CUSTOM_LIST_SIZE_CONSTRAINT + field: metadata_filter.filter_label + details: + min: 1 + max: 64 + # The following excludes are added strictly to match initial tf schema, + # at request of rileykarson@, and can be removed + # to add features to global forwarding rule at your convenience. +- type: EXCLUDE + field: ip_version + location: region +- type: EXCLUDE + field: metadata_filter + location: region +- type: EXCLUDE + field: backend_service + location: global +- type: EXCLUDE + field: allow_global_access + location: global +- type: EXCLUDE + field: subnetwork + location: global +- type: EXCLUDE + field: service_name + location: global +- type: EXCLUDE + field: service_label + location: global +- type: EXCLUDE + field: ports + location: global +- type: EXCLUDE + field: network_tier + location: global +- type: EXCLUDE + field: is_mirroring_collector + location: global +- type: EXCLUDE + field: creation_timestamp + location: global +- type: EXCLUDE + field: all_ports + location: global + # end of cautionary excludes. +- type: EXCLUDE + field: region +- type: CUSTOM_NAME + details: + name: region + field: location +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: portRangeDiffSuppress + field: port_range +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkRelativePaths + field: target +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: subnetwork +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: location +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: network +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: caseDiffSuppress + field: ip_protocol +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: internalIpDiffSuppress + field: ip_address +- type: CUSTOM_VALIDATION + details: + function: validateGCPName + field: service_label +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: backend_service +- type: CUSTOM_NAME + details: + name: metadata_filters + field: metadata_filter +- type: CUSTOM_NAME + details: + name: filter_labels + field: metadata_filter.filter_label +- type: EXCLUDE + field: location + location: global diff --git a/tpgtools/overrides/compute/forwarding_rule.yaml b/tpgtools/overrides/compute/forwarding_rule.yaml new file mode 100644 index 000000000000..a6bf76f6ec8c --- /dev/null +++ b/tpgtools/overrides/compute/forwarding_rule.yaml @@ -0,0 +1,125 @@ +# TODO(ndmckinley): This one should be upstreamed to the DCL. +- type: CUSTOM_ID + details: + id: projects/{{project}}/regions/{{region}}/forwardingRules/{{name}} + location: region +- type: EXCLUDE + field: id +- type: CUSTOM_RESOURCE_NAME + details: + title: forwarding_rule + location: region +- type: REQUIRED_OVERRIDE + location: global + field: target + details: + required: true + optional: false + computed: false +- type: CUSTOM_DEFAULT + field: load_balancing_scheme + details: + default: "EXTERNAL" +- type: CUSTOM_LIST_SIZE_CONSTRAINT + field: ports + details: + max: 5 + location: region +- type: CUSTOM_LIST_SIZE_CONSTRAINT + field: metadata_filter.filter_label + details: + min: 1 + max: 64 + # The following excludes are added strictly to match initial tf schema, + # at request of rileykarson@, and can be removed + # to add features to global forwarding rule at your convenience. +- type: EXCLUDE + field: ip_version + location: region +- type: EXCLUDE + field: metadata_filter + location: region +- type: EXCLUDE + field: backend_service + location: global +- type: EXCLUDE + field: allow_global_access + location: global +- type: EXCLUDE + field: subnetwork + location: global +- type: EXCLUDE + field: service_name + location: global +- type: EXCLUDE + field: service_label + location: global +- type: EXCLUDE + field: ports + location: global +- type: EXCLUDE + field: network_tier + location: global +- type: EXCLUDE + field: is_mirroring_collector + location: global +- type: EXCLUDE + field: creation_timestamp + location: global +- type: EXCLUDE + field: all_ports + location: global + # end of cautionary excludes. +- type: EXCLUDE + field: region +- type: CUSTOM_NAME + details: + name: region + field: location +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: portRangeDiffSuppress + field: port_range +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkRelativePaths + field: target +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: subnetwork +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: location +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: network +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: caseDiffSuppress + field: ip_protocol +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: internalIpDiffSuppress + field: ip_address +- type: CUSTOM_VALIDATION + details: + function: validateGCPName + field: service_label +- type: DIFF_SUPPRESS_FUNC + details: + diffsuppressfunc: compareSelfLinkOrResourceName + field: backend_service +- type: CUSTOM_NAME + details: + name: metadata_filters + field: metadata_filter +- type: CUSTOM_NAME + details: + name: filter_labels + field: metadata_filter.filter_label +- type: EXCLUDE + field: location + location: global diff --git a/tpgtools/property.go b/tpgtools/property.go index f9f892bfff01..91866554fb82 100644 --- a/tpgtools/property.go +++ b/tpgtools/property.go @@ -71,6 +71,7 @@ type Property struct { ValidateFunc *string SetHashFunc *string MaxItems *int64 + MinItems *int64 ConfigMode *string Removed *string @@ -372,7 +373,7 @@ func (p Property) flattenGetterWithParent(parent string) string { func (p Property) DefaultValidator() *string { switch p.Type.String() { case SchemaTypeString: - if p.Type.IsEnum() && len(p.typ.Enum) > 0 && !p.Computed { + if p.Type.IsEnum() && len(p.typ.Enum) > 0 && p.Settable { enumValues := "" for _, v := range p.typ.Enum { enumValues += fmt.Sprintf(`"%s", `, v) @@ -515,8 +516,18 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher continue } - if v.Default != "" { - d, err := renderDefault(p.Type, v.Default) + do := CustomDefaultDetails{} + doOk, err := overrides.PropertyOverrideWithDetails(CustomDefault, p, &do, location) + if err != nil { + return nil, fmt.Errorf("failed to decode custom list size details") + } + + if v.Default != "" || doOk { + def := v.Default + if doOk { + def = do.Default + } + d, err := renderDefault(p.Type, def) if err != nil { return nil, fmt.Errorf("failed to render default: %v", err) } @@ -582,6 +593,20 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher // Handle array properties if v.Items != nil { + ls := CustomListSizeConstraintDetails{} + lsOk, err := overrides.PropertyOverrideWithDetails(CustomListSize, p, &ls, location) + if err != nil { + return nil, fmt.Errorf("failed to decode custom list size details") + } + if lsOk { + if ls.Max > 0 { + p.MaxItems = &ls.Max + } + if ls.Min > 0 { + p.MinItems = &ls.Min + } + } + // We end up handling arrays of objects very similarly to nested objects // themselves if len(v.Items.Properties) > 0 { @@ -612,6 +637,16 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher } else { p.Optional = true } + cr := CustomRequiredDetails{} + crOk, err := overrides.PropertyOverrideWithDetails(CustomRequired, p, &cr, location) + if err != nil { + return nil, fmt.Errorf("failed to decode custom required details") + } + if crOk { + p.Required = cr.Required + p.Optional = cr.Optional + p.Computed = cr.Computed + } p.Settable = true @@ -632,7 +667,7 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher // special handling for project/region/zone/other fields with // provider defaults - if stringInSlice(p.title, []string{"project", "region", "zone"}) { + if stringInSlice(p.title, []string{"project", "region", "zone"}) || stringInSlice(p.customName, []string{"region", "project", "zone"}) { p.Optional = true p.Required = false p.Computed = true @@ -646,7 +681,11 @@ func createPropertiesFromSchema(schema *openapi.Schema, typeFetcher *TypeFetcher return nil, fmt.Errorf("failed to decode custom identity getter details") } - ig := fmt.Sprintf("get%s(d, config)", p.PackageName) + capitalizedPropertyName := p.PackageName + if p.customName != "" { + capitalizedPropertyName = snakeToTitleCase(p.customName) + } + ig := fmt.Sprintf("get%s(d, config)", capitalizedPropertyName) if cigOk { ig = fmt.Sprintf("%s(d, config)", cig.Function) } diff --git a/tpgtools/serialization.go b/tpgtools/serialization.go index 1795032dd127..959f2737a4f5 100644 --- a/tpgtools/serialization.go +++ b/tpgtools/serialization.go @@ -51,6 +51,10 @@ func DCLToTerraformReference(resourceType, version string) (string, error) { return "google_compute_firewall_policy_association", nil case "ComputeFirewallPolicyRule": return "google_compute_firewall_policy_rule", nil + case "ComputeForwardingRule": + return "google_compute_forwarding_rule", nil + case "ComputeGlobalForwardingRule": + return "google_compute_global_forwarding_rule", nil case "DataprocWorkflowTemplate": return "google_dataproc_workflow_template", nil case "EventarcTrigger": @@ -73,6 +77,10 @@ func DCLToTerraformReference(resourceType, version string) (string, error) { return "google_compute_firewall_policy_association", nil case "ComputeFirewallPolicyRule": return "google_compute_firewall_policy_rule", nil + case "ComputeForwardingRule": + return "google_compute_forwarding_rule", nil + case "ComputeGlobalForwardingRule": + return "google_compute_global_forwarding_rule", nil case "DataprocWorkflowTemplate": return "google_dataproc_workflow_template", nil case "EventarcTrigger": @@ -119,6 +127,18 @@ func ConvertSampleJSONToHCL(resourceType string, version string, b []byte) (stri return "", err } return ComputeFirewallPolicyRuleBetaAsHCL(*r) + case "ComputeForwardingRule": + r := &computeBeta.ForwardingRule{} + if err := json.Unmarshal(b, r); err != nil { + return "", err + } + return ComputeForwardingRuleBetaAsHCL(*r) + case "ComputeGlobalForwardingRule": + r := &computeBeta.ForwardingRule{} + if err := json.Unmarshal(b, r); err != nil { + return "", err + } + return ComputeGlobalForwardingRuleBetaAsHCL(*r) case "DataprocWorkflowTemplate": r := &dataprocBeta.WorkflowTemplate{} if err := json.Unmarshal(b, r); err != nil { @@ -177,6 +197,18 @@ func ConvertSampleJSONToHCL(resourceType string, version string, b []byte) (stri return "", err } return ComputeFirewallPolicyRuleAsHCL(*r) + case "ComputeForwardingRule": + r := &compute.ForwardingRule{} + if err := json.Unmarshal(b, r); err != nil { + return "", err + } + return ComputeForwardingRuleAsHCL(*r) + case "ComputeGlobalForwardingRule": + r := &compute.ForwardingRule{} + if err := json.Unmarshal(b, r); err != nil { + return "", err + } + return ComputeGlobalForwardingRuleAsHCL(*r) case "DataprocWorkflowTemplate": r := &dataproc.WorkflowTemplate{} if err := json.Unmarshal(b, r); err != nil { @@ -463,6 +495,151 @@ func convertComputeFirewallPolicyRuleBetaMatchLayer4ConfigsToHCL(r *computeBeta. return outputConfig + "}" } +// ComputeForwardingRuleBetaAsHCL returns a string representation of the specified resource in HCL. +// The generated HCL will include every settable field as a literal - that is, no +// variables, no references. This may not be the best possible representation, but +// the crucial point is that `terraform import; terraform apply` will not produce +// any changes. We do not validate that the resource specified will pass terraform +// validation unless is an object returned from the API after an Apply. +func ComputeForwardingRuleBetaAsHCL(r computeBeta.ForwardingRule) (string, error) { + outputConfig := "resource \"google_compute_forwarding_rule\" \"output\" {\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.AllPorts != nil { + outputConfig += fmt.Sprintf("\tall_ports = %#v\n", *r.AllPorts) + } + if r.AllowGlobalAccess != nil { + outputConfig += fmt.Sprintf("\tallow_global_access = %#v\n", *r.AllowGlobalAccess) + } + if r.BackendService != nil { + outputConfig += fmt.Sprintf("\tbackend_service = %#v\n", *r.BackendService) + } + if r.Description != nil { + outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) + } + if r.IPAddress != nil { + outputConfig += fmt.Sprintf("\tip_address = %#v\n", *r.IPAddress) + } + if r.IPProtocol != nil { + outputConfig += fmt.Sprintf("\tip_protocol = %#v\n", *r.IPProtocol) + } + if r.IsMirroringCollector != nil { + outputConfig += fmt.Sprintf("\tis_mirroring_collector = %#v\n", *r.IsMirroringCollector) + } + if r.LoadBalancingScheme != nil { + outputConfig += fmt.Sprintf("\tload_balancing_scheme = %#v\n", *r.LoadBalancingScheme) + } + if r.Network != nil { + outputConfig += fmt.Sprintf("\tnetwork = %#v\n", *r.Network) + } + if r.NetworkTier != nil { + outputConfig += fmt.Sprintf("\tnetwork_tier = %#v\n", *r.NetworkTier) + } + if r.PortRange != nil { + outputConfig += fmt.Sprintf("\tport_range = %#v\n", *r.PortRange) + } + if r.Ports != nil { + outputConfig += "\tports = [" + for _, v := range r.Ports { + outputConfig += fmt.Sprintf("%#v, ", v) + } + outputConfig += "]\n" + } + if r.Project != nil { + outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) + } + if r.Location != nil { + outputConfig += fmt.Sprintf("\tregion = %#v\n", *r.Location) + } + if r.ServiceLabel != nil { + outputConfig += fmt.Sprintf("\tservice_label = %#v\n", *r.ServiceLabel) + } + if r.Subnetwork != nil { + outputConfig += fmt.Sprintf("\tsubnetwork = %#v\n", *r.Subnetwork) + } + if r.Target != nil { + outputConfig += fmt.Sprintf("\ttarget = %#v\n", *r.Target) + } + return formatHCL(outputConfig + "}") +} + +// ComputeGlobalForwardingRuleBetaAsHCL returns a string representation of the specified resource in HCL. +// The generated HCL will include every settable field as a literal - that is, no +// variables, no references. This may not be the best possible representation, but +// the crucial point is that `terraform import; terraform apply` will not produce +// any changes. We do not validate that the resource specified will pass terraform +// validation unless is an object returned from the API after an Apply. +func ComputeGlobalForwardingRuleBetaAsHCL(r computeBeta.ForwardingRule) (string, error) { + outputConfig := "resource \"google_compute_global_forwarding_rule\" \"output\" {\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.Target != nil { + outputConfig += fmt.Sprintf("\ttarget = %#v\n", *r.Target) + } + if r.Description != nil { + outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) + } + if r.IPAddress != nil { + outputConfig += fmt.Sprintf("\tip_address = %#v\n", *r.IPAddress) + } + if r.IPProtocol != nil { + outputConfig += fmt.Sprintf("\tip_protocol = %#v\n", *r.IPProtocol) + } + if r.IPVersion != nil { + outputConfig += fmt.Sprintf("\tip_version = %#v\n", *r.IPVersion) + } + if r.LoadBalancingScheme != nil { + outputConfig += fmt.Sprintf("\tload_balancing_scheme = %#v\n", *r.LoadBalancingScheme) + } + if r.MetadataFilter != nil { + for _, v := range r.MetadataFilter { + outputConfig += fmt.Sprintf("\tmetadata_filters %s\n", convertComputeGlobalForwardingRuleBetaMetadataFilterToHCL(&v)) + } + } + if r.Network != nil { + outputConfig += fmt.Sprintf("\tnetwork = %#v\n", *r.Network) + } + if r.PortRange != nil { + outputConfig += fmt.Sprintf("\tport_range = %#v\n", *r.PortRange) + } + if r.Project != nil { + outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) + } + return formatHCL(outputConfig + "}") +} + +func convertComputeGlobalForwardingRuleBetaMetadataFilterToHCL(r *computeBeta.ForwardingRuleMetadataFilter) string { + if r == nil { + return "" + } + outputConfig := "{\n" + if r.FilterLabel != nil { + for _, v := range r.FilterLabel { + outputConfig += fmt.Sprintf("\tfilter_labels %s\n", convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabelToHCL(&v)) + } + } + if r.FilterMatchCriteria != nil { + outputConfig += fmt.Sprintf("\tfilter_match_criteria = %#v\n", *r.FilterMatchCriteria) + } + return outputConfig + "}" +} + +func convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabelToHCL(r *computeBeta.ForwardingRuleMetadataFilterFilterLabel) string { + if r == nil { + return "" + } + outputConfig := "{\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.Value != nil { + outputConfig += fmt.Sprintf("\tvalue = %#v\n", *r.Value) + } + return outputConfig + "}" +} + // DataprocWorkflowTemplateBetaAsHCL returns a string representation of the specified resource in HCL. // The generated HCL will include every settable field as a literal - that is, no // variables, no references. This may not be the best possible representation, but @@ -2232,6 +2409,151 @@ func convertComputeFirewallPolicyRuleMatchLayer4ConfigsToHCL(r *compute.Firewall return outputConfig + "}" } +// ComputeForwardingRuleAsHCL returns a string representation of the specified resource in HCL. +// The generated HCL will include every settable field as a literal - that is, no +// variables, no references. This may not be the best possible representation, but +// the crucial point is that `terraform import; terraform apply` will not produce +// any changes. We do not validate that the resource specified will pass terraform +// validation unless is an object returned from the API after an Apply. +func ComputeForwardingRuleAsHCL(r compute.ForwardingRule) (string, error) { + outputConfig := "resource \"google_compute_forwarding_rule\" \"output\" {\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.AllPorts != nil { + outputConfig += fmt.Sprintf("\tall_ports = %#v\n", *r.AllPorts) + } + if r.AllowGlobalAccess != nil { + outputConfig += fmt.Sprintf("\tallow_global_access = %#v\n", *r.AllowGlobalAccess) + } + if r.BackendService != nil { + outputConfig += fmt.Sprintf("\tbackend_service = %#v\n", *r.BackendService) + } + if r.Description != nil { + outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) + } + if r.IPAddress != nil { + outputConfig += fmt.Sprintf("\tip_address = %#v\n", *r.IPAddress) + } + if r.IPProtocol != nil { + outputConfig += fmt.Sprintf("\tip_protocol = %#v\n", *r.IPProtocol) + } + if r.IsMirroringCollector != nil { + outputConfig += fmt.Sprintf("\tis_mirroring_collector = %#v\n", *r.IsMirroringCollector) + } + if r.LoadBalancingScheme != nil { + outputConfig += fmt.Sprintf("\tload_balancing_scheme = %#v\n", *r.LoadBalancingScheme) + } + if r.Network != nil { + outputConfig += fmt.Sprintf("\tnetwork = %#v\n", *r.Network) + } + if r.NetworkTier != nil { + outputConfig += fmt.Sprintf("\tnetwork_tier = %#v\n", *r.NetworkTier) + } + if r.PortRange != nil { + outputConfig += fmt.Sprintf("\tport_range = %#v\n", *r.PortRange) + } + if r.Ports != nil { + outputConfig += "\tports = [" + for _, v := range r.Ports { + outputConfig += fmt.Sprintf("%#v, ", v) + } + outputConfig += "]\n" + } + if r.Project != nil { + outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) + } + if r.Location != nil { + outputConfig += fmt.Sprintf("\tregion = %#v\n", *r.Location) + } + if r.ServiceLabel != nil { + outputConfig += fmt.Sprintf("\tservice_label = %#v\n", *r.ServiceLabel) + } + if r.Subnetwork != nil { + outputConfig += fmt.Sprintf("\tsubnetwork = %#v\n", *r.Subnetwork) + } + if r.Target != nil { + outputConfig += fmt.Sprintf("\ttarget = %#v\n", *r.Target) + } + return formatHCL(outputConfig + "}") +} + +// ComputeGlobalForwardingRuleAsHCL returns a string representation of the specified resource in HCL. +// The generated HCL will include every settable field as a literal - that is, no +// variables, no references. This may not be the best possible representation, but +// the crucial point is that `terraform import; terraform apply` will not produce +// any changes. We do not validate that the resource specified will pass terraform +// validation unless is an object returned from the API after an Apply. +func ComputeGlobalForwardingRuleAsHCL(r compute.ForwardingRule) (string, error) { + outputConfig := "resource \"google_compute_global_forwarding_rule\" \"output\" {\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.Target != nil { + outputConfig += fmt.Sprintf("\ttarget = %#v\n", *r.Target) + } + if r.Description != nil { + outputConfig += fmt.Sprintf("\tdescription = %#v\n", *r.Description) + } + if r.IPAddress != nil { + outputConfig += fmt.Sprintf("\tip_address = %#v\n", *r.IPAddress) + } + if r.IPProtocol != nil { + outputConfig += fmt.Sprintf("\tip_protocol = %#v\n", *r.IPProtocol) + } + if r.IPVersion != nil { + outputConfig += fmt.Sprintf("\tip_version = %#v\n", *r.IPVersion) + } + if r.LoadBalancingScheme != nil { + outputConfig += fmt.Sprintf("\tload_balancing_scheme = %#v\n", *r.LoadBalancingScheme) + } + if r.MetadataFilter != nil { + for _, v := range r.MetadataFilter { + outputConfig += fmt.Sprintf("\tmetadata_filters %s\n", convertComputeGlobalForwardingRuleMetadataFilterToHCL(&v)) + } + } + if r.Network != nil { + outputConfig += fmt.Sprintf("\tnetwork = %#v\n", *r.Network) + } + if r.PortRange != nil { + outputConfig += fmt.Sprintf("\tport_range = %#v\n", *r.PortRange) + } + if r.Project != nil { + outputConfig += fmt.Sprintf("\tproject = %#v\n", *r.Project) + } + return formatHCL(outputConfig + "}") +} + +func convertComputeGlobalForwardingRuleMetadataFilterToHCL(r *compute.ForwardingRuleMetadataFilter) string { + if r == nil { + return "" + } + outputConfig := "{\n" + if r.FilterLabel != nil { + for _, v := range r.FilterLabel { + outputConfig += fmt.Sprintf("\tfilter_labels %s\n", convertComputeGlobalForwardingRuleMetadataFilterFilterLabelToHCL(&v)) + } + } + if r.FilterMatchCriteria != nil { + outputConfig += fmt.Sprintf("\tfilter_match_criteria = %#v\n", *r.FilterMatchCriteria) + } + return outputConfig + "}" +} + +func convertComputeGlobalForwardingRuleMetadataFilterFilterLabelToHCL(r *compute.ForwardingRuleMetadataFilterFilterLabel) string { + if r == nil { + return "" + } + outputConfig := "{\n" + if r.Name != nil { + outputConfig += fmt.Sprintf("\tname = %#v\n", *r.Name) + } + if r.Value != nil { + outputConfig += fmt.Sprintf("\tvalue = %#v\n", *r.Value) + } + return outputConfig + "}" +} + // DataprocWorkflowTemplateAsHCL returns a string representation of the specified resource in HCL. // The generated HCL will include every settable field as a literal - that is, no // variables, no references. This may not be the best possible representation, but @@ -3712,6 +4034,50 @@ func convertComputeFirewallPolicyRuleBetaMatchLayer4ConfigsList(i interface{}) ( return out } +func convertComputeGlobalForwardingRuleBetaMetadataFilter(i interface{}) map[string]interface{} { + if i == nil { + return nil + } + in := i.(map[string]interface{}) + return map[string]interface{}{ + "filterLabel": in["filter_labels"], + "filterMatchCriteria": in["filter_match_criteria"], + } +} + +func convertComputeGlobalForwardingRuleBetaMetadataFilterList(i interface{}) (out []map[string]interface{}) { + if i == nil { + return nil + } + + for _, v := range i.([]interface{}) { + out = append(out, convertComputeGlobalForwardingRuleBetaMetadataFilter(v)) + } + return out +} + +func convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabel(i interface{}) map[string]interface{} { + if i == nil { + return nil + } + in := i.(map[string]interface{}) + return map[string]interface{}{ + "name": in["name"], + "value": in["value"], + } +} + +func convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabelList(i interface{}) (out []map[string]interface{}) { + if i == nil { + return nil + } + + for _, v := range i.([]interface{}) { + out = append(out, convertComputeGlobalForwardingRuleBetaMetadataFilterFilterLabel(v)) + } + return out +} + func convertDataprocWorkflowTemplateBetaJobs(i interface{}) map[string]interface{} { if i == nil { return nil @@ -5534,6 +5900,50 @@ func convertComputeFirewallPolicyRuleMatchLayer4ConfigsList(i interface{}) (out return out } +func convertComputeGlobalForwardingRuleMetadataFilter(i interface{}) map[string]interface{} { + if i == nil { + return nil + } + in := i.(map[string]interface{}) + return map[string]interface{}{ + "filterLabel": in["filter_labels"], + "filterMatchCriteria": in["filter_match_criteria"], + } +} + +func convertComputeGlobalForwardingRuleMetadataFilterList(i interface{}) (out []map[string]interface{}) { + if i == nil { + return nil + } + + for _, v := range i.([]interface{}) { + out = append(out, convertComputeGlobalForwardingRuleMetadataFilter(v)) + } + return out +} + +func convertComputeGlobalForwardingRuleMetadataFilterFilterLabel(i interface{}) map[string]interface{} { + if i == nil { + return nil + } + in := i.(map[string]interface{}) + return map[string]interface{}{ + "name": in["name"], + "value": in["value"], + } +} + +func convertComputeGlobalForwardingRuleMetadataFilterFilterLabelList(i interface{}) (out []map[string]interface{}) { + if i == nil { + return nil + } + + for _, v := range i.([]interface{}) { + out = append(out, convertComputeGlobalForwardingRuleMetadataFilterFilterLabel(v)) + } + return out +} + func convertDataprocWorkflowTemplateJobs(i interface{}) map[string]interface{} { if i == nil { return nil diff --git a/tpgtools/templates/resource.go.tmpl b/tpgtools/templates/resource.go.tmpl index c95749fa1200..1604058174c0 100644 --- a/tpgtools/templates/resource.go.tmpl +++ b/tpgtools/templates/resource.go.tmpl @@ -102,6 +102,9 @@ func resource{{$.PathType}}() *schema.Resource { {{- if $p.MaxItems }} MaxItems: {{$p.MaxItems}}, {{- end }} + {{- if $p.MinItems }} + MinItems: {{$p.MinItems}}, + {{- end }} {{- if $p.Elem }} Elem: {{$p.Elem}}, {{- end }} @@ -162,6 +165,9 @@ func {{$.PathType}}{{$v.PackagePath}}Schema() *schema.Resource { {{- if $p.MaxItems }} MaxItems: {{$p.MaxItems}}, {{- end }} + {{- if $p.MinItems }} + MinItems: {{$p.MinItems}}, + {{- end }} {{- if $p.Elem }} Elem: {{$p.Elem}}, {{- end }}