Skip to content

Commit

Permalink
Merge pull request #11268 from magodo/hpc_cache_tags
Browse files Browse the repository at this point in the history
`azurerm_hpc_cache` - support for `tags`
  • Loading branch information
tombuildsstuff authored Apr 13, 2021
2 parents 7e4017c + 7f33ed4 commit 2f9b31b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
7 changes: 6 additions & 1 deletion azurerm/internal/services/hpccache/hpc_cache_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strconv"
"time"

"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2021-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -206,6 +208,8 @@ func resourceHPCCache() *schema.Resource {
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"tags": tags.Schema(),
},
}
}
Expand Down Expand Up @@ -277,6 +281,7 @@ func resourceHPCCacheCreateOrUpdate(d *schema.ResourceData, meta interface{}) er
Sku: &storagecache.CacheSku{
Name: utils.String(skuName),
},
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, name, cache)
Expand Down Expand Up @@ -362,7 +367,7 @@ func resourceHPCCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("sku_name", sku.Name)
}

return nil
return tags.FlattenAndSet(d, resp.Tags)
}

func resourceHPCCacheDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
45 changes: 45 additions & 0 deletions azurerm/internal/services/hpccache/hpc_cache_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,30 @@ func TestAccHPCCache_defaultAccessPolicy(t *testing.T) {
})
}

func TestAccHPCCache_updateTags(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test")
r := HPCCacheResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("mount_addresses.#").Exists(),
),
},
data.ImportStep(),
{
Config: r.updateTags(data),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("mount_addresses.#").Exists(),
),
},
data.ImportStep(),
})
}

func (HPCCacheResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.CacheID(state.ID)
if err != nil {
Expand All @@ -238,6 +262,27 @@ resource "azurerm_hpc_cache" "test" {
cache_size_in_gb = 3072
subnet_id = azurerm_subnet.test.id
sku_name = "Standard_2G"
tags = {
environment = "Production"
}
}
`, r.template(data), data.RandomInteger)
}

func (r HPCCacheResource) updateTags(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
resource "azurerm_hpc_cache" "test" {
name = "acctest-HPCC-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
cache_size_in_gb = 3072
subnet_id = azurerm_subnet.test.id
sku_name = "Standard_2G"
tags = {
environment = "Test"
}
}
`, r.template(data), data.RandomInteger)
}
Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/hpc_cache.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ The following arguments are supported:
* `ntp_server` - (Optional) The NTP server IP Address or FQDN for the HPC Cache. Defaults to `time.windows.com`.

* `dns` - (Optional) A `dns` block as defined below.


* `tags` - (Optional) A mapping of tags to assign to the HPC Cache.

---

An `access_rule` block contains the following:
Expand Down

0 comments on commit 2f9b31b

Please sign in to comment.