diff --git a/internal/services/datalake/client/client.go b/internal/services/datalake/client/client.go index 1d76cdb59822..2c66d5397ccd 100644 --- a/internal/services/datalake/client/client.go +++ b/internal/services/datalake/client/client.go @@ -1,41 +1,46 @@ package client import ( - analytics "github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account" "github.com/Azure/azure-sdk-for-go/services/datalake/store/2016-11-01/filesystem" - store "github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account" "github.com/hashicorp/terraform-provider-azurerm/internal/common" + analyticsaccount "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts" + analyticsfirewallrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/firewallrules" + storeaccount "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" + storefirewallrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/firewallrules" + storevirtualnetworkrules "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/virtualnetworkrules" ) type Client struct { // Data Lake Store - StoreAccountsClient *store.AccountsClient - StoreFirewallRulesClient *store.FirewallRulesClient - VirtualNetworkRulesClient *store.VirtualNetworkRulesClient + StoreAccountsClient *storeaccount.AccountsClient + StoreFirewallRulesClient *storefirewallrules.FirewallRulesClient + VirtualNetworkRulesClient *storevirtualnetworkrules.VirtualNetworkRulesClient StoreFilesClient *filesystem.Client // Data Lake Analytics - AnalyticsAccountsClient *analytics.AccountsClient - AnalyticsFirewallRulesClient *analytics.FirewallRulesClient + AnalyticsAccountsClient *analyticsaccount.AccountsClient + AnalyticsFirewallRulesClient *analyticsfirewallrules.FirewallRulesClient + + SubscriptionId string } func NewClient(o *common.ClientOptions) *Client { - StoreAccountsClient := store.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + StoreAccountsClient := storeaccount.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&StoreAccountsClient.Client, o.ResourceManagerAuthorizer) - StoreFirewallRulesClient := store.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + StoreFirewallRulesClient := storefirewallrules.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&StoreFirewallRulesClient.Client, o.ResourceManagerAuthorizer) - VirtualNetworkRulesClient := store.NewVirtualNetworkRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + VirtualNetworkRulesClient := storevirtualnetworkrules.NewVirtualNetworkRulesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&VirtualNetworkRulesClient.Client, o.ResourceManagerAuthorizer) StoreFilesClient := filesystem.NewClient() o.ConfigureClient(&StoreFilesClient.Client, o.ResourceManagerAuthorizer) - AnalyticsAccountsClient := analytics.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + AnalyticsAccountsClient := analyticsaccount.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&AnalyticsAccountsClient.Client, o.ResourceManagerAuthorizer) - AnalyticsFirewallRulesClient := analytics.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId) + AnalyticsFirewallRulesClient := analyticsfirewallrules.NewFirewallRulesClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&AnalyticsFirewallRulesClient.Client, o.ResourceManagerAuthorizer) return &Client{ @@ -45,5 +50,6 @@ func NewClient(o *common.ClientOptions) *Client { StoreFilesClient: &StoreFilesClient, AnalyticsAccountsClient: &AnalyticsAccountsClient, AnalyticsFirewallRulesClient: &AnalyticsFirewallRulesClient, + SubscriptionId: o.SubscriptionId, } } diff --git a/internal/services/datalake/data_lake_analytics_account_resource.go b/internal/services/datalake/data_lake_analytics_account_resource.go index d1beb06de5fa..205819798ad8 100644 --- a/internal/services/datalake/data_lake_analytics_account_resource.go +++ b/internal/services/datalake/data_lake_analytics_account_resource.go @@ -5,18 +5,18 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/datalake/analytics/mgmt/2016-11-01/account" + "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource { @@ -53,18 +53,18 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource { "tier": { Type: pluginsdk.TypeString, Optional: true, - Default: string(account.Consumption), + Default: string(accounts.TierTypeConsumption), DiffSuppressFunc: suppress.CaseDifference, ValidateFunc: validation.StringInSlice([]string{ - string(account.Consumption), - string(account.Commitment100000AUHours), - string(account.Commitment10000AUHours), - string(account.Commitment1000AUHours), - string(account.Commitment100AUHours), - string(account.Commitment500000AUHours), - string(account.Commitment50000AUHours), - string(account.Commitment5000AUHours), - string(account.Commitment500AUHours), + string(accounts.TierTypeConsumption), + string(accounts.TierTypeCommitmentOneZeroZeroZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentOneZeroZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentOneZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentOneZeroZeroAUHours), + string(accounts.TierTypeCommitmentFiveZeroZeroZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentFiveZeroZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentFiveZeroZeroZeroAUHours), + string(accounts.TierTypeCommitmentFiveZeroZeroAUHours), }, true), }, @@ -82,51 +82,46 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource { func resourceArmDateLakeAnalyticsAccountCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.AnalyticsAccountsClient - subscriptionId := meta.(*clients.Client).Datalake.AnalyticsAccountsClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewAnalyticsAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := accounts.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - existing, err := client.Get(ctx, id.ResourceGroup, id.AccountName) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for presence of existing Data Lake Analytics Account %s: %+v", id, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_lake_analytics_account", *existing.ID) + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_lake_analytics_account", id.ID()) } location := azure.NormalizeLocation(d.Get("location").(string)) storeAccountName := d.Get("default_store_account_name").(string) - tier := d.Get("tier").(string) + tier := accounts.TierType(d.Get("tier").(string)) t := d.Get("tags").(map[string]interface{}) log.Printf("[INFO] preparing arguments for Azure ARM Date Lake Store creation %s", id) - dateLakeAnalyticsAccount := account.CreateDataLakeAnalyticsAccountParameters{ - Location: &location, - Tags: tags.Expand(t), - CreateDataLakeAnalyticsAccountProperties: &account.CreateDataLakeAnalyticsAccountProperties{ - NewTier: account.TierType(tier), - DefaultDataLakeStoreAccount: &storeAccountName, - DataLakeStoreAccounts: &[]account.AddDataLakeStoreWithAccountParameters{ + dateLakeAnalyticsAccount := accounts.CreateDataLakeAnalyticsAccountParameters{ + Location: location, + Tags: expandTags(t), + Properties: accounts.CreateDataLakeAnalyticsAccountProperties{ + NewTier: &tier, + DefaultDataLakeStoreAccount: storeAccountName, + DataLakeStoreAccounts: []accounts.AddDataLakeStoreWithAccountParameters{ { - Name: &storeAccountName, + Name: storeAccountName, }, }, }, } - future, err := client.Create(ctx, id.ResourceGroup, id.AccountName, dateLakeAnalyticsAccount) - if err != nil { - return fmt.Errorf("issuing create request for Data Lake Analytics Account %s: %+v", id, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("creating Data Lake Analytics Account %s: %+v", id, err) + if err := client.CreateThenPoll(ctx, id, dateLakeAnalyticsAccount); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) } d.SetId(id.ID()) @@ -139,34 +134,29 @@ func resourceArmDateLakeAnalyticsAccountUpdate(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AnalyticsAccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } storeAccountName := d.Get("default_store_account_name").(string) - newTier := d.Get("tier").(string) + newTier := accounts.TierType(d.Get("tier").(string)) newTags := d.Get("tags").(map[string]interface{}) - props := &account.UpdateDataLakeAnalyticsAccountParameters{ - Tags: tags.Expand(newTags), - UpdateDataLakeAnalyticsAccountProperties: &account.UpdateDataLakeAnalyticsAccountProperties{ - NewTier: account.TierType(newTier), - DataLakeStoreAccounts: &[]account.UpdateDataLakeStoreWithAccountParameters{ + props := accounts.UpdateDataLakeAnalyticsAccountParameters{ + Tags: expandTags(newTags), + Properties: &accounts.UpdateDataLakeAnalyticsAccountProperties{ + NewTier: &newTier, + DataLakeStoreAccounts: &[]accounts.UpdateDataLakeStoreWithAccountParameters{ { - Name: &storeAccountName, + Name: storeAccountName, }, }, }, } - future, err := client.Update(ctx, id.ResourceGroup, id.AccountName, props) - if err != nil { - return fmt.Errorf("issuing update request for Data Lake Analytics Account %s: %+v", id, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the update of Data Lake Analytics Account %s to complete: %+v", id, err) + if err := client.UpdateThenPoll(ctx, *id, props); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) } return resourceArmDateLakeAnalyticsAccountRead(d, meta) @@ -177,33 +167,37 @@ func resourceArmDateLakeAnalyticsAccountRead(d *pluginsdk.ResourceData, meta int ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AnalyticsAccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[WARN] DataLakeAnalyticsAccountAccount '%s'", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Azure Data Lake Analytics Account %s: %+v", id, err) + return fmt.Errorf("reading %s: %+v", id, err) } - d.Set("name", id.AccountName) + d.Set("name", id.Name) d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - if properties := resp.DataLakeAnalyticsAccountProperties; properties != nil { - d.Set("tier", string(properties.CurrentTier)) - d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount) - } + if model := resp.Model; model != nil { + if location := model.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if properties := model.Properties; properties != nil { + d.Set("tier", properties.CurrentTier) + d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount) + } - return tags.FlattenAndSet(d, resp.Tags) + return tags.FlattenAndSet(d, flattenTags(model.Tags)) + } + return nil } func resourceArmDateLakeAnalyticsAccountDelete(d *pluginsdk.ResourceData, meta interface{}) error { @@ -211,18 +205,13 @@ func resourceArmDateLakeAnalyticsAccountDelete(d *pluginsdk.ResourceData, meta i ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AnalyticsAccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.AccountName) - if err != nil { - return fmt.Errorf("deleting Data Lake Analytics Account %s: %+v", id, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the deletion of Data Lake Analytics Account %s: %+v", id, err) + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) } return nil diff --git a/internal/services/datalake/data_lake_analytics_account_resource_test.go b/internal/services/datalake/data_lake_analytics_account_resource_test.go index ad5e9669ff6a..98eb8ad0738e 100644 --- a/internal/services/datalake/data_lake_analytics_account_resource_test.go +++ b/internal/services/datalake/data_lake_analytics_account_resource_test.go @@ -6,10 +6,11 @@ import ( "strconv" "testing" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -88,17 +89,17 @@ func TestAccDataLakeAnalyticsAccount_withTags(t *testing.T) { } func (t DataLakeAnalyticsAccountResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.AnalyticsAccountID(state.ID) + id, err := accounts.ParseAccountID(state.ID) if err != nil { return nil, err } - resp, err := clients.Datalake.AnalyticsAccountsClient.Get(ctx, id.ResourceGroup, id.AccountName) + resp, err := clients.Datalake.AnalyticsAccountsClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Date Lake Analytics Account %s: %+v", id, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } - return utils.Bool(resp.DataLakeAnalyticsAccountProperties != nil), nil + return utils.Bool(resp.Model != nil), nil } func (DataLakeAnalyticsAccountResource) basic(data acceptance.TestData) string { diff --git a/internal/services/datalake/data_lake_analytics_firewall_rule_resource.go b/internal/services/datalake/data_lake_analytics_firewall_rule_resource.go index 38f19f778718..cb5e32885563 100644 --- a/internal/services/datalake/data_lake_analytics_firewall_rule_resource.go +++ b/internal/services/datalake/data_lake_analytics_firewall_rule_resource.go @@ -2,7 +2,6 @@ package datalake import ( "fmt" - "log" "time" @@ -13,10 +12,10 @@ import ( commonValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/firewallrules" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceDataLakeAnalyticsFirewallRule() *pluginsdk.Resource { @@ -72,22 +71,22 @@ func resourceDataLakeAnalyticsFirewallRule() *pluginsdk.Resource { func resourceArmDateLakeAnalyticsFirewallRuleCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.AnalyticsFirewallRulesClient - subscriptionId := meta.(*clients.Client).Datalake.AnalyticsFirewallRulesClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewAnalyticsFirewallRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) + id := firewallrules.NewFirewallRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.FirewallRuleName) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { + if !response.WasNotFound(existing.HttpResponse) { return fmt.Errorf("checking for presence of existing Data Lake Analytics Firewall Rule %s %+v", id, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_lake_analytics_firewall_rule", *existing.ID) + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_lake_analytics_firewall_rule", id.ID()) } } @@ -96,15 +95,15 @@ func resourceArmDateLakeAnalyticsFirewallRuleCreateUpdate(d *pluginsdk.ResourceD log.Printf("[INFO] preparing arguments for Date Lake Analytics Firewall Rule creation %s", id) - dateLakeStore := account.CreateOrUpdateFirewallRuleParameters{ - CreateOrUpdateFirewallRuleProperties: &account.CreateOrUpdateFirewallRuleProperties{ - StartIPAddress: utils.String(startIPAddress), - EndIPAddress: utils.String(endIPAddress), + dateLakeStore := firewallrules.CreateOrUpdateFirewallRuleParameters{ + Properties: firewallrules.CreateOrUpdateFirewallRuleProperties{ + StartIpAddress: startIPAddress, + EndIpAddress: endIPAddress, }, } - if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.AccountName, id.FirewallRuleName, dateLakeStore); err != nil { - return fmt.Errorf("issuing create request for Data Lake Analytics %q (Resource Group %q): %+v", id.AccountName, id.ResourceGroup, err) + if _, err := client.CreateOrUpdate(ctx, id, dateLakeStore); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) } d.SetId(id.ID()) @@ -117,28 +116,30 @@ func resourceArmDateLakeAnalyticsFirewallRuleRead(d *pluginsdk.ResourceData, met ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AnalyticsFirewallRuleID(d.Id()) + id, err := firewallrules.ParseFirewallRuleID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.FirewallRuleName) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[WARN] Data Lake Analytics Firewall Rule %s", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Azure Data Lake Analytics Firewall Rule %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.FirewallRuleName) + d.Set("name", id.Name) d.Set("account_name", id.AccountName) d.Set("resource_group_name", id.ResourceGroup) - if props := resp.FirewallRuleProperties; props != nil { - d.Set("start_ip_address", props.StartIPAddress) - d.Set("end_ip_address", props.EndIPAddress) + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + d.Set("start_ip_address", props.StartIpAddress) + d.Set("end_ip_address", props.EndIpAddress) + } } return nil @@ -149,17 +150,17 @@ func resourceArmDateLakeAnalyticsFirewallRuleDelete(d *pluginsdk.ResourceData, m ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AnalyticsFirewallRuleID(d.Id()) + id, err := firewallrules.ParseFirewallRuleID(d.Id()) if err != nil { return err } - resp, err := client.Delete(ctx, id.ResourceGroup, id.AccountName, id.FirewallRuleName) + resp, err := client.Delete(ctx, *id) if err != nil { - if response.WasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return nil } - return fmt.Errorf("issuing delete request for Data Lake Analytics Firewall Rule %s: %+v", id, err) + return fmt.Errorf("deleting %s: %+v", id, err) } return nil diff --git a/internal/services/datalake/data_lake_analytics_firewall_rule_resource_test.go b/internal/services/datalake/data_lake_analytics_firewall_rule_resource_test.go index ac89696ceaca..6939e673148c 100644 --- a/internal/services/datalake/data_lake_analytics_firewall_rule_resource_test.go +++ b/internal/services/datalake/data_lake_analytics_firewall_rule_resource_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/firewallrules" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -101,17 +101,17 @@ func TestAccDataLakeAnalyticsFirewallRule_azureServices(t *testing.T) { } func (t DataLakeAnalyticsFirewallRuleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.AnalyticsFirewallRuleID(state.ID) + id, err := firewallrules.ParseFirewallRuleID(state.ID) if err != nil { return nil, err } - resp, err := clients.Datalake.AnalyticsFirewallRulesClient.Get(ctx, id.ResourceGroup, id.AccountName, id.FirewallRuleName) + resp, err := clients.Datalake.AnalyticsFirewallRulesClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Date Lake Analytics Firewall Rule %s: %v", id, err) + return nil, fmt.Errorf("retrieving %s: %v", id, err) } - return utils.Bool(resp.FirewallRuleProperties != nil), nil + return utils.Bool(resp.Model != nil), nil } func (DataLakeAnalyticsFirewallRuleResource) basic(data acceptance.TestData, startIP, endIP string) string { diff --git a/internal/services/datalake/data_lake_store_data_source.go b/internal/services/datalake/data_lake_store_data_source.go index e91d9b2fabdf..a967c33e86de 100644 --- a/internal/services/datalake/data_lake_store_data_source.go +++ b/internal/services/datalake/data_lake_store_data_source.go @@ -4,13 +4,13 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func dataSourceDataLakeStoreAccount() *pluginsdk.Resource { @@ -63,39 +63,43 @@ func dataSourceDataLakeStoreAccount() *pluginsdk.Resource { func dataSourceArmDateLakeStoreAccountRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.StoreAccountsClient - subscriptionId := meta.(*clients.Client).Datalake.StoreAccountsClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := accounts.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.Get(ctx, id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return fmt.Errorf("Data Lake Store Account %s was not found", id) + if response.WasNotFound(resp.HttpResponse) { + return fmt.Errorf("%s was not found", id) } - return fmt.Errorf("retrieving Data Lake Store Account %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.SetId(id.ID()) d.Set("name", id.Name) d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - if properties := resp.DataLakeStoreAccountProperties; properties != nil { - d.Set("tier", string(properties.CurrentTier)) + if model := resp.Model; model != nil { + if location := model.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } + + if properties := model.Properties; properties != nil { + d.Set("tier", 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)) + d.Set("encryption_state", properties.EncryptionState) + d.Set("firewall_allow_azure_ips", properties.FirewallAllowAzureIps) + d.Set("firewall_state", properties.FirewallState) - if config := properties.EncryptionConfig; config != nil { - d.Set("encryption_type", string(config.Type)) + if config := properties.EncryptionConfig; config != nil { + d.Set("encryption_type", string(config.Type)) + } } - } - return tags.FlattenAndSet(d, resp.Tags) + return tags.FlattenAndSet(d, flattenTags(model.Tags)) + } + return nil } diff --git a/internal/services/datalake/data_lake_store_firewall_rule_resource.go b/internal/services/datalake/data_lake_store_firewall_rule_resource.go index 8d751ae8a281..2a7ee0dc6592 100644 --- a/internal/services/datalake/data_lake_store_firewall_rule_resource.go +++ b/internal/services/datalake/data_lake_store_firewall_rule_resource.go @@ -12,10 +12,10 @@ import ( commonValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/firewallrules" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceDataLakeStoreFirewallRule() *pluginsdk.Resource { @@ -71,22 +71,22 @@ func resourceDataLakeStoreFirewallRule() *pluginsdk.Resource { func resourceArmDateLakeStoreAccountFirewallRuleCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.StoreFirewallRulesClient - subscriptionId := meta.(*clients.Client).Datalake.StoreFirewallRulesClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewFirewallRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) + id := firewallrules.NewFirewallRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Date Lake Store Firewall Rule %s: %+v", id, err) + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("retreiving %s: %+v", id, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_lake_store_firewall_rule", *existing.ID) + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_lake_store_firewall_rule", id.ID()) } } @@ -95,15 +95,15 @@ func resourceArmDateLakeStoreAccountFirewallRuleCreateUpdate(d *pluginsdk.Resour log.Printf("[INFO] preparing arguments for Date Lake Store Firewall Rule creation %s", id) - dateLakeStore := account.CreateOrUpdateFirewallRuleParameters{ - CreateOrUpdateFirewallRuleProperties: &account.CreateOrUpdateFirewallRuleProperties{ - StartIPAddress: utils.String(startIPAddress), - EndIPAddress: utils.String(endIPAddress), + dateLakeStore := firewallrules.CreateOrUpdateFirewallRuleParameters{ + Properties: firewallrules.CreateOrUpdateFirewallRuleProperties{ + StartIpAddress: startIPAddress, + EndIpAddress: endIPAddress, }, } - if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.AccountName, id.Name, dateLakeStore); err != nil { - return fmt.Errorf("issuing create request for Data Lake Store %q (Resource Group %q): %+v", id.AccountName, id.ResourceGroup, err) + if _, err := client.CreateOrUpdate(ctx, id, dateLakeStore); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) } d.SetId(id.ID()) @@ -116,28 +116,30 @@ func resourceArmDateLakeStoreAccountFirewallRuleRead(d *pluginsdk.ResourceData, ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FirewallRuleID(d.Id()) + id, err := firewallrules.ParseFirewallRuleID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[WARN] Data Lake Store Firewall Rule %s was not found", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Azure Data Lake Store Firewall Rule %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.Set("name", id.Name) d.Set("account_name", id.AccountName) d.Set("resource_group_name", id.ResourceGroup) - if props := resp.FirewallRuleProperties; props != nil { - d.Set("start_ip_address", props.StartIPAddress) - d.Set("end_ip_address", props.EndIPAddress) + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + d.Set("start_ip_address", props.StartIpAddress) + d.Set("end_ip_address", props.EndIpAddress) + } } return nil @@ -148,17 +150,17 @@ func resourceArmDateLakeStoreAccountFirewallRuleDelete(d *pluginsdk.ResourceData ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.FirewallRuleID(d.Id()) + id, err := firewallrules.ParseFirewallRuleID(d.Id()) if err != nil { return err } - resp, err := client.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := client.Delete(ctx, *id) if err != nil { - if response.WasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return nil } - return fmt.Errorf("issuing delete request for Data Lake Store Firewall Rule %s: %+v", id, err) + return fmt.Errorf("deleting %s: %+v", id, err) } return nil diff --git a/internal/services/datalake/data_lake_store_firewall_rule_resource_test.go b/internal/services/datalake/data_lake_store_firewall_rule_resource_test.go index aa9397a86a72..a6ca0e18dc89 100644 --- a/internal/services/datalake/data_lake_store_firewall_rule_resource_test.go +++ b/internal/services/datalake/data_lake_store_firewall_rule_resource_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/firewallrules" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -101,17 +101,17 @@ func TestAccDataLakeStoreFirewallRule_azureServices(t *testing.T) { } func (t DataLakeStoreFirewallRuleResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.FirewallRuleID(state.ID) + id, err := firewallrules.ParseFirewallRuleID(state.ID) if err != nil { return nil, err } - resp, err := clients.Datalake.StoreFirewallRulesClient.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := clients.Datalake.StoreFirewallRulesClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Date Lake Store Firewall Rule %s: %v", id, err) + return nil, fmt.Errorf("retrieving %s: %v", id, err) } - return utils.Bool(resp.FirewallRuleProperties != nil), nil + return utils.Bool(resp.Model != nil), nil } func (DataLakeStoreFirewallRuleResource) basic(data acceptance.TestData, startIP, endIP string) string { diff --git a/internal/services/datalake/data_lake_store_resource.go b/internal/services/datalake/data_lake_store_resource.go index c037cd258bd7..8fae4405cec5 100644 --- a/internal/services/datalake/data_lake_store_resource.go +++ b/internal/services/datalake/data_lake_store_resource.go @@ -5,18 +5,19 @@ import ( "log" "time" - "github.com/Azure/azure-sdk-for-go/services/datalake/store/mgmt/2016-11-01/account" + "github.com/hashicorp/go-azure-helpers/response" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/identity" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceDataLakeStore() *pluginsdk.Resource { @@ -53,27 +54,27 @@ func resourceDataLakeStore() *pluginsdk.Resource { "tier": { Type: pluginsdk.TypeString, Optional: true, - Default: string(account.Consumption), + Default: string(accounts.TierTypeConsumption), DiffSuppressFunc: suppress.CaseDifference, 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), + string(accounts.TierTypeConsumption), + string(accounts.TierTypeCommitmentOneTB), + string(accounts.TierTypeCommitmentOneZeroTB), + string(accounts.TierTypeCommitmentOneZeroZeroTB), + string(accounts.TierTypeCommitmentFiveZeroZeroTB), + string(accounts.TierTypeCommitmentOnePB), + string(accounts.TierTypeCommitmentFivePB), }, true), }, "encryption_state": { Type: pluginsdk.TypeString, Optional: true, - Default: string(account.Enabled), + Default: string(accounts.EncryptionStateEnabled), ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(account.Enabled), - string(account.Disabled), + string(accounts.EncryptionStateEnabled), + string(accounts.EncryptionStateDisabled), }, true), DiffSuppressFunc: suppress.CaseDifference, }, @@ -84,7 +85,7 @@ func resourceDataLakeStore() *pluginsdk.Resource { Computed: true, ForceNew: true, ValidateFunc: validation.StringInSlice([]string{ - string(account.ServiceManaged), + string(accounts.EncryptionConfigTypeServiceManaged), }, true), DiffSuppressFunc: suppress.CaseDifference, }, @@ -92,10 +93,10 @@ func resourceDataLakeStore() *pluginsdk.Resource { "firewall_state": { Type: pluginsdk.TypeString, Optional: true, - Default: string(account.FirewallStateEnabled), + Default: string(accounts.FirewallStateEnabled), ValidateFunc: validation.StringInSlice([]string{ - string(account.FirewallStateEnabled), - string(account.FirewallStateDisabled), + string(accounts.FirewallStateEnabled), + string(accounts.FirewallStateDisabled), }, true), DiffSuppressFunc: suppress.CaseDifference, }, @@ -103,10 +104,10 @@ func resourceDataLakeStore() *pluginsdk.Resource { "firewall_allow_azure_ips": { Type: pluginsdk.TypeString, Optional: true, - Default: string(account.FirewallAllowAzureIpsStateEnabled), + Default: string(accounts.FirewallAllowAzureIpsStateEnabled), ValidateFunc: validation.StringInSlice([]string{ - string(account.FirewallAllowAzureIpsStateEnabled), - string(account.FirewallAllowAzureIpsStateDisabled), + string(accounts.FirewallAllowAzureIpsStateEnabled), + string(accounts.FirewallAllowAzureIpsStateDisabled), }, true), DiffSuppressFunc: suppress.CaseDifference, }, @@ -116,30 +117,7 @@ func resourceDataLakeStore() *pluginsdk.Resource { Computed: true, }, - "identity": { - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "type": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: validation.StringInSlice([]string{ - "SystemAssigned", - }, false), - }, - "principal_id": { - Type: pluginsdk.TypeString, - Computed: true, - }, - "tenant_id": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - }, - }, + "identity": identity.SystemAssigned{}.Schema(), "tags": tags.Schema(), }, @@ -148,61 +126,55 @@ func resourceDataLakeStore() *pluginsdk.Resource { func resourceArmDateLakeStoreCreate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.StoreAccountsClient - subscriptionId := meta.(*clients.Client).Datalake.StoreAccountsClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := accounts.NewAccountID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.Name) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Data Lake Store %s: %+v", id, err) + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("retrieving %s: %+v", id, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_lake_store", *existing.ID) + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_lake_store", id.ID()) } } location := azure.NormalizeLocation(d.Get("location").(string)) - tier := d.Get("tier").(string) + tier := accounts.TierType(d.Get("tier").(string)) - encryptionState := account.EncryptionState(d.Get("encryption_state").(string)) - encryptionType := account.EncryptionConfigType(d.Get("encryption_type").(string)) - firewallState := account.FirewallState(d.Get("firewall_state").(string)) - firewallAllowAzureIPs := account.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string)) + encryptionState := accounts.EncryptionState(d.Get("encryption_state").(string)) + encryptionType := accounts.EncryptionConfigType(d.Get("encryption_type").(string)) + firewallState := accounts.FirewallState(d.Get("firewall_state").(string)) + firewallAllowAzureIPs := accounts.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string)) t := d.Get("tags").(map[string]interface{}) log.Printf("[INFO] preparing arguments for Data Lake Store creation %s", id) - dateLakeStore := account.CreateDataLakeStoreAccountParameters{ - Location: &location, - Tags: tags.Expand(t), + dateLakeStore := accounts.CreateDataLakeStoreAccountParameters{ + Location: location, + Tags: expandTags(t), Identity: expandDataLakeStoreIdentity(d.Get("identity").([]interface{})), - CreateDataLakeStoreAccountProperties: &account.CreateDataLakeStoreAccountProperties{ - NewTier: account.TierType(tier), - FirewallState: firewallState, - FirewallAllowAzureIps: firewallAllowAzureIPs, - EncryptionState: encryptionState, + Properties: &accounts.CreateDataLakeStoreAccountProperties{ + NewTier: &tier, + FirewallState: &firewallState, + FirewallAllowAzureIps: &firewallAllowAzureIPs, + EncryptionState: &encryptionState, - EncryptionConfig: &account.EncryptionConfig{ + EncryptionConfig: &accounts.EncryptionConfig{ Type: encryptionType, }, }, } - future, err := client.Create(ctx, id.ResourceGroup, id.Name, dateLakeStore) - if err != nil { - return fmt.Errorf("issuing create request for Data Lake Store %s: %+v", id, err) + if err := client.CreateThenPoll(ctx, id, dateLakeStore); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("creating Data Lake Store %s: %+v", id, err) - } - d.SetId(id.ID()) return resourceArmDateLakeStoreRead(d, meta) @@ -213,32 +185,27 @@ func resourceArmDateLakeStoreUpdate(d *pluginsdk.ResourceData, meta interface{}) ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } - tier := d.Get("tier").(string) - firewallState := account.FirewallState(d.Get("firewall_state").(string)) - firewallAllowAzureIPs := account.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string)) + tier := accounts.TierType(d.Get("tier").(string)) + firewallState := accounts.FirewallState(d.Get("firewall_state").(string)) + firewallAllowAzureIPs := accounts.FirewallAllowAzureIpsState(d.Get("firewall_allow_azure_ips").(string)) t := d.Get("tags").(map[string]interface{}) - props := account.UpdateDataLakeStoreAccountParameters{ - UpdateDataLakeStoreAccountProperties: &account.UpdateDataLakeStoreAccountProperties{ - NewTier: account.TierType(tier), - FirewallState: firewallState, - FirewallAllowAzureIps: firewallAllowAzureIPs, + props := accounts.UpdateDataLakeStoreAccountParameters{ + Properties: &accounts.UpdateDataLakeStoreAccountProperties{ + NewTier: &tier, + FirewallState: &firewallState, + FirewallAllowAzureIps: &firewallAllowAzureIPs, }, - Tags: tags.Expand(t), - } - - future, err := client.Update(ctx, id.ResourceGroup, id.Name, props) - if err != nil { - return fmt.Errorf("issuing update request for Data Lake Store %s: %+v", id, err) + Tags: expandTags(t), } - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for the update of Data Lake Store %s to complete: %+v", id, err) + if err := client.UpdateThenPoll(ctx, *id, props); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) } return resourceArmDateLakeStoreRead(d, meta) @@ -249,47 +216,69 @@ func resourceArmDateLakeStoreRead(d *pluginsdk.ResourceData, meta interface{}) e ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[WARN] Data Lake Store Account %s was not found", id) d.SetId("") return nil } - return fmt.Errorf("making Read request on Azure Data Lake Store %s: %+v", id, err) + return fmt.Errorf("retreiving %s: %+v", id, err) } d.Set("name", id.Name) d.Set("resource_group_name", id.ResourceGroup) - if location := resp.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } - if err := d.Set("identity", flattenDataLakeStoreIdentity(resp.Identity)); err != nil { - return fmt.Errorf("flattening identity on Data Lake Store %s: %+v", id, err) - } + if model := resp.Model; model != nil { + if location := model.Location; location != nil { + d.Set("location", azure.NormalizeLocation(*location)) + } - if properties := resp.DataLakeStoreAccountProperties; properties != nil { - d.Set("tier", string(properties.CurrentTier)) + if err := d.Set("identity", flattenDataLakeStoreIdentity(model.Identity)); err != nil { + return fmt.Errorf("flattening identity on Data Lake Store %s: %+v", id, err) + } - d.Set("encryption_state", string(properties.EncryptionState)) - d.Set("firewall_state", string(properties.FirewallState)) - d.Set("firewall_allow_azure_ips", string(properties.FirewallAllowAzureIps)) + if properties := model.Properties; properties != nil { + tier := "" + if properties.CurrentTier != nil { + tier = string(*properties.CurrentTier) + } + d.Set("tier", tier) - if config := properties.EncryptionConfig; config != nil { - d.Set("encryption_type", string(config.Type)) + encryptionState := "" + if properties.EncryptionState != nil { + encryptionState = string(*properties.EncryptionState) + } + d.Set("encryption_state", encryptionState) + + firewallState := "" + if properties.FirewallState != nil { + firewallState = string(*properties.FirewallState) + } + d.Set("firewall_state", firewallState) + + firewallAllowAzureIps := "" + if properties.FirewallAllowAzureIps != nil { + firewallAllowAzureIps = string(*properties.FirewallAllowAzureIps) + } + d.Set("firewall_allow_azure_ips", firewallAllowAzureIps) + + if config := properties.EncryptionConfig; config != nil { + d.Set("encryption_type", string(config.Type)) + } + + d.Set("endpoint", properties.Endpoint) } - d.Set("endpoint", properties.Endpoint) + return tags.FlattenAndSet(d, flattenTags(model.Tags)) } - - return tags.FlattenAndSet(d, resp.Tags) + return nil } func resourceArmDateLakeStoreDelete(d *pluginsdk.ResourceData, meta interface{}) error { @@ -297,48 +286,43 @@ func resourceArmDateLakeStoreDelete(d *pluginsdk.ResourceData, meta interface{}) ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.AccountID(d.Id()) + id, err := accounts.ParseAccountID(d.Id()) if err != nil { return err } - future, err := client.Delete(ctx, id.ResourceGroup, id.Name) - if err != nil { - return fmt.Errorf("deleting Data Lake Store %s: %+v", id, err) - } - - if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of Data Lake Store %s: %+v", id, err) + if err := client.DeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) } return nil } -func expandDataLakeStoreIdentity(input []interface{}) *account.EncryptionIdentity { +func expandDataLakeStoreIdentity(input []interface{}) *identity.SystemAssignedIdentity { if len(input) == 0 { return nil } v := input[0].(map[string]interface{}) - return &account.EncryptionIdentity{ - Type: utils.String(v["type"].(string)), + return &identity.SystemAssignedIdentity{ + Type: accounts.EncryptionConfigType(v["type"].(string)), } } -func flattenDataLakeStoreIdentity(identity *account.EncryptionIdentity) []interface{} { +func flattenDataLakeStoreIdentity(identity *identity.SystemAssignedIdentity) []interface{} { if identity == nil { return []interface{}{} } principalID := "" - if identity.PrincipalID != nil { - principalID = identity.PrincipalID.String() + if identity.PrincipalId != nil { + principalID = *identity.PrincipalId } tenantID := "" - if identity.TenantID != nil { - tenantID = identity.TenantID.String() + if identity.TenantId != nil { + tenantID = *identity.TenantId } return []interface{}{ diff --git a/internal/services/datalake/data_lake_store_resource_test.go b/internal/services/datalake/data_lake_store_resource_test.go index 9995b1a85a41..72d246bdec4f 100644 --- a/internal/services/datalake/data_lake_store_resource_test.go +++ b/internal/services/datalake/data_lake_store_resource_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datashare/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -172,17 +172,17 @@ func TestAccDataLakeStore_withTags(t *testing.T) { } func (t DataLakeStoreResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.AccountID(state.ID) + id, err := accounts.ParseAccountID(state.ID) if err != nil { return nil, err } - resp, err := clients.Datalake.StoreAccountsClient.Get(ctx, id.ResourceGroup, id.Name) + resp, err := clients.Datalake.StoreAccountsClient.Get(ctx, *id) if err != nil { - return nil, fmt.Errorf("retrieving Date Lake Store %s: %+v", id, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } - return utils.Bool(resp.DataLakeStoreAccountProperties != nil), nil + return utils.Bool(resp.Model != nil), nil } func (DataLakeStoreResource) basic(data acceptance.TestData) string { diff --git a/internal/services/datalake/data_lake_store_virtual_network_rule_resource.go b/internal/services/datalake/data_lake_store_virtual_network_rule_resource.go index 1bceb6e1e8d4..bb4620a61464 100644 --- a/internal/services/datalake/data_lake_store_virtual_network_rule_resource.go +++ b/internal/services/datalake/data_lake_store_virtual_network_rule_resource.go @@ -11,11 +11,11 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/virtualnetworkrules" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" networkValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceDataLakeStoreVirtualNetworkRule() *pluginsdk.Resource { @@ -65,35 +65,35 @@ func resourceDataLakeStoreVirtualNetworkRule() *pluginsdk.Resource { func resourceDataLakeStoreVirtualNetworkRuleCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).Datalake.VirtualNetworkRulesClient - subscriptionId := meta.(*clients.Client).Datalake.VirtualNetworkRulesClient.SubscriptionID + subscriptionId := meta.(*clients.Client).Datalake.SubscriptionId ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id := parse.NewVirtualNetworkRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) + id := virtualnetworkrules.NewVirtualNetworkRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("account_name").(string), d.Get("name").(string)) virtualNetworkSubnetId := d.Get("subnet_id").(string) if d.IsNewResource() { - existing, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + existing, err := client.Get(ctx, id) if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for presence of existing Data Lake Store Virtual Network Rule %s: %+v", id, err) + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of %s: %+v", id, err) } } - if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_lake_store_virtual_network_rule", *existing.ID) + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_lake_store_virtual_network_rule", id.ID()) } } - parameters := account.CreateOrUpdateVirtualNetworkRuleParameters{ - CreateOrUpdateVirtualNetworkRuleProperties: &account.CreateOrUpdateVirtualNetworkRuleProperties{ - SubnetID: utils.String(virtualNetworkSubnetId), + parameters := virtualnetworkrules.CreateOrUpdateVirtualNetworkRuleParameters{ + Properties: virtualnetworkrules.CreateOrUpdateVirtualNetworkRuleProperties{ + SubnetId: virtualNetworkSubnetId, }, } - if _, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.AccountName, id.Name, parameters); err != nil { - return fmt.Errorf("creating Data Lake Store Virtual Network Rule %s: %+v", id, err) + if _, err := client.CreateOrUpdate(ctx, id, parameters); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) } d.SetId(id.ID()) @@ -106,28 +106,30 @@ func resourceDataLakeStoreVirtualNetworkRuleRead(d *pluginsdk.ResourceData, meta ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualNetworkRuleID(d.Id()) + id, err := virtualnetworkrules.ParseVirtualNetworkRuleID(d.Id()) if err != nil { return err } - resp, err := client.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := client.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { log.Printf("[INFO] Data Lake Store Virtual Network Rule %s was not found - removing from state", id) d.SetId("") return nil } - return fmt.Errorf("retrieving Virtual Network Rule %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", id, err) } d.Set("name", id.Name) d.Set("account_name", id.AccountName) d.Set("resource_group_name", id.ResourceGroup) - if props := resp.VirtualNetworkRuleProperties; props != nil { - d.Set("subnet_id", props.SubnetID) + if model := resp.Model; model != nil { + if props := model.Properties; props != nil { + d.Set("subnet_id", props.SubnetId) + } } return nil @@ -138,17 +140,17 @@ func resourceDataLakeStoreVirtualNetworkRuleDelete(d *pluginsdk.ResourceData, me ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := parse.VirtualNetworkRuleID(d.Id()) + id, err := virtualnetworkrules.ParseVirtualNetworkRuleID(d.Id()) if err != nil { return err } - resp, err := client.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := client.Delete(ctx, *id) if err != nil { - if response.WasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return nil } - return fmt.Errorf("deleting Data Lake Store Virtual Network Rule %s: %+v", id, err) + return fmt.Errorf("deleting %s: %+v", id, err) } return nil diff --git a/internal/services/datalake/data_lake_store_virtual_network_rule_resource_test.go b/internal/services/datalake/data_lake_store_virtual_network_rule_resource_test.go index fe58150d0b38..0a115100df4b 100644 --- a/internal/services/datalake/data_lake_store_virtual_network_rule_resource_test.go +++ b/internal/services/datalake/data_lake_store_virtual_network_rule_resource_test.go @@ -7,10 +7,12 @@ import ( "strconv" "testing" + "github.com/hashicorp/go-azure-helpers/response" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/virtualnetworkrules" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -300,29 +302,29 @@ func TestResourceAzureRMDataLakeStoreVirtualNetworkRule_validNameValidation(t *t } func (r DataLakeStoreVirtualNetworkRuleResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualNetworkRuleID(state.ID) + id, err := virtualnetworkrules.ParseVirtualNetworkRuleID(state.ID) if err != nil { return nil, err } - resp, err := client.Datalake.VirtualNetworkRulesClient.Get(ctx, id.ResourceGroup, id.AccountName, id.Name) + resp, err := client.Datalake.VirtualNetworkRulesClient.Get(ctx, *id) if err != nil { - if utils.ResponseWasNotFound(resp.Response) { + if response.WasNotFound(resp.HttpResponse) { return utils.Bool(false), nil } - return nil, fmt.Errorf("retrieving Data Lake Store Virtual Network Rule %s: %+v", id, err) + return nil, fmt.Errorf("retrieving %s: %+v", id, err) } return utils.Bool(true), nil } func (r DataLakeStoreVirtualNetworkRuleResource) Destroy(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.VirtualNetworkRuleID(state.ID) + id, err := virtualnetworkrules.ParseVirtualNetworkRuleID(state.ID) if err != nil { return nil, err } rulesClient := client.Datalake.VirtualNetworkRulesClient - if _, err = rulesClient.Delete(ctx, id.ResourceGroup, id.AccountName, id.Name); err != nil { - return nil, fmt.Errorf("deleting Data Lake Store Virtual Network Rule %q (Account %q / Resource Group %q): %+v", id.Name, id.AccountName, id.ResourceGroup, err) + if _, err = rulesClient.Delete(ctx, *id); err != nil { + return nil, fmt.Errorf("deleting %s: %+v", id, err) } return utils.Bool(true), nil diff --git a/internal/services/datalake/transition.go b/internal/services/datalake/transition.go new file mode 100644 index 000000000000..b482f242189d --- /dev/null +++ b/internal/services/datalake/transition.go @@ -0,0 +1,23 @@ +package datalake + +import "github.com/hashicorp/terraform-provider-azurerm/utils" + +func expandTags(input map[string]interface{}) *map[string]string { + output := make(map[string]string) + for k, v := range input { + output[k] = v.(string) + } + return &output +} + +func flattenTags(input *map[string]string) map[string]*string { + output := make(map[string]*string) + + if input != nil { + for k, v := range *input { + output[k] = utils.String(v) + } + } + + return output +}