provider/azurerm: Add support for managed availability sets. (#12532)
* Add support for managed availability sets. * Formatting.
This commit is contained in:
parent
c5904cf980
commit
bf4d6d5b1e
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
"github.com/Azure/azure-sdk-for-go/arm/compute"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
|
@ -65,6 +66,13 @@ func resourceArmAvailabilitySet() *schema.Resource {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"managed": {
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
Default: false,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
"tags": tagsSchema(),
|
"tags": tagsSchema(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -82,6 +90,7 @@ func resourceArmAvailabilitySetCreate(d *schema.ResourceData, meta interface{})
|
||||||
updateDomainCount := d.Get("platform_update_domain_count").(int)
|
updateDomainCount := d.Get("platform_update_domain_count").(int)
|
||||||
faultDomainCount := d.Get("platform_fault_domain_count").(int)
|
faultDomainCount := d.Get("platform_fault_domain_count").(int)
|
||||||
tags := d.Get("tags").(map[string]interface{})
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
|
managed := d.Get("managed").(bool)
|
||||||
|
|
||||||
availSet := compute.AvailabilitySet{
|
availSet := compute.AvailabilitySet{
|
||||||
Name: &name,
|
Name: &name,
|
||||||
|
@ -93,6 +102,13 @@ func resourceArmAvailabilitySetCreate(d *schema.ResourceData, meta interface{})
|
||||||
Tags: expandTags(tags),
|
Tags: expandTags(tags),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if managed == true {
|
||||||
|
n := "Aligned"
|
||||||
|
availSet.Sku = &compute.Sku{
|
||||||
|
Name: &n,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resp, err := availSetClient.CreateOrUpdate(resGroup, name, availSet)
|
resp, err := availSetClient.CreateOrUpdate(resGroup, name, availSet)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -129,6 +145,10 @@ func resourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) er
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
|
|
||||||
|
if resp.Sku != nil && resp.Sku.Name != nil {
|
||||||
|
d.Set("managed", strings.EqualFold(*resp.Sku.Name, "Aligned"))
|
||||||
|
}
|
||||||
|
|
||||||
flattenAndSetTags(d, resp.Tags)
|
flattenAndSetTags(d, resp.Tags)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -122,6 +122,27 @@ func TestAccAzureRMAvailabilitySet_withDomainCounts(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMAvailabilitySet_managed(t *testing.T) {
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
config := fmt.Sprintf(testAccAzureRMVAvailabilitySet_managed, 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", "managed", "true"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMAvailabilitySetExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMAvailabilitySetExists(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
|
||||||
|
@ -224,8 +245,8 @@ resource "azurerm_availability_set" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
environment = "Production"
|
environment = "Production"
|
||||||
cost_center = "MSFT"
|
cost_center = "MSFT"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -241,7 +262,7 @@ resource "azurerm_availability_set" "test" {
|
||||||
resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
|
|
||||||
tags {
|
tags {
|
||||||
environment = "staging"
|
environment = "staging"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
@ -259,3 +280,18 @@ resource "azurerm_availability_set" "test" {
|
||||||
platform_fault_domain_count = 1
|
platform_fault_domain_count = 1
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
var testAccAzureRMVAvailabilitySet_managed = `
|
||||||
|
resource "azurerm_resource_group" "test" {
|
||||||
|
name = "acctestRG-%d"
|
||||||
|
location = "West US"
|
||||||
|
}
|
||||||
|
resource "azurerm_availability_set" "test" {
|
||||||
|
name = "acctestavset-%d"
|
||||||
|
location = "West US"
|
||||||
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
|
platform_update_domain_count = 10
|
||||||
|
platform_fault_domain_count = 1
|
||||||
|
managed = true
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
Loading…
Reference in New Issue