Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate clients #3999

Merged
merged 1 commit into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

resourcesprofile "github.com/Azure/azure-sdk-for-go/profiles/2017-03-09/resources/mgmt/resources"
"github.com/Azure/azure-sdk-for-go/services/analysisservices/mgmt/2017-08-01/analysisservices"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
analyticsAccount "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"
Expand All @@ -24,7 +23,6 @@ import (
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-05-01/resources"
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2018-06-01/subscriptions"
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-04-01/storage"
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
mainStorage "github.com/Azure/azure-sdk-for-go/storage"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
Expand All @@ -33,6 +31,7 @@ import (
"github.com/hashicorp/go-azure-helpers/sender"
"github.com/hashicorp/terraform/httpclient"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/analysisservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/applicationinsights"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/authorization"
Expand Down Expand Up @@ -76,6 +75,7 @@ import (
intStor "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/storage"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/streamanalytics"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/trafficmanager"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/web"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
"github.com/terraform-providers/terraform-provider-azurerm/version"
)
Expand All @@ -94,6 +94,7 @@ type ArmClient struct {
StopContext context.Context

// Services
analysisservices *analysisservices.Client
apiManagement *apimanagement.Client
appInsights *applicationinsights.Client
automation *automation.Client
Expand Down Expand Up @@ -137,6 +138,7 @@ type ArmClient struct {
storage *intStor.Client
streamanalytics *streamanalytics.Client
trafficManager *trafficmanager.Client
web *web.Client

// Authentication
applicationsClient graphrbac.ApplicationsClient
Expand Down Expand Up @@ -226,13 +228,6 @@ type ArmClient struct {
// Storage
storageServiceClient storage.AccountsClient
storageUsageClient storage.UsagesClient

// Web
appServicePlansClient web.AppServicePlansClient
appServicesClient web.AppsClient

// Analysis Services
analysisServicesServerClient analysisservices.ServersClient
}

func (c *ArmClient) configureClient(client *autorest.Client, auth autorest.Authorizer) {
Expand Down Expand Up @@ -341,6 +336,7 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool, partn
Environment: *env,
}

client.analysisservices = analysisservices.BuildClient(o)
client.apiManagement = apimanagement.BuildClient(o)
client.appInsights = applicationinsights.BuildClient(o)
client.automation = automation.BuildClient(o)
Expand Down Expand Up @@ -382,6 +378,7 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool, partn
client.signalr = signalr.BuildClient(o)
client.streamanalytics = streamanalytics.BuildClient(o)
client.trafficManager = trafficmanager.BuildClient(o)
client.web = web.BuildClient(o)

client.registerAuthentication(endpoint, graphEndpoint, c.SubscriptionID, c.TenantID, auth, graphAuth)
client.registerComputeClients(endpoint, c.SubscriptionID, auth)
Expand All @@ -391,8 +388,6 @@ func getArmClient(c *authentication.Config, skipProviderRegistration bool, partn
client.registerNetworkingClients(endpoint, c.SubscriptionID, auth)
client.registerResourcesClients(endpoint, c.SubscriptionID, auth)
client.registerStorageClients(endpoint, c.SubscriptionID, auth, o)
client.registerWebClients(endpoint, c.SubscriptionID, auth)
client.registerAnalysisServicesClients(endpoint, c.SubscriptionID, auth)

return &client, nil
}
Expand Down Expand Up @@ -698,22 +693,6 @@ func (c *ArmClient) registerStorageClients(endpoint, subscriptionId string, auth
c.storage = intStor.BuildClient(accountsClient, options)
}

func (c *ArmClient) registerWebClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
appServicePlansClient := web.NewAppServicePlansClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&appServicePlansClient.Client, auth)
c.appServicePlansClient = appServicePlansClient

appsClient := web.NewAppsClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&appsClient.Client, auth)
c.appServicesClient = appsClient
}

func (c *ArmClient) registerAnalysisServicesClients(endpoint, subscriptionId string, auth autorest.Authorizer) {
analysisServicesServersClient := analysisservices.NewServersClientWithBaseURI(endpoint, subscriptionId)
c.configureClient(&analysisServicesServersClient.Client, auth)
c.analysisServicesServerClient = analysisServicesServersClient
}

var (
storageKeyCacheMu sync.RWMutex
storageKeyCache = make(map[string]string)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func dataSourceArmAppService() *schema.Resource {
}
}
func dataSourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient

resourceGroup := d.Get("resource_group_name").(string)
name := d.Get("name").(string)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func dataSourceAppServicePlan() *schema.Resource {
}

func dataSourceAppServicePlanRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicePlansClient
client := meta.(*ArmClient).web.AppServicePlansClient

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)
Expand Down
19 changes: 19 additions & 0 deletions azurerm/internal/services/analysisservices/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package analysisservices

