diff --git a/.changelog/9485.txt b/.changelog/9485.txt new file mode 100644 index 00000000000..d5b696167b6 --- /dev/null +++ b/.changelog/9485.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +compute: added field `service_directory_registrations` to resource `google_compute_global_forwarding_rule` +``` diff --git a/google/services/compute/resource_compute_global_forwarding_rule.go b/google/services/compute/resource_compute_global_forwarding_rule.go index a46dba2e286..77bc66d50dd 100644 --- a/google/services/compute/resource_compute_global_forwarding_rule.go +++ b/google/services/compute/resource_compute_global_forwarding_rule.go @@ -308,6 +308,37 @@ cannot have overlapping 'portRange's. @pattern: \d+(?:-\d+)?`, }, + "service_directory_registrations": { + Type: schema.TypeList, + Computed: true, + Optional: true, + ForceNew: true, + Description: `Service Directory resources to register this forwarding rule with. + +Currently, only supports a single Service Directory resource.`, + MinItems: 0, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "namespace": { + Type: schema.TypeString, + Computed: true, + Optional: true, + ForceNew: true, + Description: `Service Directory namespace to register the forwarding rule under.`, + }, + "service_directory_region": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + Description: `[Optional] Service Directory region to register this global forwarding rule under. +Default to "us-central1". Only used for PSC for Google APIs. All PSC for +Google APIs Forwarding Rules on the same network should use the same Service +Directory region.`, + }, + }, + }, + }, "source_ip_ranges": { Type: schema.TypeList, Optional: true, @@ -460,6 +491,12 @@ func resourceComputeGlobalForwardingRuleCreate(d *schema.ResourceData, meta inte } else if v, ok := d.GetOkExists("target"); !tpgresource.IsEmptyValue(reflect.ValueOf(targetProp)) && (ok || !reflect.DeepEqual(v, targetProp)) { obj["target"] = targetProp } + serviceDirectoryRegistrationsProp, err := expandComputeGlobalForwardingRuleServiceDirectoryRegistrations(d.Get("service_directory_registrations"), d, config) + if err != nil { + return err + } else if v, ok := d.GetOkExists("service_directory_registrations"); !tpgresource.IsEmptyValue(reflect.ValueOf(serviceDirectoryRegistrationsProp)) && (ok || !reflect.DeepEqual(v, serviceDirectoryRegistrationsProp)) { + obj["serviceDirectoryRegistrations"] = serviceDirectoryRegistrationsProp + } sourceIpRangesProp, err := expandComputeGlobalForwardingRuleSourceIpRanges(d.Get("source_ip_ranges"), d, config) if err != nil { return err @@ -681,6 +718,9 @@ func resourceComputeGlobalForwardingRuleRead(d *schema.ResourceData, meta interf if err := d.Set("target", flattenComputeGlobalForwardingRuleTarget(res["target"], d, config)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } + if err := d.Set("service_directory_registrations", flattenComputeGlobalForwardingRuleServiceDirectoryRegistrations(res["serviceDirectoryRegistrations"], d, config)); err != nil { + return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) + } if err := d.Set("source_ip_ranges", flattenComputeGlobalForwardingRuleSourceIpRanges(res["sourceIpRanges"], d, config)); err != nil { return fmt.Errorf("Error reading GlobalForwardingRule: %s", err) } @@ -1013,6 +1053,33 @@ func flattenComputeGlobalForwardingRuleTarget(v interface{}, d *schema.ResourceD return v } +func flattenComputeGlobalForwardingRuleServiceDirectoryRegistrations(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + if v == nil { + return v + } + l := v.([]interface{}) + transformed := make([]interface{}, 0, len(l)) + for _, raw := range l { + original := raw.(map[string]interface{}) + if len(original) < 1 { + // Do not include empty json objects coming back from the api + continue + } + transformed = append(transformed, map[string]interface{}{ + "namespace": flattenComputeGlobalForwardingRuleServiceDirectoryRegistrationsNamespace(original["namespace"], d, config), + "service_directory_region": flattenComputeGlobalForwardingRuleServiceDirectoryRegistrationsServiceDirectoryRegion(original["serviceDirectoryRegion"], d, config), + }) + } + return transformed +} +func flattenComputeGlobalForwardingRuleServiceDirectoryRegistrationsNamespace(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + +func flattenComputeGlobalForwardingRuleServiceDirectoryRegistrationsServiceDirectoryRegion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenComputeGlobalForwardingRuleSourceIpRanges(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } @@ -1162,6 +1229,43 @@ func expandComputeGlobalForwardingRuleTarget(v interface{}, d tpgresource.Terraf return v, nil } +func expandComputeGlobalForwardingRuleServiceDirectoryRegistrations(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + l := v.([]interface{}) + req := make([]interface{}, 0, len(l)) + for _, raw := range l { + if raw == nil { + continue + } + original := raw.(map[string]interface{}) + transformed := make(map[string]interface{}) + + transformedNamespace, err := expandComputeGlobalForwardingRuleServiceDirectoryRegistrationsNamespace(original["namespace"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedNamespace); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["namespace"] = transformedNamespace + } + + transformedServiceDirectoryRegion, err := expandComputeGlobalForwardingRuleServiceDirectoryRegistrationsServiceDirectoryRegion(original["service_directory_region"], d, config) + if err != nil { + return nil, err + } else if val := reflect.ValueOf(transformedServiceDirectoryRegion); val.IsValid() && !tpgresource.IsEmptyValue(val) { + transformed["serviceDirectoryRegion"] = transformedServiceDirectoryRegion + } + + req = append(req, transformed) + } + return req, nil +} + +func expandComputeGlobalForwardingRuleServiceDirectoryRegistrationsNamespace(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + +func expandComputeGlobalForwardingRuleServiceDirectoryRegistrationsServiceDirectoryRegion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { + return v, nil +} + func expandComputeGlobalForwardingRuleSourceIpRanges(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) { return v, nil } diff --git a/website/docs/r/compute_global_forwarding_rule.html.markdown b/website/docs/r/compute_global_forwarding_rule.html.markdown index 88f3f0c9409..2de7959c16f 100644 --- a/website/docs/r/compute_global_forwarding_rule.html.markdown +++ b/website/docs/r/compute_global_forwarding_rule.html.markdown @@ -1135,6 +1135,10 @@ resource "google_compute_global_forwarding_rule" "default" { network = google_compute_network.network.id ip_address = google_compute_global_address.default.id load_balancing_scheme = "" + service_directory_registrations { + namespace = "sd-namespace" + service_directory_region = "europe-west3" + } } ``` ## Example Usage - Private Service Connect Google Apis No Automate Dns @@ -1348,6 +1352,12 @@ The following arguments are supported: However, a subnetwork must be specified if the network is in custom subnet mode or when creating external forwarding rule with IPv6. +* `service_directory_registrations` - + (Optional) + Service Directory resources to register this forwarding rule with. + Currently, only supports a single Service Directory resource. + Structure is [documented below](#nested_service_directory_registrations). + * `source_ip_ranges` - (Optional) If not empty, this Forwarding Rule will only forward the traffic when the source IP address matches one of the IP addresses or CIDR ranges set here. Note that a Forwarding Rule can only have up to 64 source IP ranges, and this field can only be used with a regional Forwarding Rule whose scheme is EXTERNAL. Each sourceIpRange entry should be either an IP address (for example, 1.2.3.4) or a CIDR range (for example, 1.2.3.0/24). @@ -1396,6 +1406,19 @@ The following arguments are supported: The value that the label must match. The value has a maximum length of 1024 characters. +The `service_directory_registrations` block supports: + +* `namespace` - + (Optional) + Service Directory namespace to register the forwarding rule under. + +* `service_directory_region` - + (Optional) + [Optional] Service Directory region to register this global forwarding rule under. + Default to "us-central1". Only used for PSC for Google APIs. All PSC for + Google APIs Forwarding Rules on the same network should use the same Service + Directory region. + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are exported: