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

Remove beta-only label fields from GA Compute VpnTunnel #3277

Merged
merged 1 commit into from
Mar 20, 2019
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
108 changes: 0 additions & 108 deletions google/resource_compute_vpn_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ func resourceComputeVpnTunnel() *schema.Resource {
return &schema.Resource{
Create: resourceComputeVpnTunnelCreate,
Read: resourceComputeVpnTunnelRead,
Update: resourceComputeVpnTunnelUpdate,
Delete: resourceComputeVpnTunnelDelete,

Importer: &schema.ResourceImporter{
Expand All @@ -142,7 +141,6 @@ func resourceComputeVpnTunnel() *schema.Resource {

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(240 * time.Second),
Update: schema.DefaultTimeout(240 * time.Second),
Delete: schema.DefaultTimeout(240 * time.Second),
},

Expand Down Expand Up @@ -181,11 +179,6 @@ func resourceComputeVpnTunnel() *schema.Resource {
ForceNew: true,
Default: 2,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"local_traffic_selector": {
Type: schema.TypeSet,
Computed: true,
Expand Down Expand Up @@ -227,10 +220,6 @@ func resourceComputeVpnTunnel() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"label_fingerprint": {
Type: schema.TypeString,
Computed: true,
},
"shared_secret_hash": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -307,18 +296,6 @@ func resourceComputeVpnTunnelCreate(d *schema.ResourceData, meta interface{}) er
} else if v, ok := d.GetOkExists("remote_traffic_selector"); !isEmptyValue(reflect.ValueOf(remoteTrafficSelectorProp)) && (ok || !reflect.DeepEqual(v, remoteTrafficSelectorProp)) {
obj["remoteTrafficSelector"] = remoteTrafficSelectorProp
}
labelsProp, err := expandComputeVpnTunnelLabels(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
}
labelFingerprintProp, err := expandComputeVpnTunnelLabelFingerprint(d.Get("label_fingerprint"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("label_fingerprint"); !isEmptyValue(reflect.ValueOf(labelFingerprintProp)) && (ok || !reflect.DeepEqual(v, labelFingerprintProp)) {
obj["labelFingerprint"] = labelFingerprintProp
}
regionProp, err := expandComputeVpnTunnelRegion(d.Get("region"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -425,12 +402,6 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro
if err := d.Set("remote_traffic_selector", flattenComputeVpnTunnelRemoteTrafficSelector(res["remoteTrafficSelector"], d)); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("labels", flattenComputeVpnTunnelLabels(res["labels"], d)); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("label_fingerprint", flattenComputeVpnTunnelLabelFingerprint(res["labelFingerprint"], d)); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
if err := d.Set("detailed_status", flattenComputeVpnTunnelDetailedStatus(res["detailedStatus"], d)); err != nil {
return fmt.Errorf("Error reading VpnTunnel: %s", err)
}
Expand All @@ -444,62 +415,6 @@ func resourceComputeVpnTunnelRead(d *schema.ResourceData, meta interface{}) erro
return nil
}

func resourceComputeVpnTunnelUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

d.Partial(true)

if d.HasChange("labels") || d.HasChange("label_fingerprint") {
obj := make(map[string]interface{})
labelsProp, err := expandComputeVpnTunnelLabels(d.Get("labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("labels"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
labelFingerprintProp, err := expandComputeVpnTunnelLabelFingerprint(d.Get("label_fingerprint"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("label_fingerprint"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, labelFingerprintProp)) {
obj["labelFingerprint"] = labelFingerprintProp
}

url, err := replaceVars(d, config, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/vpnTunnels/{{name}}/setLabels")
if err != nil {
return err
}
res, err := sendRequestWithTimeout(config, "POST", url, obj, d.Timeout(schema.TimeoutUpdate))
if err != nil {
return fmt.Errorf("Error updating VpnTunnel %q: %s", d.Id(), err)
}

project, err := getProject(d, config)
if err != nil {
return err
}
op := &compute.Operation{}
err = Convert(res, op)
if err != nil {
return err
}

err = computeOperationWaitTime(
config.clientCompute, op, project, "Updating VpnTunnel",
int(d.Timeout(schema.TimeoutUpdate).Minutes()))

if err != nil {
return err
}

d.SetPartial("labels")
d.SetPartial("label_fingerprint")
}

d.Partial(false)

return resourceComputeVpnTunnelRead(d, meta)
}

func resourceComputeVpnTunnelDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)

Expand Down Expand Up @@ -611,14 +526,6 @@ func flattenComputeVpnTunnelRemoteTrafficSelector(v interface{}, d *schema.Resou
return schema.NewSet(schema.HashString, v.([]interface{}))
}

func flattenComputeVpnTunnelLabels(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeVpnTunnelLabelFingerprint(v interface{}, d *schema.ResourceData) interface{} {
return v
}

func flattenComputeVpnTunnelDetailedStatus(v interface{}, d *schema.ResourceData) interface{} {
return v
}
Expand Down Expand Up @@ -679,21 +586,6 @@ func expandComputeVpnTunnelRemoteTrafficSelector(v interface{}, d TerraformResou
return v, nil
}

func expandComputeVpnTunnelLabels(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 expandComputeVpnTunnelLabelFingerprint(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
return v, nil
}

func expandComputeVpnTunnelRegion(v interface{}, d TerraformResourceData, config *Config) (interface{}, error) {
f, err := parseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
Expand Down
94 changes: 85 additions & 9 deletions website/docs/r/compute_vpn_tunnel.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,91 @@ resource "google_compute_route" "route1" {
next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}"
}
```
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgit.luolix.top%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=vpn_tunnel_beta&cloudshell_image=gcr.io%2Fgraphite-cloud-shell-images%2Fterraform%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
</a>
</div>
## Example Usage - Vpn Tunnel Beta


```hcl
resource "google_compute_vpn_tunnel" "tunnel1" {
provider = "google-beta"
name = "tunnel1"
peer_ip = "15.0.0.120"
shared_secret = "a secret message"

target_vpn_gateway = "${google_compute_vpn_gateway.target_gateway.self_link}"

depends_on = [
"google_compute_forwarding_rule.fr_esp",
"google_compute_forwarding_rule.fr_udp500",
"google_compute_forwarding_rule.fr_udp4500",
]

labels {
foo = "bar"
}
}

resource "google_compute_vpn_gateway" "target_gateway" {
provider = "google-beta"
name = "vpn1"
network = "${google_compute_network.network1.self_link}"
}

resource "google_compute_network" "network1" {
provider = "google-beta"
name = "network1"
}

resource "google_compute_address" "vpn_static_ip" {
provider = "google-beta"
name = "vpn-static-ip"
}

resource "google_compute_forwarding_rule" "fr_esp" {
provider = "google-beta"
name = "fr-esp"
ip_protocol = "ESP"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}

resource "google_compute_forwarding_rule" "fr_udp500" {
provider = "google-beta"
name = "fr-udp500"
ip_protocol = "UDP"
port_range = "500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}

resource "google_compute_forwarding_rule" "fr_udp4500" {
provider = "google-beta"
name = "fr-udp4500"
ip_protocol = "UDP"
port_range = "4500"
ip_address = "${google_compute_address.vpn_static_ip.address}"
target = "${google_compute_vpn_gateway.target_gateway.self_link}"
}

resource "google_compute_route" "route1" {
provider = "google-beta"
name = "route1"
network = "${google_compute_network.network1.name}"
dest_range = "15.0.0.0/24"
priority = 1000

next_hop_vpn_tunnel = "${google_compute_vpn_tunnel.tunnel1.self_link}"
}

provider "google-beta"{
region = "us-central1"
zone = "us-central1-a"
}
```

## Argument Reference

Expand Down Expand Up @@ -165,10 +250,6 @@ The following arguments are supported:
for example `192.168.0.0/16`. The ranges should be disjoint.
Only IPv4 is supported.

* `labels` -
(Optional)
Labels to apply to this VpnTunnel.

* `region` -
(Optional)
The region where the tunnel is located. If unset, is set to the region of `target_vpn_gateway`.
Expand All @@ -187,10 +268,6 @@ In addition to the arguments listed above, the following computed attributes are
* `shared_secret_hash` -
Hash of the shared secret.

* `label_fingerprint` -
The fingerprint used for optimistic locking of this resource. Used
internally during updates.

* `detailed_status` -
Detailed status message for the VPN tunnel.
* `self_link` - The URI of the created resource.
Expand All @@ -202,7 +279,6 @@ This resource provides the following
[Timeouts](/docs/configuration/resources.html#timeouts) configuration options:

- `create` - Default is 4 minutes.
- `update` - Default is 4 minutes.
- `delete` - Default is 4 minutes.

## Import
Expand Down