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_data_lake_store - support for encryption/firewall properties #1623

Merged
merged 6 commits into from
Jul 24, 2018
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
30 changes: 29 additions & 1 deletion azurerm/data_source_data_lake_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ func dataSourceArmDataLakeStoreAccount() *schema.Resource {
Computed: true,
},

"encryption_state": {
Type: schema.TypeString,
Computed: true,
},

"encryption_type": {
Type: schema.TypeString,
Computed: true,
},

"firewall_state": {
Type: schema.TypeString,
Computed: true,
},

"firewall_allow_azure_ips": {
Type: schema.TypeString,
Computed: true,
},

"tags": tagsForDataSourceSchema(),
},
}
Expand All @@ -42,7 +62,7 @@ func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interfac
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] DataLakeStoreAccount '%s' was not found (resource group '%s')", name, resourceGroup)
log.Printf("[WARN] DataLakeStoreAccount %q was not found (Resource Group %q)", name, resourceGroup)
d.SetId("")
return nil
}
Expand All @@ -59,6 +79,14 @@ func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interfac

if properties := resp.DataLakeStoreAccountProperties; properties != nil {
d.Set("tier", string(properties.CurrentTier))

d.Set("encryption_state", string(properties.EncryptionState))
d.Set("firewall_allow_azure_ips", string(properties.FirewallAllowAzureIps))
d.Set("firewall_state", string(properties.FirewallState))

if config := properties.EncryptionConfig; config != nil {
d.Set("encryption_type", string(config.Type))
}
}

flattenAndSetTags(d, resp.Tags)
Expand Down
101 changes: 85 additions & 16 deletions azurerm/resource_arm_data_lake_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"log"

"github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/response"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/suppress"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"

"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
)

func resourceArmDataLakeStore() *schema.Resource {
Expand All @@ -20,6 +19,7 @@ func resourceArmDataLakeStore() *schema.Resource {
Read: resourceArmDateLakeStoreRead,
Update: resourceArmDateLakeStoreUpdate,
Delete: resourceArmDateLakeStoreDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand All @@ -40,7 +40,7 @@ func resourceArmDataLakeStore() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: string(account.Consumption),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
DiffSuppressFunc: suppress.CaseDifference,
ValidateFunc: validation.StringInSlice([]string{
string(account.Consumption),
string(account.Commitment1TB),
Expand All @@ -52,6 +52,51 @@ func resourceArmDataLakeStore() *schema.Resource {
}, true),
},

"encryption_state": {
Type: schema.TypeString,
Optional: true,
Default: string(account.Enabled),
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(account.Enabled),
string(account.Disabled),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
},

"encryption_type": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(account.ServiceManaged),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
},

"firewall_state": {
Type: schema.TypeString,
Optional: true,
Default: string(account.FirewallStateEnabled),
ValidateFunc: validation.StringInSlice([]string{
string(account.FirewallStateEnabled),
string(account.FirewallStateDisabled),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
},

"firewall_allow_azure_ips": {
Type: schema.TypeString,
Optional: true,
Default: string(account.FirewallAllowAzureIpsStateEnabled),
ValidateFunc: validation.StringInSlice([]string{
string(account.FirewallAllowAzureIpsStateEnabled),
string(account.FirewallAllowAzureIpsStateDisabled),
}, true),
DiffSuppressFunc: suppress.CaseDifference,
},

"tags": tagsSchema(),
},
}
Expand All @@ -65,15 +110,26 @@ func resourceArmDateLakeStoreCreate(d *schema.ResourceData, meta interface{}) er
location := azureRMNormalizeLocation(d.Get("location").(string))
resourceGroup := d.Get("resource_group_name").(string)
tier := d.Get("tier").(string)

encryptionState := account.EncryptionState(d.Get("encryption_state").(string))
encryptionType := account.EncryptionConfigType(d.Get("encryption_type").(string))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do a d.GetOk with this value being Optional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, since otherwise there's no way to clear it (required when encryption is disabled)

firewallState := account.FirewallState(d.Get("firewall_state").(string))
firewallAllowAzureIPs := account.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string))
tags := d.Get("tags").(map[string]interface{})

log.Printf("[INFO] preparing arguments for Azure ARM Date Lake Store creation %q (Resource Group %q)", name, resourceGroup)
log.Printf("[INFO] preparing arguments for Data Lake Store creation %q (Resource Group %q)", name, resourceGroup)

dateLakeStore := account.CreateDataLakeStoreAccountParameters{
Location: &location,
Tags: expandTags(tags),
CreateDataLakeStoreAccountProperties: &account.CreateDataLakeStoreAccountProperties{
NewTier: account.TierType(tier),
NewTier: account.TierType(tier),
FirewallState: firewallState,
FirewallAllowAzureIps: firewallAllowAzureIPs,
EncryptionState: encryptionState,
EncryptionConfig: &account.EncryptionConfig{
Type: encryptionType,
},
},
}

Expand All @@ -82,7 +138,7 @@ func resourceArmDateLakeStoreCreate(d *schema.ResourceData, meta interface{}) er
return fmt.Errorf("Error issuing create request for Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err)
}

err = future.WaitForCompletion(ctx, client.Client)
err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error creating Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err)
}
Expand All @@ -106,22 +162,26 @@ func resourceArmDateLakeStoreUpdate(d *schema.ResourceData, meta interface{}) er

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
newTags := d.Get("tags").(map[string]interface{})
newTier := d.Get("tier").(string)
tier := d.Get("tier").(string)
firewallState := account.FirewallState(d.Get("firewall_state").(string))
firewallAllowAzureIPs := account.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string))
tags := d.Get("tags").(map[string]interface{})

