Merge pull request #8859 from carinadigital/arm-vm-fix
provider/azurerm: Terraform Plan errors when created resources disappear
This commit is contained in:
commit
97ad032474
|
@ -118,12 +118,12 @@ func resourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) er
|
||||||
|
|
||||||
resp, err := availSetClient.Get(resGroup, name)
|
resp, err := availSetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Availability Set %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Availability Set %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
availSet := *resp.Properties
|
availSet := *resp.Properties
|
||||||
d.Set("platform_update_domain_count", availSet.PlatformUpdateDomainCount)
|
d.Set("platform_update_domain_count", availSet.PlatformUpdateDomainCount)
|
||||||
|
|
|
@ -34,6 +34,32 @@ func TestAccAzureRMAvailabilitySet_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMAvailabilitySet_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVAvailabilitySet_basic, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMAvailabilitySetDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMAvailabilitySetExists("azurerm_availability_set.test"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"azurerm_availability_set.test", "platform_update_domain_count", "5"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"azurerm_availability_set.test", "platform_fault_domain_count", "3"),
|
||||||
|
testCheckAzureRMAvailabilitySetDisappears("azurerm_availability_set.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMAvailabilitySet_withTags(t *testing.T) {
|
func TestAccAzureRMAvailabilitySet_withTags(t *testing.T) {
|
||||||
|
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
|
@ -125,6 +151,31 @@ func testCheckAzureRMAvailabilitySetExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMAvailabilitySetDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
availSetName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for availability set: %s", availSetName)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).availSetClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, availSetName)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on availSetClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMAvailabilitySetDestroy(s *terraform.State) error {
|
func testCheckAzureRMAvailabilitySetDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).availSetClient
|
conn := testAccProvider.Meta().(*ArmClient).availSetClient
|
||||||
|
|
||||||
|
|
|
@ -226,12 +226,12 @@ func resourceArmCdnEndpointRead(d *schema.ResourceData, meta interface{}) error
|
||||||
log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
||||||
resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
d.Set("host_name", resp.Properties.HostName)
|
d.Set("host_name", resp.Properties.HostName)
|
||||||
|
|
|
@ -29,6 +29,27 @@ func TestAccAzureRMCdnEndpoint_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMCdnEndpoint_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMCdnEndpoint_basic, ri, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
||||||
|
testCheckAzureRMCdnEndpointDisappears("azurerm_cdn_endpoint.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) {
|
func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTags, ri, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTags, ri, ri, ri)
|
||||||
|
@ -96,6 +117,32 @@ func testCheckAzureRMCdnEndpointExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMCdnEndpointDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
profileName := rs.Primary.Attributes["profile_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for cdn endpoint: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
||||||
|
|
||||||
|
_, err := conn.DeleteIfExists(name, profileName, resourceGroup, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on cdnEndpointsClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMCdnEndpointDestroy(s *terraform.State) error {
|
func testCheckAzureRMCdnEndpointDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
||||||
|
|
||||||
|
|
|
@ -100,12 +100,12 @@ func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := cdnProfilesClient.Get(name, resGroup)
|
resp, err := cdnProfilesClient.Get(name, resGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Sku != nil {
|
if resp.Sku != nil {
|
||||||
d.Set("sku", string(resp.Sku.Name))
|
d.Set("sku", string(resp.Sku.Name))
|
||||||
|
|
|
@ -110,12 +110,12 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}
|
||||||
|
|
||||||
resp, err := lnetClient.Get(resGroup, name)
|
resp, err := lnetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
|
|
|
@ -29,6 +29,28 @@ func TestAccAzureRMLocalNetworkGateway_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLocalNetworkGateway_disappears(t *testing.T) {
|
||||||
|
name := "azurerm_local_network_gateway.test"
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLocalNetworkGatewayDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLocalNetworkGatewayConfig_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLocalNetworkGatewayExists(name),
|
||||||
|
resource.TestCheckResourceAttr(name, "gateway_address", "127.0.0.1"),
|
||||||
|
resource.TestCheckResourceAttr(name, "address_space.0", "127.0.0.0/8"),
|
||||||
|
testCheckAzureRMLocalNetworkGatewayDisappears(name),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
// testCheckAzureRMLocalNetworkGatewayExists returns the resurce.TestCheckFunc
|
||||||
// which checks whether or not the expected local network gateway exists both
|
// which checks whether or not the expected local network gateway exists both
|
||||||
// in the schema, and on Azure.
|
// in the schema, and on Azure.
|
||||||
|
@ -63,6 +85,37 @@ func testCheckAzureRMLocalNetworkGatewayExists(name string) resource.TestCheckFu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLocalNetworkGatewayDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// first check within the schema for the local network gateway:
|
||||||
|
res, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Local network gateway '%s' not found.", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// then, extract the name and the resource group:
|
||||||
|
id, err := parseAzureResourceID(res.Primary.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
localNetName := id.Path["localNetworkGateways"]
|
||||||
|
resGrp := id.ResourceGroup
|
||||||
|
|
||||||
|
// and finally, check that it exists on Azure:
|
||||||
|
lnetClient := testAccProvider.Meta().(*ArmClient).localNetConnClient
|
||||||
|
|
||||||
|
resp, err := lnetClient.Delete(resGrp, localNetName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
return fmt.Errorf("Local network gateway '%s' (resource group '%s') does not exist on Azure.", localNetName, resGrp)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("Error deleting the state of local network gateway '%s'.", localNetName)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
func testCheckAzureRMLocalNetworkGatewayDestroy(s *terraform.State) error {
|
||||||
for _, res := range s.RootModule().Resources {
|
for _, res := range s.RootModule().Resources {
|
||||||
if res.Type != "azurerm_local_network_gateway" {
|
if res.Type != "azurerm_local_network_gateway" {
|
||||||
|
|
|
@ -246,12 +246,12 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
|
||||||
|
|
||||||
resp, err := ifaceClient.Get(resGroup, name, "")
|
resp, err := ifaceClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Interface %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Network Interface %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
iface := *resp.Properties
|
iface := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,24 @@ func TestAccAzureRMNetworkInterface_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMNetworkInterface_disappears(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMNetworkInterfaceDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMNetworkInterface_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMNetworkInterfaceExists("azurerm_network_interface.test"),
|
||||||
|
testCheckAzureRMNetworkInterfaceDisappears("azurerm_network_interface.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) {
|
func TestAccAzureRMNetworkInterface_enableIPForwarding(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -133,6 +151,31 @@ func testCheckAzureRMNetworkInterfaceExists(name string) resource.TestCheckFunc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMNetworkInterfaceDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for availability set: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on ifaceClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMNetworkInterfaceDestroy(s *terraform.State) error {
|
func testCheckAzureRMNetworkInterfaceDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
conn := testAccProvider.Meta().(*ArmClient).ifaceClient
|
||||||
|
|
||||||
|
|
|
@ -192,12 +192,12 @@ func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{
|
||||||
|
|
||||||
resp, err := secGroupClient.Get(resGroup, name, "")
|
resp, err := secGroupClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.SecurityRules != nil {
|
if resp.Properties.SecurityRules != nil {
|
||||||
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
|
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
|
||||||
|
|
|
@ -25,6 +25,24 @@ func TestAccAzureRMNetworkSecurityGroup_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMNetworkSecurityGroup_disappears(t *testing.T) {
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMNetworkSecurityGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMNetworkSecurityGroup_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMNetworkSecurityGroupExists("azurerm_network_security_group.test"),
|
||||||
|
testCheckAzureRMNetworkSecurityGroupDisappears("azurerm_network_security_group.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) {
|
func TestAccAzureRMNetworkSecurityGroup_withTags(t *testing.T) {
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -114,6 +132,31 @@ func testCheckAzureRMNetworkSecurityGroupExists(name string) resource.TestCheckF
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMNetworkSecurityGroupDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
sgName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for network security group: %s", sgName)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).secGroupClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, sgName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on secGroupClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error {
|
func testCheckAzureRMNetworkSecurityGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).secGroupClient
|
conn := testAccProvider.Meta().(*ArmClient).secGroupClient
|
||||||
|
|
||||||
|
|
|
@ -176,12 +176,12 @@ func resourceArmNetworkSecurityRuleRead(d *schema.ResourceData, meta interface{}
|
||||||
|
|
||||||
resp, err := secRuleClient.Get(resGroup, networkSGName, sgRuleName)
|
resp, err := secRuleClient.Get(resGroup, networkSGName, sgRuleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Security Rule %s: %s", sgRuleName, err)
|
return fmt.Errorf("Error making Read request on Azure Network Security Rule %s: %s", sgRuleName, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("access", resp.Properties.Access)
|
d.Set("access", resp.Properties.Access)
|
||||||
d.Set("destination_address_prefix", resp.Properties.DestinationAddressPrefix)
|
d.Set("destination_address_prefix", resp.Properties.DestinationAddressPrefix)
|
||||||
|
|
|
@ -26,6 +26,25 @@ func TestAccAzureRMNetworkSecurityRule_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMNetworkSecurityRule_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMNetworkSecurityRuleDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMNetworkSecurityRule_basic,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMNetworkSecurityRuleExists("azurerm_network_security_rule.test"),
|
||||||
|
testCheckAzureRMNetworkSecurityRuleDisappears("azurerm_network_security_rule.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) {
|
func TestAccAzureRMNetworkSecurityRule_addingRules(t *testing.T) {
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
@ -80,6 +99,32 @@ func testCheckAzureRMNetworkSecurityRuleExists(name string) resource.TestCheckFu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMNetworkSecurityRuleDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
sgName := rs.Primary.Attributes["network_security_group_name"]
|
||||||
|
sgrName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for network security rule: %s", sgName)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).secRuleClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, sgName, sgrName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on secRuleClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error {
|
func testCheckAzureRMNetworkSecurityRuleDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).secRuleClient
|
conn := testAccProvider.Meta().(*ArmClient).secRuleClient
|
||||||
|
|
||||||
|
|
|
@ -166,12 +166,12 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := publicIPClient.Get(resGroup, name, "")
|
resp, err := publicIPClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
|
|
|
@ -98,6 +98,28 @@ func TestAccAzureRMPublicIpStatic_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMPublicIpStatic_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVPublicIpStatic_basic, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMPublicIpDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMPublicIpExists("azurerm_public_ip.test"),
|
||||||
|
testCheckAzureRMPublicIpDisappears("azurerm_public_ip.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMPublicIpStatic_idleTimeout(t *testing.T) {
|
func TestAccAzureRMPublicIpStatic_idleTimeout(t *testing.T) {
|
||||||
|
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
|
@ -240,6 +262,31 @@ func testCheckAzureRMPublicIpExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMPublicIpDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
publicIpName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for public ip: %s", publicIpName)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, publicIpName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on publicIPClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMPublicIpDestroy(s *terraform.State) error {
|
func testCheckAzureRMPublicIpDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
conn := testAccProvider.Meta().(*ArmClient).publicIPClient
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,27 @@ func TestAccAzureRMResourceGroup_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMResourceGroup_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMResourceGroup_basic, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMResourceGroupDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMResourceGroupExists("azurerm_resource_group.test"),
|
||||||
|
testCheckAzureRMResourceGroupDisappears("azurerm_resource_group.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMResourceGroup_withTags(t *testing.T) {
|
func TestAccAzureRMResourceGroup_withTags(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAzureRMResourceGroup_withTags, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMResourceGroup_withTags, ri)
|
||||||
|
@ -92,6 +113,28 @@ func testCheckAzureRMResourceGroupExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMResourceGroupDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
resourceGroup := rs.Primary.Attributes["name"]
|
||||||
|
|
||||||
|
// Ensure resource group exists in API
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).resourceGroupClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on resourceGroupClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMResourceGroupDestroy(s *terraform.State) error {
|
func testCheckAzureRMResourceGroupDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).resourceGroupClient
|
conn := testAccProvider.Meta().(*ArmClient).resourceGroupClient
|
||||||
|
|
||||||
|
|
|
@ -113,12 +113,12 @@ func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := routesClient.Get(resGroup, rtName, routeName)
|
resp, err := routesClient.Get(resGroup, rtName, routeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err)
|
return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,12 +143,12 @@ func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := routeTablesClient.Get(resGroup, name, "")
|
resp, err := routeTablesClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.Subnets != nil {
|
if resp.Properties.Subnets != nil {
|
||||||
if len(*resp.Properties.Subnets) > 0 {
|
if len(*resp.Properties.Subnets) > 0 {
|
||||||
|
|
|
@ -78,6 +78,28 @@ func TestAccAzureRMRouteTable_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMRouteTable_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMRouteTable_basic, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMRouteTableDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMRouteTableExists("azurerm_route_table.test"),
|
||||||
|
testCheckAzureRMRouteTableDisappears("azurerm_route_table.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMRouteTable_withTags(t *testing.T) {
|
func TestAccAzureRMRouteTable_withTags(t *testing.T) {
|
||||||
|
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
|
@ -177,6 +199,31 @@ func testCheckAzureRMRouteTableExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMRouteTableDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for route table: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on routeTablesClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMRouteTableDestroy(s *terraform.State) error {
|
func testCheckAzureRMRouteTableDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
conn := testAccProvider.Meta().(*ArmClient).routeTablesClient
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,28 @@ func TestAccAzureRMRoute_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMRoute_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMRoute_basic, ri, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMRouteDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMRouteExists("azurerm_route.test"),
|
||||||
|
testCheckAzureRMRouteDisappears("azurerm_route.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMRoute_multipleRoutes(t *testing.T) {
|
func TestAccAzureRMRoute_multipleRoutes(t *testing.T) {
|
||||||
|
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
|
@ -88,6 +110,32 @@ func testCheckAzureRMRouteExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMRouteDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
rtName := rs.Primary.Attributes["route_table_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for route: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).routesClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, rtName, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on routesClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMRouteDestroy(s *terraform.State) error {
|
func testCheckAzureRMRouteDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).routesClient
|
conn := testAccProvider.Meta().(*ArmClient).routesClient
|
||||||
|
|
||||||
|
|
|
@ -256,12 +256,12 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
|
||||||
|
|
||||||
resp, err := client.GetProperties(resGroup, name)
|
resp, err := client.GetProperties(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
keys, err := client.ListKeys(resGroup, name)
|
keys, err := client.ListKeys(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -84,6 +84,31 @@ func TestAccAzureRMStorageAccount_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMStorageAccount_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
rs := acctest.RandString(4)
|
||||||
|
preConfig := fmt.Sprintf(testAccAzureRMStorageAccount_basic, ri, rs)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: preConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMStorageAccountExists("azurerm_storage_account.testsa"),
|
||||||
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "account_type", "Standard_LRS"),
|
||||||
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.%", "1"),
|
||||||
|
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "tags.environment", "production"),
|
||||||
|
testCheckAzureRMStorageAccountDisappears("azurerm_storage_account.testsa"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMStorageAccountExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMStorageAccountExists(name string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// Ensure we have enough information in state to look up in API
|
// Ensure we have enough information in state to look up in API
|
||||||
|
@ -111,6 +136,29 @@ func testCheckAzureRMStorageAccountExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMStorageAccountDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
storageAccount := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
|
||||||
|
// Ensure resource group exists in API
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, storageAccount)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on storageServiceClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error {
|
func testCheckAzureRMStorageAccountDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
conn := testAccProvider.Meta().(*ArmClient).storageServiceClient
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,28 @@ func TestAccAzureRMStorageBlob_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMStorageBlob_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
rs := strings.ToLower(acctest.RandString(11))
|
||||||
|
config := fmt.Sprintf(testAccAzureRMStorageBlob_basic, ri, rs)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMStorageBlobDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMStorageBlobExists("azurerm_storage_blob.test"),
|
||||||
|
testCheckAzureRMStorageBlobDisappears("azurerm_storage_blob.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMStorageBlobBlock_source(t *testing.T) {
|
func TestAccAzureRMStorageBlobBlock_source(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
rs1 := strings.ToLower(acctest.RandString(11))
|
rs1 := strings.ToLower(acctest.RandString(11))
|
||||||
|
@ -330,6 +352,40 @@ func testCheckAzureRMStorageBlobExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMStorageBlobDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
storageAccountName := rs.Primary.Attributes["storage_account_name"]
|
||||||
|
storageContainerName := rs.Primary.Attributes["storage_container_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for storage blob: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
armClient := testAccProvider.Meta().(*ArmClient)
|
||||||
|
blobClient, accountExists, err := armClient.getBlobStorageClientForStorageAccount(resourceGroup, storageAccountName)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !accountExists {
|
||||||
|
return fmt.Errorf("Bad: Storage Account %q does not exist", storageAccountName)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = blobClient.DeleteBlobIfExists(storageContainerName, name, map[string]string{})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMStorageBlobMatchesFile(name string, kind storage.BlobType, filePath string) resource.TestCheckFunc {
|
func testCheckAzureRMStorageBlobMatchesFile(name string, kind storage.BlobType, filePath string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
|
|
||||||
|
|
|
@ -133,12 +133,12 @@ func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
||||||
ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
||||||
|
|
|
@ -30,6 +30,28 @@ func TestAccAzureRMSubnet_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMSubnet_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMSubnet_basic, ri, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMSubnetDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMSubnetExists("azurerm_subnet.test"),
|
||||||
|
testCheckAzureRMSubnetDisappears("azurerm_subnet.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMSubnetExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMSubnetExists(name string) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// Ensure we have enough information in state to look up in API
|
// Ensure we have enough information in state to look up in API
|
||||||
|
@ -60,6 +82,32 @@ func testCheckAzureRMSubnetExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMSubnetDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
vnetName := rs.Primary.Attributes["virtual_network_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for subnet: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, vnetName, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on subnetClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMSubnetDestroy(s *terraform.State) error {
|
func testCheckAzureRMSubnetDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
conn := testAccProvider.Meta().(*ArmClient).subnetClient
|
||||||
|
|
||||||
|
|
|
@ -144,12 +144,12 @@ func resourceArmTemplateDeploymentRead(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
resp, err := deployClient.Get(resGroup, name)
|
resp, err := deployClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure RM Template Deployment %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure RM Template Deployment %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputs map[string]string
|
var outputs map[string]string
|
||||||
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
|
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
|
||||||
|
|
|
@ -29,6 +29,26 @@ func TestAccAzureRMTemplateDeployment_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMTemplateDeployment_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_basicExample, ri, ri)
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMTemplateDeploymentDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMTemplateDeploymentExists("azurerm_template_deployment.test"),
|
||||||
|
testCheckAzureRMTemplateDeploymentDisappears("azurerm_template_deployment.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) {
|
func TestAccAzureRMTemplateDeployment_withParams(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withParams, ri, ri, ri)
|
config := fmt.Sprintf(testAccAzureRMTemplateDeployment_withParams, ri, ri, ri)
|
||||||
|
@ -93,6 +113,31 @@ func testCheckAzureRMTemplateDeploymentExists(name string) resource.TestCheckFun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMTemplateDeploymentDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for template deployment: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).deploymentsClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on deploymentsClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMTemplateDeploymentDestroy(s *terraform.State) error {
|
func testCheckAzureRMTemplateDeploymentDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).vmClient
|
conn := testAccProvider.Meta().(*ArmClient).vmClient
|
||||||
|
|
||||||
|
|
|
@ -153,12 +153,12 @@ func resourceArmTrafficManagerEndpointRead(d *schema.ResourceData, meta interfac
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, profileName, endpointType, name)
|
resp, err := client.Get(resGroup, profileName, endpointType, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on TrafficManager Endpoint %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on TrafficManager Endpoint %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint := *resp.Properties
|
endpoint := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,30 @@ func TestAccAzureRMTrafficManagerEndpoint_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMTrafficManagerEndpoint_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMTrafficManagerEndpoint_basic, ri, ri, ri, ri, ri, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMTrafficManagerEndpointDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMTrafficManagerEndpointExists("azurerm_traffic_manager_endpoint.testAzure"),
|
||||||
|
testCheckAzureRMTrafficManagerEndpointExists("azurerm_traffic_manager_endpoint.testExternal"),
|
||||||
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_endpoint.testAzure", "endpoint_status", "Enabled"),
|
||||||
|
resource.TestCheckResourceAttr("azurerm_traffic_manager_endpoint.testExternal", "endpoint_status", "Enabled"),
|
||||||
|
testCheckAzureRMTrafficManagerEndpointDisappears("azurerm_traffic_manager_endpoint.testAzure"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal(t *testing.T) {
|
func TestAccAzureRMTrafficManagerEndpoint_basicDisableExternal(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAzureRMTrafficManagerEndpoint_basic, ri, ri, ri, ri, ri, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMTrafficManagerEndpoint_basic, ri, ri, ri, ri, ri, ri, ri)
|
||||||
|
@ -183,6 +207,34 @@ func testCheckAzureRMTrafficManagerEndpointExists(name string) resource.TestChec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMTrafficManagerEndpointDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
endpointType := rs.Primary.Attributes["type"]
|
||||||
|
profileName := rs.Primary.Attributes["profile_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for Traffic Manager Profile: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure resource group/virtual network combination exists in API
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).trafficManagerEndpointsClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, profileName, path.Base(endpointType), name)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on trafficManagerEndpointsClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMTrafficManagerEndpointDestroy(s *terraform.State) error {
|
func testCheckAzureRMTrafficManagerEndpointDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).trafficManagerEndpointsClient
|
conn := testAccProvider.Meta().(*ArmClient).trafficManagerEndpointsClient
|
||||||
|
|
||||||
|
|
|
@ -151,12 +151,12 @@ func resourceArmTrafficManagerProfileRead(d *schema.ResourceData, meta interface
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, name)
|
resp, err := client.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Traffic Manager Profile %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Traffic Manager Profile %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
profile := *resp.Properties
|
profile := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -520,12 +520,12 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
|
||||||
resp, err := vmClient.Get(resGroup, name, "")
|
resp, err := vmClient.Get(resGroup, name, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Virtual Machine %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Virtual Machine %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Plan != nil {
|
if resp.Plan != nil {
|
||||||
if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil {
|
if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil {
|
||||||
|
|
|
@ -432,13 +432,13 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
|
||||||
|
|
||||||
resp, err := vmScaleSetClient.Get(resGroup, name)
|
resp, err := vmScaleSetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
log.Printf("[INFO] AzureRM Virtual Machine Scale Set (%s) Not Found. Removing from State", name)
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Virtual Machine Scale Set %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Virtual Machine Scale Set %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
log.Printf("[INFO] AzureRM Virtual Machine Scale Set (%s) Not Found. Removing from State", name)
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
|
|
|
@ -28,6 +28,26 @@ func TestAccAzureRMVirtualMachineScaleSet_basicLinux(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMVirtualMachineScaleSet_basicLinux_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVirtualMachineScaleSet_basicLinux, ri, ri, ri, ri, ri, ri, ri, ri)
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMVirtualMachineScaleSetDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMVirtualMachineScaleSetExists("azurerm_virtual_machine_scale_set.test"),
|
||||||
|
testCheckAzureRMVirtualMachineScaleSetDisappears("azurerm_virtual_machine_scale_set.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
//func TestAccAzureRMVirtualMachineScaleSet_basicWindowsMachine(t *testing.T) {
|
//func TestAccAzureRMVirtualMachineScaleSet_basicWindowsMachine(t *testing.T) {
|
||||||
// ri := acctest.RandInt()
|
// ri := acctest.RandInt()
|
||||||
// rs := acctest.RandString(6)
|
// rs := acctest.RandString(6)
|
||||||
|
@ -76,6 +96,31 @@ func testCheckAzureRMVirtualMachineScaleSetExists(name string) resource.TestChec
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMVirtualMachineScaleSetDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for virtual machine: scale set %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on vmScaleSetClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMVirtualMachineScaleSetDestroy(s *terraform.State) error {
|
func testCheckAzureRMVirtualMachineScaleSetDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
|
conn := testAccProvider.Meta().(*ArmClient).vmScaleSetClient
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,27 @@ func TestAccAzureRMVirtualMachine_basicLinuxMachine(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMVirtualMachine_basicLinuxMachine_disappears(t *testing.T) {
|
||||||
|
var vm compute.VirtualMachine
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVirtualMachine_basicLinuxMachine, ri, ri, ri, ri, ri, ri, ri)
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMVirtualMachineDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMVirtualMachineExists("azurerm_virtual_machine.test", &vm),
|
||||||
|
testCheckAzureRMVirtualMachineDisappears("azurerm_virtual_machine.test", &vm),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
|
func TestAccAzureRMVirtualMachine_withDataDisk(t *testing.T) {
|
||||||
var vm compute.VirtualMachine
|
var vm compute.VirtualMachine
|
||||||
|
|
||||||
|
@ -409,6 +430,31 @@ func testCheckAzureRMVirtualMachineVHDExistance(name string, shouldExist bool) r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMVirtualMachineDisappears(name string, vm *compute.VirtualMachine) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
vmName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for virtual machine: %s", vmName)
|
||||||
|
}
|
||||||
|
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).vmClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, vmName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on vmClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var testAccAzureRMVirtualMachine_basicLinuxMachine = `
|
var testAccAzureRMVirtualMachine_basicLinuxMachine = `
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
|
|
|
@ -133,12 +133,13 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err
|
||||||
|
|
||||||
resp, err := vnetClient.Get(resGroup, name, "")
|
resp, err := vnetClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure virtual network %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure virtual network %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
vnet := *resp.Properties
|
vnet := *resp.Properties
|
||||||
|
|
||||||
// update appropriate values
|
// update appropriate values
|
||||||
|
|
|
@ -124,12 +124,12 @@ func resourceArmVirtualNetworkPeeringRead(d *schema.ResourceData, meta interface
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, vnetName, name)
|
resp, err := client.Get(resGroup, vnetName, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure virtual network peering %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure virtual network peering %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
peer := *resp.Properties
|
peer := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,32 @@ func TestAccAzureRMVirtualNetworkPeering_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMVirtualNetworkPeering_disappears(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVirtualNetworkPeering_basic, ri, ri, ri, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMVirtualNetworkPeeringDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMVirtualNetworkPeeringExists("azurerm_virtual_network_peering.test1"),
|
||||||
|
testCheckAzureRMVirtualNetworkPeeringExists("azurerm_virtual_network_peering.test2"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"azurerm_virtual_network_peering.test1", "allow_virtual_network_access", "true"),
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"azurerm_virtual_network_peering.test2", "allow_virtual_network_access", "true"),
|
||||||
|
testCheckAzureRMVirtualNetworkPeeringDisappears("azurerm_virtual_network_peering.test1"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMVirtualNetworkPeering_update(t *testing.T) {
|
func TestAccAzureRMVirtualNetworkPeering_update(t *testing.T) {
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
preConfig := fmt.Sprintf(testAccAzureRMVirtualNetworkPeering_basic, ri, ri, ri, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMVirtualNetworkPeering_basic, ri, ri, ri, ri, ri)
|
||||||
|
@ -110,6 +136,33 @@ func testCheckAzureRMVirtualNetworkPeeringExists(name string) resource.TestCheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMVirtualNetworkPeeringDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
name := rs.Primary.Attributes["name"]
|
||||||
|
vnetName := rs.Primary.Attributes["virtual_network_name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for virtual network peering: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure resource group/virtual network peering combination exists in API
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).vnetPeeringsClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, vnetName, name, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on vnetPeeringsClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMVirtualNetworkPeeringDestroy(s *terraform.State) error {
|
func testCheckAzureRMVirtualNetworkPeeringDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).vnetPeeringsClient
|
conn := testAccProvider.Meta().(*ArmClient).vnetPeeringsClient
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,28 @@ func TestAccAzureRMVirtualNetwork_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMVirtualNetwork_disappears(t *testing.T) {
|
||||||
|
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVirtualNetwork_basic, ri, ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMVirtualNetworkDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: config,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMVirtualNetworkExists("azurerm_virtual_network.test"),
|
||||||
|
testCheckAzureRMVirtualNetworkDisappears("azurerm_virtual_network.test"),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) {
|
func TestAccAzureRMVirtualNetwork_withTags(t *testing.T) {
|
||||||
|
|
||||||
ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
|
@ -98,6 +120,32 @@ func testCheckAzureRMVirtualNetworkExists(name string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMVirtualNetworkDisappears(name string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
// Ensure we have enough information in state to look up in API
|
||||||
|
rs, ok := s.RootModule().Resources[name]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
virtualNetworkName := rs.Primary.Attributes["name"]
|
||||||
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
|
if !hasResourceGroup {
|
||||||
|
return fmt.Errorf("Bad: no resource group found in state for virtual network: %s", virtualNetworkName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure resource group/virtual network combination exists in API
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).vnetClient
|
||||||
|
|
||||||
|
_, err := conn.Delete(resourceGroup, virtualNetworkName, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Bad: Delete on vnetClient: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMVirtualNetworkDestroy(s *terraform.State) error {
|
func testCheckAzureRMVirtualNetworkDestroy(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*ArmClient).vnetClient
|
conn := testAccProvider.Meta().(*ArmClient).vnetClient
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue