Merge pull request #4719 from hashicorp/f-azurerm-tag-resources

Add tagging support for ARM resource groups and virtual networks
This commit is contained in:
James Nugent 2016-01-18 13:20:35 -05:00
commit 14344d0857
2 changed files with 34 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
} }

View File

@ -75,6 +75,8 @@ func resourceArmVirtualNetwork() *schema.Resource {
Required: true, Required: true,
ForceNew: true, ForceNew: true,
}, },
"tags": tagsSchema(),
}, },
} }
} }
@ -88,11 +90,13 @@ func resourceArmVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) e
name := d.Get("name").(string) name := d.Get("name").(string)
location := d.Get("location").(string) location := d.Get("location").(string)
resGroup := d.Get("resource_group_name").(string) resGroup := d.Get("resource_group_name").(string)
tags := d.Get("tags").(map[string]interface{})
vnet := network.VirtualNetwork{ vnet := network.VirtualNetwork{
Name: &name, Name: &name,
Location: &location, Location: &location,
Properties: getVirtualNetworkProperties(d), Properties: getVirtualNetworkProperties(d),
Tags: expandTags(tags),
} }
resp, err := vnetClient.CreateOrUpdate(resGroup, name, vnet) resp, err := vnetClient.CreateOrUpdate(resGroup, name, vnet)
@ -162,6 +166,8 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err
} }
d.Set("dns_servers", dnses) d.Set("dns_servers", dnses)
flattenAndSetTags(d, resp.Tags)
return nil return nil
} }