-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/gce: VPN resources, documentation, tests and example #3213
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,18 +32,32 @@ func resourceComputeAddress() *schema.Resource { | |
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"region": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
ForceNew: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func getOptionalRegion(d *schema.ResourceData, config *Config) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wish we could just use this as |
||
if res, ok := d.GetOk("region"); !ok { | ||
return config.Region | ||
} else { | ||
return res.(string) | ||
} | ||
} | ||
|
||
func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
region := getOptionalRegion(d, config) | ||
|
||
// Build the address parameter | ||
addr := &compute.Address{Name: d.Get("name").(string)} | ||
log.Printf("[DEBUG] Address insert request: %#v", addr) | ||
op, err := config.clientCompute.Addresses.Insert( | ||
config.Project, config.Region, addr).Do() | ||
config.Project, region, addr).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error creating address: %s", err) | ||
} | ||
|
@@ -56,7 +70,7 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro | |
Service: config.clientCompute, | ||
Op: op, | ||
Project: config.Project, | ||
Region: config.Region, | ||
Region: region, | ||
Type: OperationWaitRegion, | ||
} | ||
state := w.Conf() | ||
|
@@ -81,8 +95,10 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro | |
func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
region := getOptionalRegion(d, config) | ||
|
||
addr, err := config.clientCompute.Addresses.Get( | ||
config.Project, config.Region, d.Id()).Do() | ||
config.Project, region, d.Id()).Do() | ||
if err != nil { | ||
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 { | ||
// The resource doesn't exist anymore | ||
|
@@ -103,10 +119,11 @@ func resourceComputeAddressRead(d *schema.ResourceData, meta interface{}) error | |
func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) error { | ||
config := meta.(*Config) | ||
|
||
region := getOptionalRegion(d, config) | ||
// Delete the address | ||
log.Printf("[DEBUG] address delete request") | ||
op, err := config.clientCompute.Addresses.Delete( | ||
config.Project, config.Region, d.Id()).Do() | ||
config.Project, region, d.Id()).Do() | ||
if err != nil { | ||
return fmt.Errorf("Error deleting address: %s", err) | ||
} | ||
|
@@ -116,7 +133,7 @@ func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) erro | |
Service: config.clientCompute, | ||
Op: op, | ||
Project: config.Project, | ||
Region: config.Region, | ||
Region: region, | ||
Type: OperationWaitRegion, | ||
} | ||
state := w.Conf() | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: The changelog is something maintainers update via github web iface when they're merging the PR to avoid any potential conflicts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I was hoping I was saving you the trouble of updating that, sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know you could do it when merging, I used to do a separate commit after the merge. How do you do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually just do it via github web iface. AFAIK others do as well.