Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_hpc_cache: update API version to 2020-03-01 and support mtu and root_squash_enabled properties #8078

Merged
merged 6 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azurerm/internal/services/storage/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagesync/mgmt/2020-03-01/storagesync"
"github.com/Azure/go-autorest/autorest"
az "github.com/Azure/go-autorest/autorest/azure"
Expand Down
39 changes: 36 additions & 3 deletions azurerm/internal/services/storage/resource_arm_hpc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand All @@ -19,12 +19,14 @@ import (

func resourceArmHPCCache() *schema.Resource {
return &schema.Resource{
Create: resourceArmHPCCacheCreate,
Create: resourceArmHPCCacheCreateOrUpdate,
Update: resourceArmHPCCacheCreateOrUpdate,
Read: resourceArmHPCCacheRead,
Delete: resourceArmHPCCacheDelete,

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Update: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Delete: schema.DefaultTimeout(30 * time.Minute),
},
Expand Down Expand Up @@ -76,6 +78,23 @@ func resourceArmHPCCache() *schema.Resource {
}, false),
},

"mtu": {
Type: schema.TypeInt,
Optional: true,
Default: 1500,
ValidateFunc: validation.IntBetween(576, 1500),
},

"root_squash_enabled": {
Type: schema.TypeBool,
Optional: true,
// TODO 3.0: remove "Computed: true" and add "Default: true"
// The old resource has no consistent default for the rootSquash setting. In order not to
// break users, we intentionally mark this property as Computed.
// https://docs.microsoft.com/en-us/azure/hpc-cache/configuration#configure-root-squash.
Computed: true,
},

"mount_addresses": {
Type: schema.TypeList,
Computed: true,
Expand All @@ -85,7 +104,7 @@ func resourceArmHPCCache() *schema.Resource {
}
}

