From a7a40509e32e93e2531923e7d63a3ff87180b459 Mon Sep 17 00:00:00 2001 From: Neeran Gul Date: Fri, 4 May 2018 11:22:15 +0100 Subject: [PATCH 01/23] adding adls client and account resources --- azurerm/config.go | 11 + azurerm/data_source_data_lake_store.go | 64 ++++++ azurerm/data_source_data_lake_store_test.go | 96 +++++++++ azurerm/import_arm_data_lake_store_test.go | 54 +++++ azurerm/resource_arm_cdn_profile_test.go | 2 +- azurerm/resource_arm_data_lake_store.go | 184 +++++++++++++++++ azurerm/resource_arm_data_lake_store_test.go | 204 +++++++++++++++++++ 7 files changed, 614 insertions(+), 1 deletion(-) create mode 100644 azurerm/data_source_data_lake_store.go create mode 100644 azurerm/data_source_data_lake_store_test.go create mode 100644 azurerm/import_arm_data_lake_store_test.go create mode 100644 azurerm/resource_arm_data_lake_store.go create mode 100644 azurerm/resource_arm_data_lake_store_test.go diff --git a/azurerm/config.go b/azurerm/config.go index 06c646de77c9..8b73059373a0 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -20,6 +20,7 @@ import ( "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/dns/mgmt/2016-04-01/dns" + "github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account" "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" "github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" @@ -137,6 +138,9 @@ type ArmClient struct { sqlServerAzureADAdministratorsClient sql.ServerAzureADAdministratorsClient sqlVirtualNetworkRulesClient sql.VirtualNetworkRulesClient + // Data Lake Store + dataLakeStoreAccount account.AccountsClient + // KeyVault keyVaultClient keyvault.VaultsClient keyVaultManagementClient keyVault.BaseClient @@ -372,6 +376,7 @@ func getArmClient(c *authentication.Config) (*ArmClient, error) { client.registerDatabases(endpoint, c.SubscriptionID, auth, sender) client.registerDeviceClients(endpoint, c.SubscriptionID, auth, sender) client.registerDNSClients(endpoint, c.SubscriptionID, auth, sender) + client.registerDataLakeStoreAccountClients(endpoint, c.SubscriptionID, auth, sender) client.registerEventGridClients(endpoint, c.SubscriptionID, auth, sender) client.registerEventHubClients(endpoint, c.SubscriptionID, auth, sender) client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth, sender) @@ -644,6 +649,12 @@ func (c *ArmClient) registerDNSClients(endpoint, subscriptionId string, auth aut c.zonesClient = zo } +func (c *ArmClient) registerDataLakeStoreAccountClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { + dataLakeStoreAccountClient := accounts.NewAccountsClientWithBaseURI(endpoint, subscriptionId) + c.configureClient(&dataLakeStoreAccountClient.Client, auth) + c.dataLakeStoreAccountClient = dataLakeStoreAccountClient +} + func (c *ArmClient) registerEventGridClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { egtc := eventgrid.NewTopicsClientWithBaseURI(endpoint, subscriptionId) setUserAgent(&egtc.Client) diff --git a/azurerm/data_source_data_lake_store.go b/azurerm/data_source_data_lake_store.go new file mode 100644 index 000000000000..2b8f48640e9b --- /dev/null +++ b/azurerm/data_source_data_lake_store.go @@ -0,0 +1,64 @@ +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, + 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("") + 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)) + } + d.Set("tier", string(resp.Type)) + + + flattenAndSetTags(d, resp.Tags) + + return nil +} diff --git a/azurerm/data_source_data_lake_store_test.go b/azurerm/data_source_data_lake_store_test.go new file mode 100644 index 000000000000..21b68e28eaeb --- /dev/null +++ b/azurerm/data_source_data_lake_store_test.go @@ -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.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( + resource.testCheckAzureRMDataLakeStoreExists(dataSourceName), + ), + }, + }, + }) +} + +func TestAccDataSourceAzureRMDataLakeStore_monthlycommitment(t *testing.T) { + dataSourceName := "data.azurerm_data_lake_store.test" + rInt := acctest.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 { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestRG_%d" + location = "%s" +} + +resource "azurerm_data_lake_store" "test" { + name = "acctestdatalakestore%d" + location = "%s" + 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) +} + +func testAccDataSourceDataLakeStore_monthlycommitment(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 = "acctestdatalakestore%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) +} diff --git a/azurerm/import_arm_data_lake_store_test.go b/azurerm/import_arm_data_lake_store_test.go new file mode 100644 index 000000000000..f70057bd58a3 --- /dev/null +++ b/azurerm/import_arm_data_lake_store_test.go @@ -0,0 +1,54 @@ +package azurerm + +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.RandInt() + 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_importPayAsYouGoWithTags(t *testing.T) { + resourceName := "azurerm_data_lake_store.test" + + ri := acctest.RandInt() + config := testAccAzureDataLakeStore_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, + }, + }, + }) +} diff --git a/azurerm/resource_arm_cdn_profile_test.go b/azurerm/resource_arm_cdn_profile_test.go index c8e30c42f028..9bf1f8a2446a 100644 --- a/azurerm/resource_arm_cdn_profile_test.go +++ b/azurerm/resource_arm_cdn_profile_test.go @@ -12,7 +12,7 @@ import ( ) func init() { - resource.AddTestSweepers("azurerm_cdn_profile", &resource.Sweeper{ + resource.AddTestSweepers("azurerm_data_lake_store", &resource.Sweeper{ Name: "azurerm_cdn_profile", F: testSweepCDNProfiles, }) diff --git a/azurerm/resource_arm_data_lake_store.go b/azurerm/resource_arm_data_lake_store.go new file mode 100644 index 000000000000..ee5843f867c9 --- /dev/null +++ b/azurerm/resource_arm_data_lake_store.go @@ -0,0 +1,184 @@ +package azurerm + +import ( + "fmt" + "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/response" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDateLakeStore() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDateLakeStoreCreate, + Read: resourceArmDateLakeStoreRead, + Update: resourceArmDateLakeStoreUpdate, + Delete: resourceArmDateLakeStoreDelete, + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + + "location": locationSchema(), + + "resource_group_name": resourceGroupNameSchema(), + + "tier": { + Type: schema.TypeString, + Required: false, + ForceNew: false, + DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + }, + + "tags": tagsSchema(), + }, + } +} + +func resourceArmDateLakeStoreCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataLakeStoreAccountClient + ctx := meta.(*ArmClient).StopContext + + log.Printf("[INFO] preparing arguments for Azure ARM Date Lake Store creation.") + + name := d.Get("name").(string) + location := azureRMNormalizeLocation(d.Get("location").(string)) + resGroup := d.Get("resource_group_name").(string) + tier := d.Get("tier").(string) + tags := d.Get("tags").(map[string]interface{}) + + dateLakeStore := accounts.CreateDataLakeStoreAccountParameters{ + Location: &location, + Tags: expandTags(tags), + CreateDataLakeStoreAccountProperties: &accounts.CreateDataLakeStoreAccountProperties{ + NewTier: tier, + }, + } + + future, err := client.Create(ctx, resGroup, name, dateLakeStore) + if err != nil { + return err + } + + err = future.WaitForCompletion(ctx, client.Client) + if err != nil { + return err + } + + read, err := client.Get(ctx, resGroup, name) + if err != nil { + return err + } + if read.ID == nil { + return fmt.Errorf("Cannot read Data Lake Store %s (resource group %s) ID", name, resGroup) + } + + d.SetId(*read.ID) + + return resourceArmDateLakeStoreRead(d, meta) +} + +func resourceArmDateLakeStoreUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataLakeStoreAccountClient + ctx := meta.(*ArmClient).StopContext + + if !d.HasChange("tags") { + return nil + } + + name := d.Get("name").(string) + resourceGroup := d.Get("resource_group_name").(string) + newTags := d.Get("tags").(map[string]interface{}) + newTier := d.Get("tier").(string) + + props := accounts.UpdateDataLakeStoreAccountParameters{ + Tags: expandTags(newTags), + UpdateDataLakeStoreAccountProperties: &accounts.UpdateDataLakeStoreAccountProperties{ + NewTier: newTier, + } + } + + 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) + 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) + } + + return resourceArmDateLakeStoreRead(d, meta) +} + +func resourceArmDateLakeStoreRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataLakeStoreAccountClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + name := id.Path["accounts"] + + resp, err := client.Get(ctx, resourceGroup, name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + return fmt.Errorf("Error making Read request on Azure Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + d.Set("name", name) + d.Set("resource_group_name", resourceGroup) + if location := resp.Location; location != nil { + d.Set("location", azureRMNormalizeLocation(*location)) + } + + d.Set("tier", resp.Type) + + flattenAndSetTags(d, resp.Tags) + + return nil +} + +func resourceArmDateLakeStoreDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataLakeStoreAccountClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + + resourceGroup := id.ResourceGroup + name := id.Path["accounts"] + future, err := client.Delete(ctx, resourceGroup, name) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error issuing delete request for Azure Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err) + } + + err = future.WaitForCompletion(ctx, client.Client) + if err != nil { + if response.WasNotFound(future.Response()) { + return nil + } + return fmt.Errorf("Error waiting for Azure Data Lake Store %q (Resource Group %q) to be deleted: %+v", name, resourceGroup, err) + } + + return err +} diff --git a/azurerm/resource_arm_data_lake_store_test.go b/azurerm/resource_arm_data_lake_store_test.go new file mode 100644 index 000000000000..39fe00aa725d --- /dev/null +++ b/azurerm/resource_arm_data_lake_store_test.go @@ -0,0 +1,204 @@ +package azurerm + +import ( + "fmt" + "log" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/acctest" + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" +) + +func TestAccAzureRMDataLakeStore_payasyougo(t *testing.T) { + resourceName := "azurerm_data_lake_store.test" + ri := acctest.RandInt() + config := testAccAzureRMDataLakeStore_payasyougo(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataLakeStoreExists(resourceName), + ), + }, + }, + }) +} + +func TestAccAzureRMDataLakeStore_monthlycommitment(t *testing.T) { + resourceName := "azurerm_data_lake_store.test" + ri := acctest.RandInt() + config := TestAccAzureRMDataLakeStore_monthlycommitment(ri, testLocation()) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataLakeStoreExists(resourceName), + ), + }, + }, + }) +} + +func TestAccAzureRMDataLakeStore_withTags(t *testing.T) { + resourceName := "azurerm_data_lake_store.test" + ri := acctest.RandInt() + location := testLocation() + preConfig := testAccAzureRMDataLakeStore_withTags(ri, location) + postConfig := testAccAzureRMDataLakeStore_withTagsUpdate(ri, location) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataLakeStoreDestroy, + Steps: []resource.TestStep{ + { + Config: preConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataLakeStoreExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "2"), + ), + }, + { + Config: postConfig, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDnsZoneExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tags.%", "1"), + ), + }, + }, + }) +} + +func testCheckAzureRMDataLakeStoreExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + accountName := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for data lake store: %s", name) + } + + conn := testAccProvider.Meta().(*ArmClient).dataLakeStoreAccountClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := conn.Get(ctx, resourceGroup, accountName) + if err != nil { + return fmt.Errorf("Bad: Get on dataLakeStoreAccountClient: %+v", err) + } + + if resp.StatusCode == http.StatusNotFound { + return fmt.Errorf("Bad: Date Lake Store %q (resource group: %q) does not exist", accountName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMDataLakeStoreDestroy(s *terraform.State) error { + conn := testAccProvider.Meta().(*ArmClient).dataLakeStoreAccountClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_lake_store" { + continue + } + + accountName := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + + resp, err := conn.Get(ctx, resourceGroup, accountName) + if err != nil { + if resp.StatusCode == http.StatusNotFound { + return nil + } + + return err + } + + return fmt.Errorf("Data Lake Store still exists:\n%#v", resp) + } + + return nil +} + +func testAccAzureRMDataLakeStore_payasyougo(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 = "acctestlake%d" + resource_group_name = "${azurerm_resource_group.test.name}" +} +`, rInt, location, rInt) +} + +func TestAccAzureRMDataLakeStore_monthlycommitment(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 = "acctestlake%d" + resource_group_name = "${azurerm_resource_group.test.name}" + tier = "Commitment_1TB" +} +`, rInt, location, rInt) +} + +func testAccAzureRMDataLakeStore_withTags(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 = "acctestlake%d" + resource_group_name = "${azurerm_resource_group.test.name}" + tags { + environment = "Production" + cost_center = "MSFT" + } +} +`, rInt, location, rInt) +} + +func testAccAzureRMDataLakeStore_withTagsUpdate(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 = "acctestlake%d" + resource_group_name = "${azurerm_resource_group.test.name}" + tags { + environment = "staging" + } +} +`, rInt, location, rInt) +} + From 9b4590c5d4198f63e71c0b28cb2befeeaad0eadc Mon Sep 17 00:00:00 2001 From: Neeran Gul Date: Fri, 4 May 2018 12:44:00 +0100 Subject: [PATCH 02/23] fixing errors --- azurerm/config.go | 6 +++--- azurerm/data_source_data_lake_store.go | 5 ++--- azurerm/data_source_data_lake_store_test.go | 8 ++++---- azurerm/import_arm_data_lake_store_test.go | 4 ++-- azurerm/resource_arm_data_lake_store.go | 21 ++++++++++---------- azurerm/resource_arm_data_lake_store_test.go | 18 +++++++++-------- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index 8b73059373a0..f5f988c4a579 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -19,8 +19,8 @@ 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/dns/mgmt/2016-04-01/dns" "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" "github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" @@ -139,7 +139,7 @@ type ArmClient struct { sqlVirtualNetworkRulesClient sql.VirtualNetworkRulesClient // Data Lake Store - dataLakeStoreAccount account.AccountsClient + dataLakeStoreAccountClient account.AccountsClient // KeyVault keyVaultClient keyvault.VaultsClient @@ -650,7 +650,7 @@ func (c *ArmClient) registerDNSClients(endpoint, subscriptionId string, auth aut } func (c *ArmClient) registerDataLakeStoreAccountClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { - dataLakeStoreAccountClient := accounts.NewAccountsClientWithBaseURI(endpoint, subscriptionId) + dataLakeStoreAccountClient := account.NewAccountsClientWithBaseURI(endpoint, subscriptionId) c.configureClient(&dataLakeStoreAccountClient.Client, auth) c.dataLakeStoreAccountClient = dataLakeStoreAccountClient } diff --git a/azurerm/data_source_data_lake_store.go b/azurerm/data_source_data_lake_store.go index 2b8f48640e9b..e5db925ba599 100644 --- a/azurerm/data_source_data_lake_store.go +++ b/azurerm/data_source_data_lake_store.go @@ -24,7 +24,7 @@ func dataSourceArmDataLakeStoreAccount() *schema.Resource { "tier": { Type: schema.TypeString, Optional: true, - Default: false + Default: false, }, "tags": tagsForDataSourceSchema(), @@ -55,8 +55,7 @@ func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interfac if location := resp.Location; location != nil { d.Set("location", azureRMNormalizeLocation(*location)) } - d.Set("tier", string(resp.Type)) - + d.Set("tier", resp.Type) flattenAndSetTags(d, resp.Tags) diff --git a/azurerm/data_source_data_lake_store_test.go b/azurerm/data_source_data_lake_store_test.go index 21b68e28eaeb..46c4d93cef75 100644 --- a/azurerm/data_source_data_lake_store_test.go +++ b/azurerm/data_source_data_lake_store_test.go @@ -20,7 +20,7 @@ func TestAccDataSourceAzureRMDataLakeStore_payasyougo(t *testing.T) { { Config: testAccDataSourceDataLakeStore_payasyougo(rInt, location), Check: resource.ComposeTestCheckFunc( - resource.testCheckAzureRMDataLakeStoreExists(dataSourceName), + testCheckAzureRMDataLakeStoreExists(dataSourceName), ), }, }, @@ -41,7 +41,7 @@ func TestAccDataSourceAzureRMDataLakeStore_monthlycommitment(t *testing.T) { Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(dataSourceName, "tier", "Commitment_1TB"), resource.TestCheckResourceAttr(dataSourceName, "tags.%", "1"), - resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world") + resource.TestCheckResourceAttr(dataSourceName, "tags.hello", "world"), ), }, }, @@ -68,7 +68,7 @@ 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) +`, rInt, location, rInt, location) } func testAccDataSourceDataLakeStore_monthlycommitment(rInt int, location string) string { @@ -92,5 +92,5 @@ 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) +`, rInt, location, rInt, location) } diff --git a/azurerm/import_arm_data_lake_store_test.go b/azurerm/import_arm_data_lake_store_test.go index f70057bd58a3..77e33d416bd1 100644 --- a/azurerm/import_arm_data_lake_store_test.go +++ b/azurerm/import_arm_data_lake_store_test.go @@ -30,11 +30,11 @@ func TestAccAzureRMDataLakeStore_importPayAsYouGo(t *testing.T) { }) } -func TestAccAzureRMDataLakeStore_importPayAsYouGoWithTags(t *testing.T) { +func TestAccAzureRMDataLakeStore_importTags(t *testing.T) { resourceName := "azurerm_data_lake_store.test" ri := acctest.RandInt() - config := testAccAzureDataLakeStore_withTags(ri, testLocation()) + config := testAccAzureRMDataLakeStore_withTags(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, diff --git a/azurerm/resource_arm_data_lake_store.go b/azurerm/resource_arm_data_lake_store.go index ee5843f867c9..1b98ce0dc428 100644 --- a/azurerm/resource_arm_data_lake_store.go +++ b/azurerm/resource_arm_data_lake_store.go @@ -6,7 +6,6 @@ import ( "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/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -33,9 +32,9 @@ func resourceArmDateLakeStore() *schema.Resource { "resource_group_name": resourceGroupNameSchema(), "tier": { - Type: schema.TypeString, - Required: false, - ForceNew: false, + Type: schema.TypeString, + Required: false, + ForceNew: false, DiffSuppressFunc: ignoreCaseDiffSuppressFunc, }, @@ -53,13 +52,13 @@ func resourceArmDateLakeStoreCreate(d *schema.ResourceData, meta interface{}) er name := d.Get("name").(string) location := azureRMNormalizeLocation(d.Get("location").(string)) resGroup := d.Get("resource_group_name").(string) - tier := d.Get("tier").(string) + tier := d.Get("tier").(account.TierType) tags := d.Get("tags").(map[string]interface{}) - dateLakeStore := accounts.CreateDataLakeStoreAccountParameters{ + dateLakeStore := account.CreateDataLakeStoreAccountParameters{ Location: &location, Tags: expandTags(tags), - CreateDataLakeStoreAccountProperties: &accounts.CreateDataLakeStoreAccountProperties{ + CreateDataLakeStoreAccountProperties: &account.CreateDataLakeStoreAccountProperties{ NewTier: tier, }, } @@ -98,13 +97,13 @@ 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) + newTier := d.Get("tier").(account.TierType) - props := accounts.UpdateDataLakeStoreAccountParameters{ + props := account.UpdateDataLakeStoreAccountParameters{ Tags: expandTags(newTags), - UpdateDataLakeStoreAccountProperties: &accounts.UpdateDataLakeStoreAccountProperties{ + UpdateDataLakeStoreAccountProperties: &account.UpdateDataLakeStoreAccountProperties{ NewTier: newTier, - } + }, } future, err := client.Update(ctx, resourceGroup, name, props) diff --git a/azurerm/resource_arm_data_lake_store_test.go b/azurerm/resource_arm_data_lake_store_test.go index 39fe00aa725d..6c1db16ff9d8 100644 --- a/azurerm/resource_arm_data_lake_store_test.go +++ b/azurerm/resource_arm_data_lake_store_test.go @@ -2,7 +2,6 @@ package azurerm import ( "fmt" - "log" "net/http" "testing" @@ -34,7 +33,7 @@ func TestAccAzureRMDataLakeStore_payasyougo(t *testing.T) { func TestAccAzureRMDataLakeStore_monthlycommitment(t *testing.T) { resourceName := "azurerm_data_lake_store.test" ri := acctest.RandInt() - config := TestAccAzureRMDataLakeStore_monthlycommitment(ri, testLocation()) + config := testAccAzureRMDataLakeStore_monthlycommitment(ri, testLocation()) resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -148,11 +147,12 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctestlake%d" resource_group_name = "${azurerm_resource_group.test.name}" + location = "%s" } -`, rInt, location, rInt) +`, rInt, location, rInt, location) } -func TestAccAzureRMDataLakeStore_monthlycommitment(rInt int, location string) string { +func testAccAzureRMDataLakeStore_monthlycommitment(rInt int, location string) string { return fmt.Sprintf(` resource "azurerm_resource_group" "test" { name = "acctestRG_%d" @@ -162,9 +162,10 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctestlake%d" resource_group_name = "${azurerm_resource_group.test.name}" + location = "%s" tier = "Commitment_1TB" } -`, rInt, location, rInt) +`, rInt, location, rInt, location) } func testAccAzureRMDataLakeStore_withTags(rInt int, location string) string { @@ -177,12 +178,13 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctestlake%d" resource_group_name = "${azurerm_resource_group.test.name}" + location = "%s" tags { environment = "Production" cost_center = "MSFT" } } -`, rInt, location, rInt) +`, rInt, location, rInt, location) } func testAccAzureRMDataLakeStore_withTagsUpdate(rInt int, location string) string { @@ -195,10 +197,10 @@ resource "azurerm_resource_group" "test" { resource "azurerm_data_lake_store" "test" { name = "acctestlake%d" resource_group_name = "${azurerm_resource_group.test.name}" + location = "%s" tags { environment = "staging" } } -`, rInt, location, rInt) +`, rInt, location, rInt, location) } - From 0f434d8fcda4e2ab9bc077fd8c34f86ae8474365 Mon Sep 17 00:00:00 2001 From: Neeran Gul Date: Fri, 4 May 2018 20:31:04 +0100 Subject: [PATCH 03/23] adding provider, sorted order and fixed tests --- azurerm/config.go | 14 ++++----- azurerm/provider.go | 3 ++ azurerm/resource_arm_cdn_profile_test.go | 2 +- azurerm/resource_arm_data_lake_store.go | 32 +++++++++++++------- azurerm/resource_arm_data_lake_store_test.go | 8 +++-- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/azurerm/config.go b/azurerm/config.go index f5f988c4a579..1180004604ad 100644 --- a/azurerm/config.go +++ b/azurerm/config.go @@ -374,9 +374,9 @@ 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.registerDataLakeStoreAccountClients(endpoint, c.SubscriptionID, auth, sender) client.registerEventGridClients(endpoint, c.SubscriptionID, auth, sender) client.registerEventHubClients(endpoint, c.SubscriptionID, auth, sender) client.registerKeyVaultClients(endpoint, c.SubscriptionID, auth, keyVaultAuth, sender) @@ -633,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) @@ -649,12 +655,6 @@ func (c *ArmClient) registerDNSClients(endpoint, subscriptionId string, auth aut c.zonesClient = zo } -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) registerEventGridClients(endpoint, subscriptionId string, auth autorest.Authorizer, sender autorest.Sender) { egtc := eventgrid.NewTopicsClientWithBaseURI(endpoint, subscriptionId) setUserAgent(&egtc.Client) diff --git a/azurerm/provider.go b/azurerm/provider.go index 13388cb2e9a4..7fec890e27bc 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -84,6 +84,7 @@ func Provider() terraform.ResourceProvider { "azurerm_client_config": dataSourceArmClientConfig(), "azurerm_cdn_profile": dataSourceArmCdnProfile(), "azurerm_dns_zone": dataSourceArmDnsZone(), + "azurerm_data_lake_store": dataSourceArmDataLakeStoreAccount(), "azurerm_eventhub_namespace": dataSourceEventHubNamespace(), "azurerm_image": dataSourceArmImage(), "azurerm_key_vault_access_policy": dataSourceArmKeyVaultAccessPolicy(), @@ -127,6 +128,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(), @@ -331,6 +333,7 @@ func determineAzureResourceProvidersToRegister(providerList []resources.Provider "Microsoft.DBforPostgreSQL": {}, "Microsoft.Devices": {}, "Microsoft.DocumentDB": {}, + "Microsoft.DataLakeStore": {}, "Microsoft.EventGrid": {}, "Microsoft.EventHub": {}, "Microsoft.KeyVault": {}, diff --git a/azurerm/resource_arm_cdn_profile_test.go b/azurerm/resource_arm_cdn_profile_test.go index 9bf1f8a2446a..c8e30c42f028 100644 --- a/azurerm/resource_arm_cdn_profile_test.go +++ b/azurerm/resource_arm_cdn_profile_test.go @@ -12,7 +12,7 @@ import ( ) func init() { - resource.AddTestSweepers("azurerm_data_lake_store", &resource.Sweeper{ + resource.AddTestSweepers("azurerm_cdn_profile", &resource.Sweeper{ Name: "azurerm_cdn_profile", F: testSweepCDNProfiles, }) diff --git a/azurerm/resource_arm_data_lake_store.go b/azurerm/resource_arm_data_lake_store.go index 1b98ce0dc428..56a125b05cfb 100644 --- a/azurerm/resource_arm_data_lake_store.go +++ b/azurerm/resource_arm_data_lake_store.go @@ -6,11 +6,12 @@ import ( "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/response" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func resourceArmDateLakeStore() *schema.Resource { +func resourceArmDataLakeStore() *schema.Resource { return &schema.Resource{ Create: resourceArmDateLakeStoreCreate, Read: resourceArmDateLakeStoreRead, @@ -33,9 +34,19 @@ func resourceArmDateLakeStore() *schema.Resource { "tier": { Type: schema.TypeString, - Required: false, ForceNew: false, + Optional: true, + Default: string(account.Consumption), DiffSuppressFunc: ignoreCaseDiffSuppressFunc, + ValidateFunc: validation.StringInSlice([]string{ + string(account.Consumption), + string(account.Commitment1TB), + string(account.Commitment10TB), + string(account.Commitment100TB), + string(account.Commitment500TB), + string(account.Commitment1PB), + string(account.Commitment5PB), + }, true), }, "tags": tagsSchema(), @@ -52,14 +63,14 @@ func resourceArmDateLakeStoreCreate(d *schema.ResourceData, meta interface{}) er name := d.Get("name").(string) location := azureRMNormalizeLocation(d.Get("location").(string)) resGroup := d.Get("resource_group_name").(string) - tier := d.Get("tier").(account.TierType) + tier := d.Get("tier").(string) tags := d.Get("tags").(map[string]interface{}) dateLakeStore := account.CreateDataLakeStoreAccountParameters{ Location: &location, Tags: expandTags(tags), CreateDataLakeStoreAccountProperties: &account.CreateDataLakeStoreAccountProperties{ - NewTier: tier, + NewTier: account.TierType(tier), }, } @@ -90,19 +101,15 @@ func resourceArmDateLakeStoreUpdate(d *schema.ResourceData, meta interface{}) er client := meta.(*ArmClient).dataLakeStoreAccountClient ctx := meta.(*ArmClient).StopContext - if !d.HasChange("tags") { - return nil - } - name := d.Get("name").(string) resourceGroup := d.Get("resource_group_name").(string) newTags := d.Get("tags").(map[string]interface{}) - newTier := d.Get("tier").(account.TierType) + newTier := d.Get("tier").(string) props := account.UpdateDataLakeStoreAccountParameters{ Tags: expandTags(newTags), UpdateDataLakeStoreAccountProperties: &account.UpdateDataLakeStoreAccountProperties{ - NewTier: newTier, + NewTier: account.TierType(newTier), }, } @@ -134,6 +141,7 @@ func resourceArmDateLakeStoreRead(d *schema.ResourceData, meta interface{}) erro if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") + fmt.Print("Oh no nothing was found") return nil } return fmt.Errorf("Error making Read request on Azure Data Lake Store %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -145,7 +153,9 @@ func resourceArmDateLakeStoreRead(d *schema.ResourceData, meta interface{}) erro d.Set("location", azureRMNormalizeLocation(*location)) } - d.Set("tier", resp.Type) + if tier := resp.DataLakeStoreAccountProperties; tier != nil { + d.Set("tier", string(tier.CurrentTier)) + } flattenAndSetTags(d, resp.Tags) diff --git a/azurerm/resource_arm_data_lake_store_test.go b/azurerm/resource_arm_data_lake_store_test.go index 6c1db16ff9d8..182cfeaf3dd7 100644 --- a/azurerm/resource_arm_data_lake_store_test.go +++ b/azurerm/resource_arm_data_lake_store_test.go @@ -12,7 +12,7 @@ import ( func TestAccAzureRMDataLakeStore_payasyougo(t *testing.T) { resourceName := "azurerm_data_lake_store.test" - ri := acctest.RandInt() + ri := acctest.RandIntRange(1, 999999) config := testAccAzureRMDataLakeStore_payasyougo(ri, testLocation()) resource.Test(t, resource.TestCase{ @@ -24,6 +24,7 @@ func TestAccAzureRMDataLakeStore_payasyougo(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMDataLakeStoreExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tier", "Consumption"), ), }, }, @@ -32,7 +33,7 @@ func TestAccAzureRMDataLakeStore_payasyougo(t *testing.T) { func TestAccAzureRMDataLakeStore_monthlycommitment(t *testing.T) { resourceName := "azurerm_data_lake_store.test" - ri := acctest.RandInt() + ri := acctest.RandIntRange(1, 999999) config := testAccAzureRMDataLakeStore_monthlycommitment(ri, testLocation()) resource.Test(t, resource.TestCase{ @@ -44,6 +45,7 @@ func TestAccAzureRMDataLakeStore_monthlycommitment(t *testing.T) { Config: config, Check: resource.ComposeTestCheckFunc( testCheckAzureRMDataLakeStoreExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "tier", "Commitment_1TB"), ), }, }, @@ -52,7 +54,7 @@ func TestAccAzureRMDataLakeStore_monthlycommitment(t *testing.T) { func TestAccAzureRMDataLakeStore_withTags(t *testing.T) { resourceName := "azurerm_data_lake_store.test" - ri := acctest.RandInt() + ri := acctest.RandIntRange(1, 999999) location := testLocation() preConfig := testAccAzureRMDataLakeStore_withTags(ri, location) postConfig := testAccAzureRMDataLakeStore_withTagsUpdate(ri, location) From 6d3c508779fb34d4f0319d260e5b96c5cc6b8aa8 Mon Sep 17 00:00:00 2001 From: Neeran Gul Date: Tue, 8 May 2018 16:55:31 +0100 Subject: [PATCH 04/23] adding website docs and fixing data source --- azurerm/data_source_data_lake_store.go | 5 +- website/azurerm.erb | 15 +++++ website/docs/d/data_lake_store.html.markdown | 36 ++++++++++ website/docs/r/data_lake_store.html.markdown | 70 ++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 website/docs/d/data_lake_store.html.markdown create mode 100644 website/docs/r/data_lake_store.html.markdown diff --git a/azurerm/data_source_data_lake_store.go b/azurerm/data_source_data_lake_store.go index e5db925ba599..47a9bde55eb2 100644 --- a/azurerm/data_source_data_lake_store.go +++ b/azurerm/data_source_data_lake_store.go @@ -55,7 +55,10 @@ func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interfac if location := resp.Location; location != nil { d.Set("location", azureRMNormalizeLocation(*location)) } - d.Set("tier", resp.Type) + + if tier := resp.DataLakeStoreAccountProperties; tier != nil { + d.Set("tier", string(tier.CurrentTier)) + } flattenAndSetTags(d, resp.Tags) diff --git a/website/azurerm.erb b/website/azurerm.erb index f52739eeb4cf..1891f051332e 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -55,6 +55,10 @@ azurerm_dns_zone + > + azurerm_data_lake_store + + > azurerm_eventhub_namespace @@ -372,6 +376,17 @@ + > + Data Lake Store Resources + + + > DNS Resources