Skip to content

Commit

Permalink
refactoring clients: phase 4 (#5127)
Browse files Browse the repository at this point in the history
* resources: refactoring the client into a package

* relay: refactoring the client into a package

* redis: refactoring to use the new pattern

* recoveryservices: refactoring to use modules

* privatedns: refactoring to use the new structure

* postgresql: refactoring to use the new structure

* portal: refactoring to use the new structure

* policy: refactoring to use the new package

* notificationhub: refactoring to use the new structure

* network: refactoring to use the new structure

* netapp: refactoring to use the new structure

* refactor: consistent naming
  • Loading branch information
tombuildsstuff authored and katbyte committed Dec 10, 2019
1 parent cbb2b05 commit 80499ee
Show file tree
Hide file tree
Showing 52 changed files with 501 additions and 248 deletions.
22 changes: 0 additions & 22 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,6 @@ import (
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/notificationhub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/relay"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/scheduler"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/search"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter"
Expand Down Expand Up @@ -136,17 +125,6 @@ func (client *ArmClient) Build(o *common.ClientOptions) error {
}

// TODO: move these Clients inside of Common so this method can be moved in there
client.Netapp = netapp.BuildClient(o)
client.Network = network.BuildClient(o)
client.NotificationHubs = notificationhub.BuildClient(o)
client.Policy = policy.BuildClient(o)
client.Portal = portal.BuildClient(o)
client.Postgres = postgres.BuildClient(o)
client.PrivateDns = privatedns.BuildClient(o)
client.RecoveryServices = recoveryservices.BuildClient(o)
client.Redis = redis.BuildClient(o)
client.Relay = relay.BuildClient(o)
client.Resource = resource.BuildClient(o)
client.Search = search.BuildClient(o)
client.SecurityCenter = securitycenter.BuildClient(o)
client.ServiceBus = servicebus.BuildClient(o)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_healthcare_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func dataSourceArmHealthcareService() *schema.Resource {
}

func dataSourceArmHealthcareServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Healthcare.HealthcareServiceClient
client := meta.(*ArmClient).HealthCare.HealthcareServiceClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_mssql_elasticpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func dataSourceArmMsSqlElasticpool() *schema.Resource {
}

func dataSourceArmMsSqlElasticpoolRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Mssql.ElasticPoolsClient
client := meta.(*ArmClient).MSSQL.ElasticPoolsClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_netapp_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func dataSourceArmNetAppAccount() *schema.Resource {
}

func dataSourceArmNetAppAccountRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Netapp.AccountClient
client := meta.(*ArmClient).NetApp.AccountClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_netapp_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func dataSourceArmNetAppPool() *schema.Resource {
}

func dataSourceArmNetAppPoolRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Netapp.PoolClient
client := meta.(*ArmClient).NetApp.PoolClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_user_assigned_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func dataSourceArmUserAssignedIdentity() *schema.Resource {
}

func dataSourceArmUserAssignedIdentityRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).Msi.UserAssignedIdentitiesClient
client := meta.(*ArmClient).MSI.UserAssignedIdentitiesClient
ctx, cancel := timeouts.ForRead(meta.(*ArmClient).StopContext, d)
defer cancel()

Expand Down
56 changes: 34 additions & 22 deletions azurerm/internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ import (
msi "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi/client"
mssql "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql/client"
mysql "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mysql/client"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/notificationhub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/relay"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource"
netapp "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/netapp/client"
network "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/client"
notificationhub "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/notificationhub/client"
policy "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy/client"
portal "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal/client"
postgres "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres/client"
privatedns "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns/client"
recoveryServices "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices/client"
redis "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis/client"
relay "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/relay/client"
resource "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource/client"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/scheduler"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/search"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/securitycenter"
Expand Down Expand Up @@ -99,7 +99,7 @@ type Client struct {
Frontdoor *frontdoor.Client
Graph *graph.Client
HDInsight *hdinsight.Client
Healthcare *healthcare.Client
HealthCare *healthcare.Client

// Phrase 3
IoTHub *iothub.Client
Expand All @@ -112,19 +112,19 @@ type Client struct {
MariaDB *mariadb.Client
Media *media.Client
Monitor *monitor.Client
Msi *msi.Client
Mssql *mssql.Client
Mysql *mysql.Client
MSI *msi.Client
MSSQL *mssql.Client
MySQL *mysql.Client

// TODO: Phase 4
Netapp *netapp.Client
// Phase 4
NetApp *netapp.Client
Network *network.Client
NotificationHubs *notificationhub.Client
Policy *policy.Client
Portal *portal.Client
Postgres *postgres.Client
PrivateDns *privatedns.Client
RecoveryServices *recoveryservices.Client
RecoveryServices *recoveryServices.Client
Redis *redis.Client
Relay *relay.Client
Resource *resource.Client
Expand Down Expand Up @@ -169,7 +169,7 @@ func (client *Client) Build(o *common.ClientOptions) error {
client.Frontdoor = frontdoor.NewClient(o)
client.Graph = graph.NewClient(o)
client.HDInsight = hdinsight.NewClient(o)
client.Healthcare = healthcare.NewClient(o)
client.HealthCare = healthcare.NewClient(o)
client.IoTHub = iothub.NewClient(o)
client.KeyVault = keyvault.NewClient(o)
client.Kusto = kusto.NewClient(o)
Expand All @@ -180,9 +180,21 @@ func (client *Client) Build(o *common.ClientOptions) error {
client.MariaDB = mariadb.NewClient(o)
client.Media = media.NewClient(o)
client.Monitor = monitor.NewClient(o)
client.Msi = msi.NewClient(o)
client.Mssql = mssql.NewClient(o)
client.Mysql = mysql.NewClient(o)
client.MSI = msi.NewClient(o)
client.MSSQL = mssql.NewClient(o)
client.MySQL = mysql.NewClient(o)

client.NetApp = netapp.NewClient(o)
client.Network = network.NewClient(o)
client.NotificationHubs = notificationhub.NewClient(o)
client.Policy = policy.NewClient(o)
client.Portal = portal.NewClient(o)
client.Postgres = postgres.NewClient(o)
client.PrivateDns = privatedns.NewClient(o)
client.RecoveryServices = recoveryServices.NewClient(o)
client.Redis = redis.NewClient(o)
client.Relay = relay.NewClient(o)
client.Resource = resource.NewClient(o)

return nil
}
21 changes: 21 additions & 0 deletions azurerm/internal/provider/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/msi"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mssql"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/mysql"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/notificationhub"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/portal"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/privatedns"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/recoveryservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/redis"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/relay"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/resource"
)

func SupportedServices() []common.ServiceRegistration {
Expand Down Expand Up @@ -80,5 +90,16 @@ func SupportedServices() []common.ServiceRegistration {
msi.Registration{},
mssql.Registration{},
mysql.Registration{},

network.Registration{},
notificationhub.Registration{},
policy.Registration{},
portal.Registration{},
postgres.Registration{},
privatedns.Registration{},
recoveryservices.Registration{},
redis.Registration{},
relay.Registration{},
resource.Registration{},
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package netapp
package client

import (
"github.com/Azure/azure-sdk-for-go/services/netapp/mgmt/2019-06-01/netapp"
Expand All @@ -10,7 +10,7 @@ type Client struct {
PoolClient *netapp.PoolsClient
}

func BuildClient(o *common.ClientOptions) *Client {
func NewClient(o *common.ClientOptions) *Client {
accountClient := netapp.NewAccountsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&accountClient.Client, o.ResourceManagerAuthorizer)

Expand Down
22 changes: 22 additions & 0 deletions azurerm/internal/services/netapp/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package netapp

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "NetApp"
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package client

import (
"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
Expand Down Expand Up @@ -43,7 +43,7 @@ type Client struct {
PrivateLinkServiceClient *network.PrivateLinkServicesClient
}

func BuildClient(o *common.ClientOptions) *Client {
func NewClient(o *common.ClientOptions) *Client {
ApplicationGatewaysClient := network.NewApplicationGatewaysClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&ApplicationGatewaysClient.Client, o.ResourceManagerAuthorizer)

Expand Down
22 changes: 22 additions & 0 deletions azurerm/internal/services/network/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package network

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "Network"
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package notificationhub
package client

import (
"github.com/Azure/azure-sdk-for-go/services/notificationhubs/mgmt/2017-04-01/notificationhubs"
Expand All @@ -10,15 +10,15 @@ type Client struct {
NamespacesClient *notificationhubs.NamespacesClient
}

func BuildClient(o *common.ClientOptions) *Client {
NamespacesClient := notificationhubs.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer)
func NewClient(o *common.ClientOptions) *Client {
hubsClient := notificationhubs.NewClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&hubsClient.Client, o.ResourceManagerAuthorizer)

HubsClient := notificationhubs.NewClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&HubsClient.Client, o.ResourceManagerAuthorizer)
namespacesClient := notificationhubs.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&namespacesClient.Client, o.ResourceManagerAuthorizer)

return &Client{
HubsClient: &HubsClient,
NamespacesClient: &NamespacesClient,
HubsClient: &hubsClient,
NamespacesClient: &namespacesClient,
}
}
22 changes: 22 additions & 0 deletions azurerm/internal/services/notificationhub/registration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package notificationhub

import (
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)

type Registration struct{}

// Name is the name of this Service
func (r Registration) Name() string {
return "Notification Hub"
}

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}

// SupportedResources returns the supported Resources supported by this Service
func (r Registration) SupportedResources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
}
29 changes: 0 additions & 29 deletions azurerm/internal/services/policy/client.go

This file was deleted.

Loading

0 comments on commit 80499ee

Please sign in to comment.