-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 resources azurerm_virtual_network_gateway and azurerm_virtual_network_gateway_connection #133
Changes from 5 commits
1f79d31
2087dd7
a236467
ee0bbe1
b89586f
2990404
c6ec4bc
554046a
b4143ba
b06dd57
f07a31c
0325c74
1686272
ed51416
9739bc1
f95bf5d
26b1d69
4baf7e5
d724fd7
8fcfc41
51614e0
d94db0f
1b6ddaa
81a63b6
6b2f496
19eb152
f82fdd1
66e4602
5046f19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
) | ||
|
||
func TestAccAzureRMVirtualNetworkGatewayConnection_importSiteToSite(t *testing.T) { | ||
resourceName := "azurerm_virtual_network_gateway_connection.test" | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMVirtualNetworkGatewayConnection_sitetosite, ri) | ||
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. minor could we switch this over to a function returning a formatted string to match the newer resources? |
||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMVirtualNetworkGatewayConnectionDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
|
||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package azurerm | ||
|
||
import ( | ||
"fmt" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"testing" | ||
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. minor could we sort the imports here? |
||
) | ||
|
||
func TestAccAzureRMVirtualNetworkGateway_importBasic(t *testing.T) { | ||
resourceName := "azurerm_virtual_network_gateway.test" | ||
|
||
ri := acctest.RandInt() | ||
config := fmt.Sprintf(testAccAzureRMVirtualNetworkGateway_basic, ri) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testCheckAzureRMVirtualNetworkGatewayDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
}, | ||
|
||
{ | ||
ResourceName: resourceName, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/network" | ||
"github.com/hashicorp/errwrap" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
|
@@ -97,15 +98,10 @@ func resourceArmLocalNetworkGatewayCreate(d *schema.ResourceData, meta interface | |
func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}) error { | ||
lnetClient := meta.(*ArmClient).localNetConnClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
name := id.Path["localNetworkGateways"] | ||
if name == "" { | ||
return fmt.Errorf("Cannot find 'localNetworkGateways' in '%s', make sure it is specified in the ID parameter", d.Id()) | ||
} | ||
resGroup := id.ResourceGroup | ||
|
||
resp, err := lnetClient.Get(resGroup, name) | ||
if err != nil { | ||
|
@@ -134,12 +130,10 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{} | |
func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface{}) error { | ||
lnetClient := meta.(*ArmClient).localNetConnClient | ||
|
||
id, err := parseAzureResourceID(d.Id()) | ||
resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(d.Id()) | ||
if err != nil { | ||
return err | ||
} | ||
name := id.Path["localNetworkGateways"] | ||
resGroup := id.ResourceGroup | ||
|
||
deleteResp, error := lnetClient.Delete(resGroup, name, make(chan struct{})) | ||
resp := <-deleteResp | ||
|
@@ -155,3 +149,33 @@ func resourceArmLocalNetworkGatewayDelete(d *schema.ResourceData, meta interface | |
|
||
return nil | ||
} | ||
|
||
func resourceGroupAndLocalNetworkGatewayFromId(localNetworkGatewayId string) (string, string, error) { | ||
id, err := parseAzureResourceID(localNetworkGatewayId) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
name := id.Path["localNetworkGateways"] | ||
resGroup := id.ResourceGroup | ||
|
||
return resGroup, name, nil | ||
} | ||
|
||
func retrieveLocalNetworkGatewayById(localNetworkGatewayId string, meta interface{}) (*network.LocalNetworkGateway, bool, error) { | ||
lnetClient := meta.(*ArmClient).localNetConnClient | ||
|
||
resGroup, name, err := resourceGroupAndLocalNetworkGatewayFromId(localNetworkGatewayId) | ||
if err != nil { | ||
return nil, false, errwrap.Wrapf("Error Getting LocalNetworkGateway Name and Group: {{err}}", err) | ||
} | ||
|
||
resp, err := lnetClient.Get(resGroup, name) | ||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { | ||
return nil, false, nil | ||
} | ||
return nil, false, fmt.Errorf("Error making Read request on Azure LocalNetworkGateway %s: %s", name, err) | ||
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. it'd be good to return the full error by making the second argument |
||
} | ||
|
||
return &resp, true, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ import ( | |
"net/http" | ||
|
||
"github.com/Azure/azure-sdk-for-go/arm/network" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
"time" | ||
) | ||
|
||
var subnetResourceName = "azurerm_subnet" | ||
|
@@ -236,5 +238,48 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error { | |
_, error := subnetClient.Delete(resGroup, vnetName, name, make(chan struct{})) | ||
err = <-error | ||
|
||
// After deleting a gateway subnet, we check if the subnet has been deleted and | ||
// retry if necessary. This is necessary as a workaround for scenarios in which | ||
// a gateway subnet is deleted immediately after its previously associated | ||
// virtual network gateway has been deleted. Unfortunately, the Azure Management | ||
// API does not provide information on the state, therefore we try for a | ||
// limited period of time. | ||
if err != nil && name == "GatewaySubnet" { | ||
err = resourceArmSubnetRetryDeleteGatewaySubnet(subnetClient, name, vnetName, resGroup) | ||
} | ||
|
||
return err | ||
} | ||
|
||
func resourceArmSubnetRetryDeleteGatewaySubnet(subnetClient network.SubnetsClient, name string, vnetName string, resGroup string) error { | ||
stateConf := &resource.StateChangeConf{ | ||
Pending: []string{"Deleting", "Failed"}, | ||
Target: []string{"NotFound"}, | ||
Refresh: func() (interface{}, string, error) { | ||
resp, err := subnetClient.Get(resGroup, vnetName, name, "") | ||
|
||
if err != nil { | ||
if resp.StatusCode == http.StatusNotFound { | ||
return resp, "NotFound", nil | ||
} | ||
|
||
return nil, "", fmt.Errorf("Error issuing read request when retrying to delete Gateway Subnet %s/%s (resource group %s): %s", vnetName, name, resGroup, err) | ||
} | ||
|
||
// Retry deletion of gateway subnet if provisioning state is failed | ||
if *resp.SubnetPropertiesFormat.ProvisioningState == "Failed" { | ||
log.Printf("[DEBUG] Retry deleting Gateway Subnet %s/%s after failed provisioning state.", vnetName, name) | ||
subnetClient.Delete(resGroup, vnetName, name, make(chan struct{})) | ||
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. do we need to check the result of this call? in addition - do we need to implement some kind of "max attempts" here? 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. This workaround should not be relevant anymore. |
||
} | ||
|
||
return resp, *resp.SubnetPropertiesFormat.ProvisioningState, nil | ||
}, | ||
PollInterval: 30 * time.Second, | ||
Timeout: 15 * time.Minute, | ||
} | ||
if _, err := stateConf.WaitForState(); err != nil { | ||
return fmt.Errorf("Error waiting for Gateway Subnet %s/%s to be removed: %s", vnetName, name, err) | ||
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. can this last argument become |
||
} | ||
|
||
return nil | ||
} |
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.
minor could we sort the imports here?