func resourceArmHPCCacheCreate(d *schema.ResourceData, meta interface{}) error {
func resourceArmHPCCacheCreateOrUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Storage.CachesClient
ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d)
defer cancel()
Expand All @@ -111,13 +130,21 @@ func resourceArmHPCCacheCreate(d *schema.ResourceData, meta interface{}) error {
cacheSize := d.Get("cache_size_in_gb").(int)
subnet := d.Get("subnet_id").(string)
skuName := d.Get("sku_name").(string)
rootSquash := d.Get("root_squash_enabled").(bool)
mtu := d.Get("mtu").(int)

cache := &storagecache.Cache{
Name: utils.String(name),
Location: utils.String(location),
CacheProperties: &storagecache.CacheProperties{
CacheSizeGB: utils.Int32(int32(cacheSize)),
Subnet: utils.String(subnet),
NetworkSettings: &storagecache.CacheNetworkSettings{
Mtu: utils.Int32(int32(mtu)),
},
SecuritySettings: &storagecache.CacheSecuritySettings{
RootSquash: &rootSquash,
},
},
Sku: &storagecache.CacheSku{
Name: utils.String(skuName),
Expand Down Expand Up @@ -174,6 +201,12 @@ func resourceArmHPCCacheRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cache_size_in_gb", props.CacheSizeGB)
d.Set("subnet_id", props.Subnet)
d.Set("mount_addresses", utils.FlattenStringSlice(props.MountAddresses))
if props.NetworkSettings != nil {
d.Set("mtu", props.NetworkSettings.Mtu)
}
if props.SecuritySettings != nil {
d.Set("root_squash_enabled", props.SecuritySettings.RootSquash)
}
}

if sku := resp.Sku; sku != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"time"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand Down Expand Up @@ -104,9 +104,9 @@ func resourceArmHPCCacheBlobTargetCreateOrUpdate(d *schema.ResourceData, meta in
},
}
param := &storagecache.StorageTarget{
StorageTargetProperties: &storagecache.StorageTargetProperties{
BasicStorageTargetProperties: &storagecache.ClfsTargetProperties{
Junctions: &namespaceJunction,
TargetType: storagecache.StorageTargetTypeClfs,
TargetType: storagecache.TargetTypeClfs,
Clfs: &storagecache.ClfsTarget{
Target: utils.String(containerId),
},
Expand Down Expand Up @@ -161,7 +161,12 @@ func resourceArmHPCCacheBlobTargetRead(d *schema.ResourceData, meta interface{})
d.Set("resource_group_name", id.ResourceGroup)
d.Set("cache_name", id.Cache)

if props := resp.StorageTargetProperties; props != nil {
if props := resp.BasicStorageTargetProperties; props != nil {
props, ok := props.AsClfsTargetProperties()
if !ok {
return fmt.Errorf("The type of this HPC Cache Target %q (Resource Group %q, Cahe %q) is not a Blob Target", id.Name, id.ResourceGroup, id.Cache)
}

storageContainerId := ""
if props.Clfs != nil && props.Clfs.Target != nil {
storageContainerId = *props.Clfs.Target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

azSchema "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/schema"

"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2019-11-01/storagecache"
"github.com/Azure/azure-sdk-for-go/services/storagecache/mgmt/2020-03-01/storagecache"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
Expand Down Expand Up @@ -129,9 +129,9 @@ func resourceArmHPCCacheNFSTargetCreateOrUpdate(d *schema.ResourceData, meta int

// Construct parameters
param := &storagecache.StorageTarget{
StorageTargetProperties: &storagecache.StorageTargetProperties{
BasicStorageTargetProperties: &storagecache.Nfs3TargetProperties{
Junctions: expandNamespaceJunctions(d.Get("namespace_junction").(*schema.Set).List()),
TargetType: storagecache.StorageTargetTypeNfs3,
TargetType: storagecache.TargetTypeNfs3,
Nfs3: &storagecache.Nfs3Target{
Target: utils.String(d.Get("target_host_name").(string)),
UsageModel: utils.String(d.Get("usage_model").(string)),
Expand Down Expand Up @@ -186,7 +186,11 @@ func resourceArmHPCCacheNFSTargetRead(d *schema.ResourceData, meta interface{})
d.Set("resource_group_name", id.ResourceGroup)
d.Set("cache_name", id.Cache)

if props := resp.StorageTargetProperties; props != nil {
if props := resp.BasicStorageTargetProperties; props != nil {
props, ok := props.AsNfs3TargetProperties()
if !ok {
return fmt.Errorf("The type of this HPC Cache Target %q (Resource Group %q, Cahe %q) is not a NFS Target", id.Name, id.ResourceGroup, id.Cache)
}
if nfs3 := props.Nfs3; nfs3 != nil {
d.Set("target_host_name", nfs3.Target)
d.Set("usage_model", nfs3.UsageModel)
Expand Down
159 changes: 136 additions & 23 deletions azurerm/internal/services/storage/tests/resource_arm_hpc_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,78 @@ func TestAccAzureRMHPCCache_basic(t *testing.T) {
})
}

func TestAccAzureRMHPCCache_mtu(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMHPCCacheDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMHPCCache_mtu(data, 1000),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMHPCCache_mtu(data, 1500),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMHPCCache_mtu(data, 1000),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMHPCCache_rootSquash(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMHPCCacheDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMHPCCache_rootSquash(data, false),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMHPCCache_rootSquash(data, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMHPCCache_rootSquash(data, true),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMHPCCacheExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "mount_addresses.#"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMHPCCache_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_hpc_cache", "test")
resource.ParallelTest(t, resource.TestCase{
Expand Down Expand Up @@ -101,29 +173,9 @@ func testCheckAzureRMHPCCacheDestroy(s *terraform.State) error {
}

func testAccAzureRMHPCCache_basic(data acceptance.TestData) string {
template := testAccAzureRMHPCCache_template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctest-VN-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestsub-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.2.0/24"
}
%s

resource "azurerm_hpc_cache" "test" {
name = "acctest-HPCC-%d"
Expand All @@ -133,7 +185,7 @@ resource "azurerm_hpc_cache" "test" {
subnet_id = azurerm_subnet.test.id
sku_name = "Standard_2G"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
`, template, data.RandomInteger)
}

func testAccAzureRMHPCCahce_requiresImport(data acceptance.TestData) string {
Expand All @@ -151,3 +203,64 @@ resource "azurerm_hpc_cache" "import" {
}
`, template)
}

func testAccAzureRMHPCCache_mtu(data acceptance.TestData, mtu int) string {
template := testAccAzureRMHPCCache_template(data)
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"
mtu = %d
}
`, template, data.RandomInteger, mtu)
}

func testAccAzureRMHPCCache_rootSquash(data acceptance.TestData, enable bool) string {
template := testAccAzureRMHPCCache_template(data)
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"
root_squash_enabled = %t
}
`, template, data.RandomInteger, enable)
}

func testAccAzureRMHPCCache_template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}

resource "azurerm_virtual_network" "test" {
name = "acctest-VN-%d"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_subnet" "test" {
name = "acctestsub-%d"
resource_group_name = azurerm_resource_group.test.name
virtual_network_name = azurerm_virtual_network.test.name
address_prefix = "10.0.2.0/24"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}
Loading