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

New Resource: azurerm_data_lake_store #1219

Merged
merged 26 commits into from
May 20, 2018
Merged
Show file tree
Hide file tree
Changes from 16 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
11 changes: 11 additions & 0 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2017-09-30/containerservice"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
"github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account"
"github.com/Azure/azure-sdk-for-go/services/dns/mgmt/2016-04-01/dns"
"github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2017-09-15-preview/eventgrid"
"github.com/Azure/azure-sdk-for-go/services/eventhub/mgmt/2017-04-01/eventhub"
Expand Down Expand Up @@ -137,6 +138,9 @@ type ArmClient struct {
sqlServerAzureADAdministratorsClient sql.ServerAzureADAdministratorsClient
sqlVirtualNetworkRulesClient sql.VirtualNetworkRulesClient

// Data Lake Store
dataLakeStoreAccountClient account.AccountsClient

// KeyVault
keyVaultClient keyvault.VaultsClient
keyVaultManagementClient keyVault.BaseClient
Expand Down Expand Up @@ -370,6 +374,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) {
client.registerContainerServicesClients(endpoint, c.SubscriptionID, auth)
client.registerCosmosDBClients(endpoint, c.SubscriptionID, auth, sender)
client.registerDatabases(endpoint, c.SubscriptionID, auth, sender)
client.registerDataLakeStoreAccountClients(endpoint, c.SubscriptionID, auth, sender)
client.registerDeviceClients(endpoint, c.SubscriptionID, auth, sender)
client.registerDNSClients(endpoint, c.SubscriptionID, auth, sender)
client.registerEventGridClients(endpoint, c.SubscriptionID, auth, sender)
Expand Down Expand Up @@ -628,6 +633,12 @@ func (c *ArmClient) registerDatabases(endpoint, subscriptionId string, auth auto
c.sqlVirtualNetworkRulesClient = sqlVNRClient
}

func (c *ArmClient) registerDataLakeStoreAccountClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
dataLakeStoreAccountClient := account.NewAccountsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&dataLakeStoreAccountClient.Client, auth)
c.dataLakeStoreAccountClient = dataLakeStoreAccountClient
}

func (c *ArmClient) registerDeviceClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) {
iotClient := devices.NewIotHubResourceClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&iotClient.Client, auth)
Expand Down
66 changes: 66 additions & 0 deletions azurerm/data_source_data_lake_store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package azurerm

import (
"fmt"

"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmDataLakeStoreAccount() *schema.Resource {
return &schema.Resource{
Read: dataSourceArmDateLakeStoreAccountRead,

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"resource_group_name": resourceGroupNameForDataSourceSchema(),

"location": locationForDataSourceSchema(),

"tier": {
Type: schema.TypeString,
Optional: true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe this should be computed with no default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup has to be computed

Default: false,
},

"tags": tagsForDataSourceSchema(),
},
}
}

func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).dataLakeStoreAccountClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
d.SetId("")
Copy link
Collaborator

@WodansSon WodansSon May 16, 2018

Choose a reason for hiding this comment

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

Can you add a warning message here that it wasn't found? Something like...
log.Printf("[WARN] DataLakeStoreAccount '%s' was not found (resource group '%s')", name, resourcGroup)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, in next commit

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

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
if location := resp.Location; location != nil {
d.Set("location", azureRMNormalizeLocation(*location))
}

if tier := resp.DataLakeStoreAccountProperties; tier != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we assign this to properties not tier for clarity?

Copy link
Contributor Author

@paktek123 paktek123 May 17, 2018

Choose a reason for hiding this comment

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

done

d.Set("tier", string(tier.CurrentTier))
}

flattenAndSetTags(d, resp.Tags)

return nil
}
96 changes: 96 additions & 0 deletions azurerm/data_source_data_lake_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package azurerm

import (
"fmt"
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccDataSourceAzureRMDataLakeStore_payasyougo(t *testing.T) {
dataSourceName := "data.azurerm_data_lake_store.test"
rInt := acctest.RandIntRange(1, 999999)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we use acctest.RandInt() like the majority of the other tests?

Copy link
Contributor Author

@paktek123 paktek123 May 17, 2018

Choose a reason for hiding this comment

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

there is a limitation on the name for an ADLS account which has to be between 3 to 24 characters. I wanted to restrict the length of the name to within that limit. RandInt() generates a larger string if I am not mistaken. I will use random string and revert the resource group name to randInt()

location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceDataLakeStore_payasyougo(rInt, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDataLakeStoreExists(dataSourceName),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we also check to make sure that tier is set to its default value here?

resource.TestCheckResourceAttr(dataSourceName, "tier", "Consumption"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in next commit

),
},
},
})
}