props := account.UpdateDataLakeStoreAccountParameters{
Tags: expandTags(newTags),
UpdateDataLakeStoreAccountProperties: &account.UpdateDataLakeStoreAccountProperties{
NewTier: account.TierType(newTier),
NewTier: account.TierType(tier),
FirewallState: firewallState,
FirewallAllowAzureIps: firewallAllowAzureIPs,
},
Tags: expandTags(tags),
}

future, err := client.Update(ctx, resourceGroup, name, props)
if err != nil {
return fmt.Errorf("Error issuing update request for Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err)
}

err = future.WaitForCompletion(ctx, client.Client)
err = future.WaitForCompletionRef(ctx, client.Client)
if err != nil {
return fmt.Errorf("Error waiting for the update of Data Lake Store %q (Resource Group %q) to commplete: %+v", name, resourceGroup, err)
}
Expand All @@ -143,10 +203,11 @@ func resourceArmDateLakeStoreRead(d *schema.ResourceData, meta interface{}) erro
resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
log.Printf("[WARN] DataLakeStoreAccount '%s' was not found (resource group '%s')", name, resourceGroup)
log.Printf("[WARN] Data Lake Store Account %q was not found (Resource Group %q)", name, resourceGroup)
d.SetId("")
return nil
}

return fmt.Errorf("Error making Read request on Azure Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err)
}

Expand All @@ -156,8 +217,16 @@ func resourceArmDateLakeStoreRead(d *schema.ResourceData, meta interface{}) erro
d.Set("location", azureRMNormalizeLocation(*location))
}

if tier := resp.DataLakeStoreAccountProperties; tier != nil {
d.Set("tier", string(tier.CurrentTier))
if properties := resp.DataLakeStoreAccountProperties; properties != nil {
d.Set("tier", string(properties.CurrentTier))

d.Set("encryption_state", string(properties.EncryptionState))
d.Set("firewall_state", string(properties.FirewallState))
d.Set("firewall_allow_azure_ips", string(properties.FirewallAllowAzureIps))

if config := properties.EncryptionConfig; config != nil {
d.Set("encryption_type", string(config.Type))
}
}

flattenAndSetTags(d, resp.Tags)
Expand Down
114 changes: 110 additions & 4 deletions azurerm/resource_arm_data_lake_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestAccAzureRMDataLakeStore_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "tier", "Consumption"),
resource.TestCheckResourceAttr(resourceName, "encryption_state", "Enabled"),
resource.TestCheckResourceAttr(resourceName, "encryption_type", "ServiceManaged"),
),
},
{
Expand Down Expand Up @@ -61,6 +63,78 @@ func TestAccAzureRMDataLakeStore_tier(t *testing.T) {
})
}

func TestAccAzureRMDataLakeStore_encryptionDisabled(t *testing.T) {
resourceName := "azurerm_data_lake_store.test"
ri := acctest.RandInt()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMDataLakeStoreDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDataLakeStore_encryptionDisabled(ri, testLocation()),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "encryption_state", "Disabled"),
resource.TestCheckResourceAttr(resourceName, "encryption_type", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMDataLakeStore_firewallUpdate(t *testing.T) {
resourceName := "azurerm_data_lake_store.test"
ri := acctest.RandInt()
location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMDataLakeStoreDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Enabled", "Enabled"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "firewall_state", "Enabled"),
resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Enabled"),
),
},
{
Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Enabled", "Disabled"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "firewall_state", "Enabled"),
resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Disabled"),
),
},
{
Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Disabled", "Enabled"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "firewall_state", "Disabled"),
resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Enabled"),
),
},
{
Config: testAccAzureRMDataLakeStore_firewall(ri, location, "Disabled", "Disabled"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "firewall_state", "Disabled"),
resource.TestCheckResourceAttr(resourceName, "firewall_allow_azure_ips", "Disabled"),
),
},
},
})
}

func TestAccAzureRMDataLakeStore_withTags(t *testing.T) {
resourceName := "azurerm_data_lake_store.test"
ri := acctest.RandInt()
Expand Down Expand Up @@ -168,20 +242,52 @@ resource "azurerm_data_lake_store" "test" {
func testAccAzureRMDataLakeStore_tier(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_data_lake_store" "test" {
name = "acctest%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"

tier = "Commitment_1TB"
}
`, rInt, location, strconv.Itoa(rInt)[0:15])
}

func testAccAzureRMDataLakeStore_encryptionDisabled(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_data_lake_store" "test" {
name = "acctest%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
encryption_state = "Disabled"
}
`, rInt, location, strconv.Itoa(rInt)[0:15])
}

func testAccAzureRMDataLakeStore_firewall(rInt int, location string, firewallState string, firewallAllowAzureIPs string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_data_lake_store" "test" {
name = "acctest%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
firewall_state = "%s"
firewall_allow_azure_ips = "%s"
}
`, rInt, location, strconv.Itoa(rInt)[0:15], firewallState, firewallAllowAzureIPs)
}

func testAccAzureRMDataLakeStore_withTags(rInt int, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand All @@ -193,7 +299,7 @@ resource "azurerm_data_lake_store" "test" {
name = "acctest%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"

tags {
environment = "Production"
cost_center = "MSFT"
Expand All @@ -213,7 +319,7 @@ resource "azurerm_data_lake_store" "test" {
name = "acctest%s"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"

tags {
environment = "staging"
}
Expand Down
Loading