Skip to content

Commit

Permalink
Added support for labels field in the google_compute_external_vpn_gat…
Browse files Browse the repository at this point in the history
…eway (#7053) (#13642)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Feb 2, 2023
1 parent 867ae23 commit ae54361
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/7053.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added the `labels` field to the `google_compute_external_vpn_gateway` resource
```
31 changes: 31 additions & 0 deletions google/resource_compute_external_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ it cannot be an IP address from Google Compute Engine.`,
},
},
},
"labels": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Description: `Labels for the external VPN gateway resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"redundancy_type": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -122,6 +129,12 @@ func resourceComputeExternalVpnGatewayCreate(d *schema.ResourceData, meta interf
} else if v, ok := d.GetOkExists("description"); !isEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
labelsProp, err := expandComputeExternalVpnGatewayLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
nameProp, err := expandComputeExternalVpnGatewayName(d.Get("name"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -224,6 +237,9 @@ func resourceComputeExternalVpnGatewayRead(d *schema.ResourceData, meta interfac
if err := d.Set("description", flattenComputeExternalVpnGatewayDescription(res["description"], d, config)); err != nil {
return fmt.Errorf("Error reading ExternalVpnGateway: %s", err)
}
if err := d.Set("labels", flattenComputeExternalVpnGatewayLabels(res["labels"], d, config)); err != nil {
return fmt.Errorf("Error reading ExternalVpnGateway: %s", err)
}
if err := d.Set("name", flattenComputeExternalVpnGatewayName(res["name"], d, config)); err != nil {
return fmt.Errorf("Error reading ExternalVpnGateway: %s", err)
}
Expand Down Expand Up @@ -309,6 +325,10 @@ func flattenComputeExternalVpnGatewayDescription(v interface{}, d *schema.Resour
return v
}

func flattenComputeExternalVpnGatewayLabels(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}

func flattenComputeExternalVpnGatewayName(v interface{}, d *schema.ResourceData, config *Config) interface{} {
return v
}
Expand Down Expand Up @@ -361,6 +381,17 @@ func expandComputeExternalVpnGatewayDescription(v interface{}, d TerraformResour
return v, nil
}

func expandComputeExternalVpnGatewayLabels(v interface{}, d TerraformResourceData, config *Config) (map[string]string, error) {
if v == nil {
return map[string]string{}, nil
}
m := make(map[string]string)
for k, val := range v.(map[string]interface{}) {
m[k] = val.(string)
}
return m, nil
}

func expandComputeExternalVpnGatewayName(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}
Expand Down
42 changes: 42 additions & 0 deletions google/resource_compute_external_vpn_gateway_generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,48 @@ resource "google_compute_router_peer" "router1_peer2" {
`, context)
}

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

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

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckComputeExternalVpnGatewayDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeExternalVpnGateway_onlyExternalVpnGatewayFullExample(context),
},
{
ResourceName: "google_compute_external_vpn_gateway.external_gateway",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccComputeExternalVpnGateway_onlyExternalVpnGatewayFullExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_compute_external_vpn_gateway" "external_gateway" {
name = "tf-test-external-gateway%{random_suffix}"
redundancy_type = "SINGLE_IP_INTERNALLY_REDUNDANT"
description = "An externally managed VPN gateway"
interface {
id = 0
ip_address = "8.8.8.8"
}
labels = {
key = "value"
otherkey = ""
}
}
`, context)
}

func testAccCheckComputeExternalVpnGatewayDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/compute_external_vpn_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ The following arguments are supported:
(Optional)
An optional description of this resource.

* `labels` -
(Optional)
Labels for the external VPN gateway resource.

* `redundancy_type` -
(Optional)
Indicates the redundancy type of this external VPN gateway
Expand Down

0 comments on commit ae54361

Please sign in to comment.