func TestAccDataSourceAzureRMDataLakeStore_monthlycommitment(t *testing.T) {
dataSourceName := "data.azurerm_data_lake_store.test"
rInt := acctest.RandIntRange(1, 999999)
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

@paktek123 paktek123 May 17, 2018

Choose a reason for hiding this comment

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

there is a limitation on the name for an ADLS account which has to be between 3 to 24 characters. I wanted to restrict the length of the name to within that limit. RandInt() generates a larger string if I am not mistaken.I will use random string and revert the resource group name to randInt()

location := testLocation()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceDataLakeStore_monthlycommitment(rInt, location),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "tier", "Commitment_1TB"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"),
),
},
},
})
}

func testAccDataSourceDataLakeStore_payasyougo(rInt int, location string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we change this to testAccDataSourceDataLakeStore_basic as we are checking the basic minimum required tf config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, renamed to basic in next commit

return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we formate the terraform in all the tests?

resource "azurerm_resource_group" "test" {
	name     = "acctestRG_%d"
	location = "%s"
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved to 2 spaces (I think thats what I think that means)

name = "acctestRG_%d"
location = "%s"
}

resource "azurerm_data_lake_store" "test" {
name = "acctest%d"
location = "%s"
resource_group_name = "${azurerm_resource_group.test.name}"
tags {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should only be checking required fields in the basic test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup makes sensem, removed tags

hello = "world"
}
}

data "azurerm_data_lake_store" "test" {
name = "${azurerm_data_lake_store.test.name}"
resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}"
}
`, rInt, location, rInt, location)
}

func testAccDataSourceDataLakeStore_monthlycommitment(rInt int, location string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we change this to testAccDataSourceDataLakeStore_tier as that is what we are checking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in next commit

return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG_%d"
location = "%s"
}

resource "azurerm_data_lake_store" "test" {
name = "acctest%d"
location = "%s"
tier = "Commitment_1TB"
resource_group_name = "${azurerm_resource_group.test.name}"
tags {
hello = "world"
}
}

data "azurerm_data_lake_store" "test" {
name = "${azurerm_data_lake_store.test.name}"
resource_group_name = "${azurerm_data_lake_store.test.resource_group_name}"
}
`, rInt, location, rInt, location)
}
54 changes: 54 additions & 0 deletions azurerm/import_arm_data_lake_store_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package azurerm
Copy link
Collaborator

Choose a reason for hiding this comment

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

We are moving away from a separate import test. Lets remove this file and add the following to all the resource tests:

			{
				ResourceName:      resourceName,
				ImportState:       true,
				ImportStateVerify: true,
			},

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, in next commit


import (
"testing"

"github.com/hashicorp/terraform/helper/acctest"
"github.com/hashicorp/terraform/helper/resource"
)

func TestAccAzureRMDataLakeStore_importPayAsYouGo(t *testing.T) {
resourceName := "azurerm_data_lake_store.test"

ri := acctest.RandIntRange(1, 999999)
config := testAccAzureRMDataLakeStore_payasyougo(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMDataLakeStoreDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccAzureRMDataLakeStore_importTags(t *testing.T) {
resourceName := "azurerm_data_lake_store.test"

ri := acctest.RandIntRange(1, 999999)
config := testAccAzureRMDataLakeStore_withTags(ri, testLocation())

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMDataLakeStoreDestroy,
Steps: []resource.TestStep{
{
Config: config,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
3 changes: 3 additions & 0 deletions azurerm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_client_config": dataSourceArmClientConfig(),
"azurerm_cosmosdb_account": dataSourceArmCosmosDBAccount(),
"azurerm_dns_zone": dataSourceArmDnsZone(),
"azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: alphabetically this should be above azurerm_dns_zone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved, in next commit

"azurerm_eventhub_namespace": dataSourceEventHubNamespace(),
"azurerm_image": dataSourceArmImage(),
"azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(),
Expand Down Expand Up @@ -130,6 +131,7 @@ func Provider() terraform.ResourceProvider {
"azurerm_container_service": resourceArmContainerService(),
"azurerm_container_group": resourceArmContainerGroup(),
"azurerm_cosmosdb_account": resourceArmCosmosDBAccount(),
"azurerm_data_lake_store": resourceArmDataLakeStore(),
"azurerm_dns_a_record": resourceArmDnsARecord(),
"azurerm_dns_aaaa_record": resourceArmDnsAAAARecord(),
"azurerm_dns_cname_record": resourceArmDnsCNameRecord(),
Expand Down Expand Up @@ -334,6 +336,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider
"Microsoft.DBforPostgreSQL": {},
"Microsoft.Devices": {},
"Microsoft.DocumentDB": {},
"Microsoft.DataLakeStore": {},
Copy link
Collaborator

Choose a reason for hiding this comment

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

minor: alphabetically this should be higher up

Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved in next commit

"Microsoft.EventGrid": {},
"Microsoft.EventHub": {},
"Microsoft.KeyVault": {},
Expand Down
Loading