Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add serviceDirectoryRegistrations message to resource google_compute_global_forwarding_rule #16581

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/9485.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added field `service_directory_registrations` to resource `google_compute_global_forwarding_rule`
```
104 changes: 104 additions & 0 deletions google/services/compute/resource_compute_global_forwarding_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
23 changes: 23 additions & 0 deletions website/docs/r/compute_global_forwarding_rule.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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.

<a name="nested_service_directory_registrations"></a>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:
Expand Down