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{
Create: resourceArmResourceGroupCreate,
Read: resourceArmResourceGroupRead,
Update: resourceArmResourceGroupUpdate,
Exists: resourceArmResourceGroupExists,
Delete: resourceArmResourceGroupDelete,
@ -33,6 +34,8 @@ func resourceArmResourceGroup() *schema.Resource {
ForceNew: true,
StateFunc: azureRMNormalizeLocation,
},
"tags": tagsSchema(),
},
}
}
@ -55,16 +58,39 @@ func validateArmResourceGroupName(v interface{}, k string) (ws []string, es []er
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 {
client := meta.(*ArmClient)
resGroupClient := client.resourceGroupClient
name := d.Get("name").(string)
location := d.Get("location").(string)
tags := d.Get("tags").(map[string]interface{})
rg := resources.ResourceGroup{
Name: &name,
Location: &location,
Tags: expandTags(tags),
}
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("location", res.Location)
flattenAndSetTags(d, res.Tags)
return nil
}

View File

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