provider/azurerm: Support tagging `azurerm_resource_group`

This commit is contained in:
James Nugent 2016-01-18 13:12:54 -05:00
parent d5e3db9deb
commit 2ff0c65c3c
1 changed files with 28 additions and 0 deletions

View File

@ -17,6 +17,7 @@ func resourceArmResourceGroup() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceArmResourceGroupCreate, Create: resourceArmResourceGroupCreate,
Read: resourceArmResourceGroupRead, Read: resourceArmResourceGroupRead,
Update: resourceArmResourceGroupUpdate,
Exists: resourceArmResourceGroupExists, Exists: resourceArmResourceGroupExists,
Delete: resourceArmResourceGroupDelete, Delete: resourceArmResourceGroupDelete,
@ -33,6 +34,8 @@ func resourceArmResourceGroup() *schema.Resource {
ForceNew: true, ForceNew: true,
StateFunc: azureRMNormalizeLocation, StateFunc: azureRMNormalizeLocation,
}, },
"tags": tagsSchema(),
}, },
} }
} }
@ -55,16 +58,39 @@ func validateArmResourceGroupName(v interface{}, k string) (ws []string, es []er
return return
} }
func resourceArmResourceGroupUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
resGroupClient := client.resourceGroupClient
if !d.HasChange("tags") {
return nil
}
name := d.Get("name").(string)
newTags := d.Get("tags").(map[string]interface{})
_, err := resGroupClient.Patch(name, resources.ResourceGroup{
Tags: expandTags(newTags),
})
if err != nil {
return fmt.Errorf("Error issuing Azure ARM create request to update resource group %q: %s", name, err)
}
return resourceArmResourceGroupRead(d, meta)
}
func resourceArmResourceGroupCreate(d *schema.ResourceData, meta interface{}) error { func resourceArmResourceGroupCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient) client := meta.(*ArmClient)
resGroupClient := client.resourceGroupClient resGroupClient := client.resourceGroupClient
name := d.Get("name").(string) name := d.Get("name").(string)
location := d.Get("location").(string) location := d.Get("location").(string)
tags := d.Get("tags").(map[string]interface{})
rg := resources.ResourceGroup{ rg := resources.ResourceGroup{
Name: &name, Name: &name,
Location: &location, Location: &location,
Tags: expandTags(tags),
} }
resp, err := resGroupClient.CreateOrUpdate(name, rg) resp, err := resGroupClient.CreateOrUpdate(name, rg)
@ -109,6 +135,8 @@ func resourceArmResourceGroupRead(d *schema.ResourceData, meta interface{}) erro
d.Set("name", res.Name) d.Set("name", res.Name)
d.Set("location", res.Location) d.Set("location", res.Location)
flattenAndSetTags(d, res.Tags)
return nil return nil
} }