Skip to content

Commit

Permalink
refactor: fixing the broken auto-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 11, 2021
1 parent cf6b7c6 commit 8cf3d21
Show file tree
Hide file tree
Showing 22 changed files with 312 additions and 337 deletions.
39 changes: 19 additions & 20 deletions internal/services/appconfiguration/app_configuration_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import (
"strings"
"time"

configurationstores2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/sdk/2020-06-01/configurationstores"

"github.com/Azure/azure-sdk-for-go/services/appconfiguration/mgmt/2020-06-01/appconfiguration"
"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/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/sdk/2020-06-01/configurationstores"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand All @@ -36,7 +35,7 @@ func resourceAppConfiguration() *pluginsdk.Resource {
},

Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := configurationstores2.ConfigurationStoreID(id)
_, err := configurationstores.ConfigurationStoreID(id)
return err
}),

Expand Down Expand Up @@ -205,7 +204,7 @@ func resourceAppConfigurationCreate(d *pluginsdk.ResourceData, meta interface{})

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
resourceId := configurationstores2.NewConfigurationStoreID(subscriptionId, resourceGroup, name)
resourceId := configurationstores.NewConfigurationStoreID(subscriptionId, resourceGroup, name)
existing, err := client.Get(ctx, resourceId)
if err != nil {
if !response.WasNotFound(existing.HttpResponse) {
Expand All @@ -216,9 +215,9 @@ func resourceAppConfigurationCreate(d *pluginsdk.ResourceData, meta interface{})
return tf.ImportAsExistsError("azurerm_app_configuration", resourceId.ID())
}

parameters := configurationstores2.ConfigurationStore{
parameters := configurationstores.ConfigurationStore{
Location: azure.NormalizeLocation(d.Get("location").(string)),
Sku: configurationstores2.Sku{
Sku: configurationstores.Sku{
Name: d.Get("sku").(string),
},
Tags: expandTags(d.Get("tags").(map[string]interface{})),
Expand All @@ -240,13 +239,13 @@ func resourceAppConfigurationUpdate(d *pluginsdk.ResourceData, meta interface{})
defer cancel()

log.Printf("[INFO] preparing arguments for Azure ARM App Configuration update.")
id, err := configurationstores2.ConfigurationStoreID(d.Id())
id, err := configurationstores.ConfigurationStoreID(d.Id())
if err != nil {
return err
}

parameters := configurationstores2.ConfigurationStoreUpdateParameters{
Sku: &configurationstores2.Sku{
parameters := configurationstores.ConfigurationStoreUpdateParameters{
Sku: &configurationstores.Sku{
Name: d.Get("sku").(string),
},
Tags: expandTags(d.Get("tags").(map[string]interface{})),
Expand All @@ -268,7 +267,7 @@ func resourceAppConfigurationRead(d *pluginsdk.ResourceData, meta interface{}) e
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := configurationstores2.ConfigurationStoreID(d.Id())
id, err := configurationstores.ConfigurationStoreID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -320,7 +319,7 @@ func resourceAppConfigurationDelete(d *pluginsdk.ResourceData, meta interface{})
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := configurationstores2.ConfigurationStoreID(d.Id())
id, err := configurationstores.ConfigurationStoreID(d.Id())
if err != nil {
return err
}
Expand All @@ -339,7 +338,7 @@ type flattenedAccessKeys struct {
secondaryWriteKey []interface{}
}

func flattenAppConfigurationAccessKeys(values []configurationstores2.AccessKey) flattenedAccessKeys {
func flattenAppConfigurationAccessKeys(values []configurationstores.AccessKey) flattenedAccessKeys {
result := flattenedAccessKeys{
primaryReadKey: make([]interface{}, 0),
primaryWriteKey: make([]interface{}, 0),
Expand Down Expand Up @@ -376,7 +375,7 @@ func flattenAppConfigurationAccessKeys(values []configurationstores2.AccessKey)
return result
}

func flattenAppConfigurationAccessKey(input configurationstores2.AccessKey) []interface{} {
func flattenAppConfigurationAccessKey(input configurationstores.AccessKey) []interface{} {
connectionString := ""

if input.ConnectionString != nil {
Expand All @@ -402,23 +401,23 @@ func flattenAppConfigurationAccessKey(input configurationstores2.AccessKey) []in
}
}

func expandAppConfigurationIdentity(identities []interface{}) *configurationstores2.ResourceIdentity {
var out = func(in configurationstores2.IdentityType) *configurationstores2.ResourceIdentity {
return &configurationstores2.ResourceIdentity{
func expandAppConfigurationIdentity(identities []interface{}) *configurationstores.ResourceIdentity {
var out = func(in configurationstores.IdentityType) *configurationstores.ResourceIdentity {
return &configurationstores.ResourceIdentity{
Type: &in,
}
}

if len(identities) == 0 {
return out(configurationstores2.IdentityTypeNone)
return out(configurationstores.IdentityTypeNone)
}
identity := identities[0].(map[string]interface{})
identityType := configurationstores2.IdentityType(identity["type"].(string))
identityType := configurationstores.IdentityType(identity["type"].(string))
return out(identityType)
}

func flattenAppConfigurationIdentity(identity *configurationstores2.ResourceIdentity) []interface{} {
if identity == nil || identity.Type == nil || *identity.Type == configurationstores2.IdentityTypeNone {
func flattenAppConfigurationIdentity(identity *configurationstores.ResourceIdentity) []interface{} {
if identity == nil || identity.Type == nil || *identity.Type == configurationstores.IdentityTypeNone {
return []interface{}{}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"log"
"time"

authorizationruleseventhubs2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationruleseventhubs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/eventhubs"

"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/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationruleseventhubs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/eventhubs"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -93,16 +92,16 @@ func resourceEventHubAuthorizationRuleCreateUpdate(d *pluginsdk.ResourceData, me
locks.ByName(id.NamespaceName, eventHubNamespaceResourceName)
defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceResourceName)

parameters := authorizationruleseventhubs2.AuthorizationRule{
parameters := authorizationruleseventhubs.AuthorizationRule{
Name: &id.Name,
Properties: &authorizationruleseventhubs2.AuthorizationRuleProperties{
Properties: &authorizationruleseventhubs.AuthorizationRuleProperties{
Rights: expandEventHubAuthorizationRuleRights(d),
},
}

//lintignore:R006
return pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
localId := authorizationruleseventhubs2.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroup, id.NamespaceName, id.EventhubName, id.Name)
localId := authorizationruleseventhubs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroup, id.NamespaceName, id.EventhubName, id.Name)
if _, err := authorizationRulesClient.EventHubsCreateOrUpdateAuthorizationRule(ctx, localId, parameters); err != nil {
return pluginsdk.NonRetryableError(fmt.Errorf("creating %s: %+v", id, err))
}
Expand Down Expand Up @@ -159,7 +158,7 @@ func resourceEventHubAuthorizationRuleRead(d *pluginsdk.ResourceData, meta inter
}
}

localId := authorizationruleseventhubs2.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroup, id.NamespaceName, id.EventhubName, id.Name)
localId := authorizationruleseventhubs.NewAuthorizationRuleID(id.SubscriptionId, id.ResourceGroup, id.NamespaceName, id.EventhubName, id.Name)
keysResp, err := authorizationRulesClient.EventHubsListKeys(ctx, localId)
if err != nil {
return fmt.Errorf("listing keys for %s: %+v", *id, err)
Expand Down
21 changes: 10 additions & 11 deletions internal/services/eventhub/eventhub_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import (
"strings"
"time"

eventhubsclusters2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/eventhubsclusters"

"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/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/eventhubsclusters"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand All @@ -29,7 +28,7 @@ func resourceEventHubCluster() *pluginsdk.Resource {
Update: resourceEventHubClusterCreateUpdate,
Delete: resourceEventHubClusterDelete,
Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error {
_, err := eventhubsclusters2.ClusterID(id)
_, err := eventhubsclusters.ClusterID(id)
return err
}),

Expand Down Expand Up @@ -75,7 +74,7 @@ func resourceEventHubClusterCreateUpdate(d *pluginsdk.ResourceData, meta interfa
defer cancel()
log.Printf("[INFO] preparing arguments for Azure ARM EventHub Cluster creation.")

id := eventhubsclusters2.NewClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := eventhubsclusters.NewClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
if d.IsNewResource() {
existing, err := client.ClustersGet(ctx, id)
if err != nil {
Expand All @@ -89,7 +88,7 @@ func resourceEventHubClusterCreateUpdate(d *pluginsdk.ResourceData, meta interfa
}
}

cluster := eventhubsclusters2.Cluster{
cluster := eventhubsclusters.Cluster{
Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))),
Tags: expandTags(d.Get("tags").(map[string]interface{})),
Sku: expandEventHubClusterSkuName(d.Get("sku_name").(string)),
Expand All @@ -111,7 +110,7 @@ func resourceEventHubClusterRead(d *pluginsdk.ResourceData, meta interface{}) er
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := eventhubsclusters2.ClusterID(d.Id())
id, err := eventhubsclusters.ClusterID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -141,7 +140,7 @@ func resourceEventHubClusterDelete(d *pluginsdk.ResourceData, meta interface{})
client := meta.(*clients.Client).Eventhub.ClusterClient
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()
id, err := eventhubsclusters2.ClusterID(d.Id())
id, err := eventhubsclusters.ClusterID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -170,7 +169,7 @@ func resourceEventHubClusterDelete(d *pluginsdk.ResourceData, meta interface{})
}) //lintignore:R006
}

func expandEventHubClusterSkuName(skuName string) *eventhubsclusters2.ClusterSku {
func expandEventHubClusterSkuName(skuName string) *eventhubsclusters.ClusterSku {
if len(skuName) == 0 {
return nil
}
Expand All @@ -180,13 +179,13 @@ func expandEventHubClusterSkuName(skuName string) *eventhubsclusters2.ClusterSku
return nil
}

return &eventhubsclusters2.ClusterSku{
Name: eventhubsclusters2.ClusterSkuName(name),
return &eventhubsclusters.ClusterSku{
Name: eventhubsclusters.ClusterSkuName(name),
Capacity: utils.Int64(int64(capacity)),
}
}

func flattenEventHubClusterSkuName(input *eventhubsclusters2.ClusterSku) string {
func flattenEventHubClusterSkuName(input *eventhubsclusters.ClusterSku) string {
if input == nil || input.Capacity == nil {
return ""
}
Expand Down
19 changes: 9 additions & 10 deletions internal/services/eventhub/eventhub_consumer_group_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import (
"fmt"
"time"

consumergroups2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/consumergroups"

"github.com/hashicorp/go-azure-helpers/response"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/consumergroups"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
Expand Down Expand Up @@ -84,7 +83,7 @@ func (r ConsumerGroupResource) Create() sdk.ResourceFunc {
client := metadata.Client.Eventhub.ConsumerGroupClient
subscriptionId := metadata.Client.Account.SubscriptionId

id := consumergroups2.NewConsumergroupID(subscriptionId, state.ResourceGroupName, state.NamespaceName, state.EventHubName, state.Name)
id := consumergroups.NewConsumergroupID(subscriptionId, state.ResourceGroupName, state.NamespaceName, state.EventHubName, state.Name)
existing, err := client.Get(ctx, id)
if err != nil && !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for the presence of an existing %s: %+v", id, err)
Expand All @@ -93,9 +92,9 @@ func (r ConsumerGroupResource) Create() sdk.ResourceFunc {
return metadata.ResourceRequiresImport(r.ResourceType(), id)
}

parameters := consumergroups2.ConsumerGroup{
parameters := consumergroups.ConsumerGroup{
Name: utils.String(state.Name),
Properties: &consumergroups2.ConsumerGroupProperties{
Properties: &consumergroups.ConsumerGroupProperties{
UserMetadata: utils.String(state.UserMetadata),
},
}
Expand All @@ -114,7 +113,7 @@ func (r ConsumerGroupResource) Create() sdk.ResourceFunc {
func (r ConsumerGroupResource) Update() sdk.ResourceFunc {
return sdk.ResourceFunc{
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
id, err := consumergroups2.ConsumergroupID(metadata.ResourceData.Id())
id, err := consumergroups.ConsumergroupID(metadata.ResourceData.Id())
if err != nil {
return err
}
Expand All @@ -128,9 +127,9 @@ func (r ConsumerGroupResource) Update() sdk.ResourceFunc {
metadata.Logger.Infof("updating Consumer Group %q..", state.Name)
client := metadata.Client.Eventhub.ConsumerGroupClient

parameters := consumergroups2.ConsumerGroup{
parameters := consumergroups.ConsumerGroup{
Name: utils.String(id.Name),
Properties: &consumergroups2.ConsumerGroupProperties{
Properties: &consumergroups.ConsumerGroupProperties{
UserMetadata: utils.String(state.UserMetadata),
},
}
Expand All @@ -149,7 +148,7 @@ func (r ConsumerGroupResource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Eventhub.ConsumerGroupClient
id, err := consumergroups2.ConsumergroupID(metadata.ResourceData.Id())
id, err := consumergroups.ConsumergroupID(metadata.ResourceData.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -184,7 +183,7 @@ func (r ConsumerGroupResource) Delete() sdk.ResourceFunc {
return sdk.ResourceFunc{
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.Eventhub.ConsumerGroupClient
id, err := consumergroups2.ConsumergroupID(metadata.ResourceData.Id())
id, err := consumergroups.ConsumergroupID(metadata.ResourceData.Id())
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"log"
"time"

authorizationrulesnamespaces2 "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationrulesnamespaces"

"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/locks"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationrulesnamespaces"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
Expand Down Expand Up @@ -71,7 +70,7 @@ func resourceEventHubNamespaceAuthorizationRuleCreateUpdate(d *pluginsdk.Resourc

log.Printf("[INFO] preparing arguments for AzureRM EventHub Namespace Authorization Rule creation.")

id := authorizationrulesnamespaces2.NewAuthorizationRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("namespace_name").(string), d.Get("name").(string))
id := authorizationrulesnamespaces.NewAuthorizationRuleID(subscriptionId, d.Get("resource_group_name").(string), d.Get("namespace_name").(string), d.Get("name").(string))
if d.IsNewResource() {
existing, err := client.NamespacesGetAuthorizationRule(ctx, id)
if err != nil {
Expand All @@ -88,9 +87,9 @@ func resourceEventHubNamespaceAuthorizationRuleCreateUpdate(d *pluginsdk.Resourc
locks.ByName(id.NamespaceName, eventHubNamespaceResourceName)
defer locks.UnlockByName(id.NamespaceName, eventHubNamespaceResourceName)

parameters := authorizationrulesnamespaces2.AuthorizationRule{
parameters := authorizationrulesnamespaces.AuthorizationRule{
Name: &id.Name,
Properties: &authorizationrulesnamespaces2.AuthorizationRuleProperties{
Properties: &authorizationrulesnamespaces.AuthorizationRuleProperties{
Rights: expandEventHubAuthorizationRuleRights(d),
},
}
Expand All @@ -108,7 +107,7 @@ func resourceEventHubNamespaceAuthorizationRuleRead(d *pluginsdk.ResourceData, m
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := authorizationrulesnamespaces2.AuthorizationRuleID(d.Id())
id, err := authorizationrulesnamespaces.AuthorizationRuleID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -157,7 +156,7 @@ func resourceEventHubNamespaceAuthorizationRuleDelete(d *pluginsdk.ResourceData,
ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d)
defer cancel()

id, err := authorizationrulesnamespaces2.AuthorizationRuleID(d.Id())
id, err := authorizationrulesnamespaces.AuthorizationRuleID(d.Id())
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 8cf3d21

Please sign in to comment.