Skip to content

Commit

Permalink
add is_hns_enabled to storage account for data lake storage gen2
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Afflerbach authored and Robin Afflerbach committed Mar 12, 2019
1 parent daba2bd commit 7bf3fdc
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 2,762 deletions.
2 changes: 1 addition & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/search/mgmt/2015-08-19/search"
"github.com/Azure/azure-sdk-for-go/services/servicebus/mgmt/2017-04-01/servicebus"
"github.com/Azure/azure-sdk-for-go/services/servicefabric/mgmt/2018-02-01/servicefabric"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-02-01/storage"
"github.com/Azure/azure-sdk-for-go/services/trafficmanager/mgmt/2017-05-01/trafficmanager"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"

Expand Down
6 changes: 6 additions & 0 deletions azurerm/data_source_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ func dataSourceArmStorageAccount() *schema.Resource {
Computed: true,
},

"is_hns_enabled": {
Type: schema.TypeBool,
Computed: true,
},

"primary_location": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -236,6 +241,7 @@ func dataSourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) e
if props := resp.AccountProperties; props != nil {
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("is_hns_enabled", props.IsHnsEnabled)

if customDomain := props.CustomDomain; customDomain != nil {
if err := d.Set("custom_domain", flattenStorageAccountCustomDomain(customDomain)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_container_registry_migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"

"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-02-01/storage"
"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/terraform"
)
Expand Down
16 changes: 15 additions & 1 deletion azurerm/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"regexp"
"strings"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-02-01/storage"
"github.com/hashicorp/go-getter/helper/url"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -145,6 +145,13 @@ func resourceArmStorageAccount() *schema.Resource {
Optional: true,
},

"is_hns_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},

"network_rules": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -385,6 +392,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
enableBlobEncryption := d.Get("enable_blob_encryption").(bool)
enableFileEncryption := d.Get("enable_file_encryption").(bool)
enableHTTPSTrafficOnly := d.Get("enable_https_traffic_only").(bool)
isHnsEnabled := d.Get("is_hns_enabled").(bool)

accountTier := d.Get("account_tier").(string)
replicationType := d.Get("account_replication_type").(string)
Expand Down Expand Up @@ -413,6 +421,7 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
},
EnableHTTPSTrafficOnly: &enableHTTPSTrafficOnly,
NetworkRuleSet: networkRules,
IsHnsEnabled: &isHnsEnabled,
},
}

Expand Down Expand Up @@ -441,6 +450,10 @@ func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) e
}

parameters.AccountPropertiesCreateParameters.AccessTier = storage.AccessTier(accessTier.(string))
} else {
if isHnsEnabled {
return fmt.Errorf("`is_hns_enabled` can only be used with account kinds `StorageV2` and `BlobStorage`")
}
}

// Create
Expand Down Expand Up @@ -679,6 +692,7 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
if props := resp.AccountProperties; props != nil {
d.Set("access_tier", props.AccessTier)
d.Set("enable_https_traffic_only", props.EnableHTTPSTrafficOnly)
d.Set("is_hns_enabled", props.IsHnsEnabled)

if customDomain := props.CustomDomain; customDomain != nil {
if err := d.Set("custom_domain", flattenStorageAccountCustomDomain(customDomain)); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_storage_account_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-02-01/storage"
"github.com/hashicorp/terraform/terraform"
)

Expand Down
76 changes: 76 additions & 0 deletions azurerm/resource_arm_storage_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,42 @@ func TestAccAzureRMStorageAccount_enableHttpsTrafficOnly(t *testing.T) {
})
}

func TestAccAzureRMStorageAccount_isHnsEnabled(t *testing.T) {
resourceName := "azurerm_storage_account.testsa"
ri := tf.AccRandTimeInt()
rs := acctest.RandString(4)
location := testLocation()
preConfig := testAccAzureRMStorageAccount_isHnsEnabledTrue(ri, rs, location)
postConfig := testAccAzureRMStorageAccount_isHnsEnabledFalse(ri, rs, location)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
{
Config: preConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(resourceName),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "is_hns_enabled", "true"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: postConfig,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(resourceName),
resource.TestCheckResourceAttr("azurerm_storage_account.testsa", "is_hns_enabled", "false"),
),
},
},
})
}

func TestAccAzureRMStorageAccount_blobStorageWithUpdate(t *testing.T) {
resourceName := "azurerm_storage_account.testsa"
ri := tf.AccRandTimeInt()
Expand Down Expand Up @@ -856,6 +892,46 @@ resource "azurerm_storage_account" "testsa" {
`, rInt, location, rString)
}

func testAccAzureRMStorageAccount_isHnsEnabledTrue(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
name = "acctestAzureRMSA-%d"
location = "%s"
}
resource "azurerm_storage_account" "testsa" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "${azurerm_resource_group.testrg.location}"
account_kind = "StorageV2"
account_tier = "Standard"
account_replication_type = "LRS"
is_hns_enabled = true
}
`, rInt, location, rString)
}

func testAccAzureRMStorageAccount_isHnsEnabledFalse(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
name = "acctestAzureRMSA-%d"
location = "%s"
}
resource "azurerm_storage_account" "testsa" {
name = "unlikely23exst2acct%s"
resource_group_name = "${azurerm_resource_group.testrg.name}"
location = "${azurerm_resource_group.testrg.location}"
account_kind = "StorageV2"
account_tier = "Standard"
account_replication_type = "LRS"
is_hns_enabled = false
}
`, rInt, location, rString)
}

func testAccAzureRMStorageAccount_blobStorage(rInt int, rString string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "testrg" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.6.3 // indirect
github.com/hashicorp/go-azure-helpers v0.0.0-20181211121309-38db96513363
github.com/hashicorp/go-cleanhttp v0.0.0-20170211013415-3573b8b52aa7 // indirect
github.com/hashicorp/go-getter v0.0.0-20180226183729-64040d90d4ab // indirect
github.com/hashicorp/go-getter v0.0.0-20180226183729-64040d90d4ab
github.com/hashicorp/go-hclog v0.0.0-20170903163258-8105cc0a3736 // indirect
github.com/hashicorp/go-multierror v1.0.0
github.com/hashicorp/go-plugin v0.0.0-20170816151819-a5174f84d7f8 // indirect
Expand Down
Loading

0 comments on commit 7bf3fdc

Please sign in to comment.