Skip to content

Commit bed3f8a

Browse files
Add support for Azure metadata (tags) (#191)
* Add support for Azure metadata (tags) * Restyled by gofmt * Also tag the resource group Co-authored-by: Restyled.io <commits@restyled.io>
1 parent f7755f7 commit bed3f8a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

iterative/azure/provider.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
3434
spot := d.Get("spot").(bool)
3535
spotPrice := d.Get("spot_price").(float64)
3636

37+
metadata := map[string]*string{}
38+
for key, value := range d.Get("metadata").(map[string]interface{}) {
39+
stringValue := value.(string)
40+
metadata[key] = &stringValue
41+
}
42+
3743
image := d.Get("image").(string)
3844
if image == "" {
3945
image = "Canonical:UbuntuServer:18.04-LTS:latest"
@@ -61,6 +67,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
6167
gpName,
6268
resources.Group{
6369
Location: to.StringPtr(region),
70+
Tags: metadata,
6471
})
6572
if err != nil {
6673
return err
@@ -73,6 +80,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
7380
gpName,
7481
nsgName,
7582
network.SecurityGroup{
83+
Tags: metadata,
7684
Location: to.StringPtr(region),
7785
SecurityGroupPropertiesFormat: &network.SecurityGroupPropertiesFormat{
7886
SecurityRules: &[]network.SecurityRule{
@@ -106,6 +114,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
106114
gpName,
107115
ipName,
108116
network.PublicIPAddress{
117+
Tags: metadata,
109118
Name: to.StringPtr(ipName),
110119
Location: to.StringPtr(region),
111120
PublicIPAddressPropertiesFormat: &network.PublicIPAddressPropertiesFormat{
@@ -126,6 +135,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
126135
gpName,
127136
vnetName,
128137
network.VirtualNetwork{
138+
Tags: metadata,
129139
Location: to.StringPtr(region),
130140
VirtualNetworkPropertiesFormat: &network.VirtualNetworkPropertiesFormat{
131141
AddressSpace: &network.AddressSpace{
@@ -163,6 +173,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
163173

164174
nicClient, _ := getNicClient(subscriptionID)
165175
nicParams := network.Interface{
176+
Tags: metadata,
166177
Name: to.StringPtr(nicName),
167178
Location: to.StringPtr(region),
168179
InterfacePropertiesFormat: &network.InterfacePropertiesFormat{
@@ -188,6 +199,7 @@ func ResourceMachineCreate(ctx context.Context, d *schema.ResourceData, m interf
188199

189200
vmClient, _ := getVMClient(subscriptionID)
190201
vmSettings := compute.VirtualMachine{
202+
Tags: metadata,
191203
Location: to.StringPtr(region),
192204
VirtualMachineProperties: &compute.VirtualMachineProperties{
193205
HardwareProfile: &compute.HardwareProfile{

0 commit comments

Comments
 (0)