import (
"github.com/Azure/azure-sdk-for-go/services/analysisservices/mgmt/2017-08-01/analysisservices"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
ServerClient analysisservices.ServersClient
}

func BuildClient(o *common.ClientOptions) *Client {
c := Client{}

c.ServerClient = analysisservices.NewServersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&c.ServerClient.Client, o.ResourceManagerAuthorizer)

return &c
}
23 changes: 23 additions & 0 deletions azurerm/internal/services/web/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package web

import (
"github.com/Azure/azure-sdk-for-go/services/web/mgmt/2018-02-01/web"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/common"
)

type Client struct {
AppServicePlansClient web.AppServicePlansClient
AppServicesClient web.AppsClient
}

func BuildClient(o *common.ClientOptions) *Client {
c := Client{}

c.AppServicePlansClient = web.NewAppServicePlansClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&c.AppServicePlansClient.Client, o.ResourceManagerAuthorizer)

c.AppServicesClient = web.NewAppsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&c.AppServicesClient.Client, o.ResourceManagerAuthorizer)

return &c
}
8 changes: 4 additions & 4 deletions azurerm/resource_arm_analysis_services_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func resourceArmAnalysisServicesServer() *schema.Resource {
}

func resourceArmAnalysisServicesServerCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).analysisServicesServerClient
client := meta.(*ArmClient).analysisservices.ServerClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for Azure ARM Analysis Services Server creation.")
Expand Down Expand Up @@ -160,7 +160,7 @@ func resourceArmAnalysisServicesServerCreate(d *schema.ResourceData, meta interf
}

func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).analysisServicesServerClient
client := meta.(*ArmClient).analysisservices.ServerClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down Expand Up @@ -214,7 +214,7 @@ func resourceArmAnalysisServicesServerRead(d *schema.ResourceData, meta interfac
}

func resourceArmAnalysisServicesServerUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).analysisServicesServerClient
client := meta.(*ArmClient).analysisservices.ServerClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for Azure ARM Analysis Services Server creation.")
Expand Down Expand Up @@ -250,7 +250,7 @@ func resourceArmAnalysisServicesServerUpdate(d *schema.ResourceData, meta interf
}

func resourceArmAnalysisServicesServerDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).analysisServicesServerClient
client := meta.(*ArmClient).analysisservices.ServerClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_analysis_services_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ resource "azurerm_analysis_services_server" "test" {
}

func testCheckAzureRMAnalysisServicesServerDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).analysisServicesServerClient
client := testAccProvider.Meta().(*ArmClient).analysisservices.ServerClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_analysis_services_server" {
Expand Down Expand Up @@ -393,7 +393,7 @@ func testCheckAzureRMAnalysisServicesServerExists(resourceName string) resource.
return fmt.Errorf("Bad: no resource group found in state for Analysis Services Server: %s", analysisServicesServerName)
}

client := testAccProvider.Meta().(*ArmClient).analysisServicesServerClient
client := testAccProvider.Meta().(*ArmClient).analysisservices.ServerClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.GetDetails(ctx, resourceGroup, analysisServicesServerName)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions azurerm/resource_arm_app_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func resourceArmAppService() *schema.Resource {
}

func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for AzureRM App Service creation.")
Expand Down Expand Up @@ -295,7 +295,7 @@ func resourceArmAppServiceCreate(d *schema.ResourceData, meta interface{}) error
}

func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down Expand Up @@ -468,7 +468,7 @@ func resourceArmAppServiceUpdate(d *schema.ResourceData, meta interface{}) error
}

