Skip to content

Commit

Permalink
Merge pull request hashicorp#14158 from hashicorp/pandora-datalake-swap
Browse files Browse the repository at this point in the history
datalake - switching to use an embedded sdk
  • Loading branch information
tombuildsstuff authored Nov 12, 2021
2 parents d042f29 + f4f13a2 commit bf89540
Show file tree
Hide file tree
Showing 39 changed files with 343 additions and 12,052 deletions.
30 changes: 18 additions & 12 deletions internal/services/datalake/client/client.go
Original file line number Diff line number Diff line change
@@ -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{
Expand All @@ -45,5 +50,6 @@ func NewClient(o *common.ClientOptions) *Client {
StoreFilesClient: &StoreFilesClient,
AnalyticsAccountsClient: &AnalyticsAccountsClient,
AnalyticsFirewallRulesClient: &AnalyticsFirewallRulesClient,
SubscriptionId: o.SubscriptionId,
}
}
129 changes: 59 additions & 70 deletions internal/services/datalake/data_lake_analytics_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/lang/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 {
Expand Down Expand Up @@ -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),
},

Expand All @@ -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())
Expand All @@ -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)
Expand All @@ -177,52 +167,51 @@ 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 {
client := meta.(*clients.Client).Datalake.AnalyticsAccountsClient
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit bf89540

Please sign in to comment.