-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3213 from lwander/f-gce-vpn
provider/gce: VPN resources, documentation, tests and example
- Loading branch information
Showing
17 changed files
with
1,011 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
builtin/providers/google/resource_compute_vpn_gateway.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package google | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
|
||
"google.golang.org/api/compute/v1" | ||
) | ||
|
||
func resourceComputeVpnGateway() *schema.Resource { | ||
return &schema.Resource{ | ||
// Unfortunately, the VPNGatewayService does not support update | ||
// operations. This is why everything is marked forcenew | ||
Create: resourceComputeVpnGatewayCreate, | ||
Read: resourceComputeVpnGatewayRead, | ||
Delete: resourceComputeVpnGatewayDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"description": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"network": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
}, | ||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
"self_link": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceComputeVpnGatewayCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
name := d.Get("name").(string) | ||
network := d.Get("network").(string) | ||
region := getOptionalRegion(d, config) | ||
project := config.Project | ||
|
||
vpnGatewaysService := compute.NewTargetVpnGatewaysService(config.clientCompute) | ||
|
||
vpnGateway := &compute.TargetVpnGateway{ | ||
Name: name, | ||
Network: network, | ||
} | ||
|
||
if v, ok := d.GetOk("description"); ok { | ||
vpnGateway.Description = v.(string) | ||
} | ||
|
||
op, err := vpnGatewaysService.Insert(project, region, vpnGateway).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error Inserting VPN Gateway %s into network %s: %s", name, network, err) | ||
} | ||
|
||
err = resourceOperationWaitRegion(config, op, region, "Inserting VPN Gateway") | ||
if err != nil { | ||
return fmt.Errorf("Error Waiting to Insert VPN Gateway %s into network %s: %s", name, network, err) | ||
} | ||
|
||
return resourceComputeVpnGatewayRead(d, meta) | ||
} | ||
|
||
func resourceComputeVpnGatewayRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
name := d.Get("name").(string) | ||
region := d.Get("region").(string) | ||
project := config.Project | ||
|
||
vpnGatewaysService := compute.NewTargetVpnGatewaysService(config.clientCompute) | ||
vpnGateway, err := vpnGatewaysService.Get(project, region, name).Do() | ||
|
||
if err != nil { | ||
return fmt.Errorf("Error Reading VPN Gateway %s: %s", name, err) | ||
} | ||
|
||
d.Set("self_link", vpnGateway.SelfLink) | ||
d.SetId(name) | ||
|
||
return nil | ||
} | ||
|
||
func resourceComputeVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
name := d.Get("name").(string) | ||
region := d.Get("region").(string) | ||
project := config.Project | ||
|
||
vpnGatewaysService := compute.NewTargetVpnGatewaysService(config.clientCompute) | ||
|
||
op, err := vpnGatewaysService.Delete(project, region, name).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error Reading VPN Gateway %s: %s", name, err) | ||
} | ||
|
||
err = resourceOperationWaitRegion(config, op, region, "Deleting VPN Gateway") | ||
if err != nil { | ||
return fmt.Errorf("Error Waiting to Delete VPN Gateway %s: %s", name, err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.