func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand Down Expand Up @@ -629,7 +629,7 @@ func resourceArmAppServiceRead(d *schema.ResourceData, meta interface{}) error {
}

func resourceArmAppServiceDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_app_service_active_slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func resourceArmAppServiceActiveSlot() *schema.Resource {
}

func resourceArmAppServiceActiveSlotCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient
ctx := meta.(*ArmClient).StopContext

appServiceName := d.Get("app_service_name").(string)
Expand Down Expand Up @@ -79,7 +79,7 @@ func resourceArmAppServiceActiveSlotCreateUpdate(d *schema.ResourceData, meta in
}

func resourceArmAppServiceActiveSlotRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down
6 changes: 3 additions & 3 deletions azurerm/resource_arm_app_service_custom_hostname_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func resourceArmAppServiceCustomHostnameBinding() *schema.Resource {
}

func resourceArmAppServiceCustomHostnameBindingCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for App Service Hostname Binding creation.")
Expand Down Expand Up @@ -90,7 +90,7 @@ func resourceArmAppServiceCustomHostnameBindingCreate(d *schema.ResourceData, me
}

func resourceArmAppServiceCustomHostnameBindingRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand Down Expand Up @@ -120,7 +120,7 @@ func resourceArmAppServiceCustomHostnameBindingRead(d *schema.ResourceData, meta
}

func resourceArmAppServiceCustomHostnameBindingDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicesClient
client := meta.(*ArmClient).web.AppServicesClient

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func testAccAzureRMAppServiceCustomHostnameBinding_multiple(t *testing.T, appSer
}

func testCheckAzureRMAppServiceCustomHostnameBindingDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*ArmClient).appServicesClient
client := testAccProvider.Meta().(*ArmClient).web.AppServicesClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_app_service_custom_hostname_binding" {
Expand Down Expand Up @@ -170,7 +170,7 @@ func testCheckAzureRMAppServiceCustomHostnameBindingExists(resourceName string)
appServiceName := rs.Primary.Attributes["app_service_name"]
hostname := rs.Primary.Attributes["hostname"]

client := testAccProvider.Meta().(*ArmClient).appServicesClient
client := testAccProvider.Meta().(*ArmClient).web.AppServicesClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.GetHostNameBinding(ctx, resourceGroup, appServiceName, hostname)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions azurerm/resource_arm_app_service_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func resourceArmAppServicePlan() *schema.Resource {
}

func resourceArmAppServicePlanCreateUpdate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicePlansClient
client := meta.(*ArmClient).web.AppServicePlansClient
ctx := meta.(*ArmClient).StopContext

log.Printf("[INFO] preparing arguments for AzureRM App Service Plan creation.")
Expand Down Expand Up @@ -255,7 +255,7 @@ func resourceArmAppServicePlanCreateUpdate(d *schema.ResourceData, meta interfac
}

func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicePlansClient
client := meta.(*ArmClient).web.AppServicePlansClient

id, err := parseAzureResourceID(d.Id())
if err != nil {
Expand Down Expand Up @@ -326,7 +326,7 @@ func resourceArmAppServicePlanRead(d *schema.ResourceData, meta interface{}) err
}

func resourceArmAppServicePlanDelete(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).appServicePlansClient
client := meta.(*ArmClient).web.AppServicePlansClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_app_service_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ func TestAccAzureRMAppServicePlan_basicWindowsContainer(t *testing.T) {
}

func testCheckAzureRMAppServicePlanDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*ArmClient).appServicePlansClient
conn := testAccProvider.Meta().(*ArmClient).web.AppServicePlansClient

for _, rs := range s.RootModule().Resources {
if rs.Type != "azurerm_app_service_plan" {
Expand Down Expand Up @@ -364,7 +364,7 @@ func testCheckAzureRMAppServicePlanExists(resourceName string) resource.TestChec
return fmt.Errorf("Bad: no resource group found in state for App Service Plan: %s", appServicePlanName)
}

conn := testAccProvider.Meta().(*ArmClient).appServicePlansClient
conn := testAccProvider.Meta().(*ArmClient).web.AppServicePlansClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := conn.Get(ctx, resourceGroup, appServicePlanName)
if err != nil {
Expand Down
Loading