Skip to content

Commit

Permalink
Merge pull request #3544 from terraform-providers/f/refactor
Browse files Browse the repository at this point in the history
Refactor: migrating clients into packages
  • Loading branch information
tombuildsstuff authored May 30, 2019
2 parents 19a3f4c + 5990af0 commit d66f52a
Show file tree
Hide file tree
Showing 133 changed files with 594 additions and 498 deletions.
8 changes: 4 additions & 4 deletions azurerm/automation_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func datasourceAutomationVariableCommonSchema(attType schema.ValueType) map[stri
}

func resourceAutomationVariableCreateUpdate(d *schema.ResourceData, meta interface{}, varType string) error {
client := meta.(*ArmClient).automationVariableClient
client := meta.(*ArmClient).automation.VariableClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
Expand Down Expand Up @@ -188,7 +188,7 @@ func resourceAutomationVariableCreateUpdate(d *schema.ResourceData, meta interfa
}

func resourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error {
client := meta.(*ArmClient).automationVariableClient
client := meta.(*ArmClient).automation.VariableClient
ctx := meta.(*ArmClient).StopContext

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

func datasourceAutomationVariableRead(d *schema.ResourceData, meta interface{}, varType string) error {
client := meta.(*ArmClient).automationVariableClient
client := meta.(*ArmClient).automation.VariableClient
ctx := meta.(*ArmClient).StopContext

resourceGroup := d.Get("resource_group_name").(string)
Expand Down Expand Up @@ -279,7 +279,7 @@ func datasourceAutomationVariableRead(d *schema.ResourceData, meta interface{},
}

func resourceAutomationVariableDelete(d *schema.ResourceData, meta interface{}, varType string) error {
client := meta.(*ArmClient).automationVariableClient
client := meta.(*ArmClient).automation.VariableClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down
4 changes: 2 additions & 2 deletions azurerm/automation_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func testCheckAzureRMAutomationVariableExists(resourceName string, varType strin
resourceGroup := rs.Primary.Attributes["resource_group_name"]
accountName := rs.Primary.Attributes["automation_account_name"]

client := testAccProvider.Meta().(*ArmClient).automationVariableClient
client := testAccProvider.Meta().(*ArmClient).automation.VariableClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

if resp, err := client.Get(ctx, resourceGroup, accountName, name); err != nil {
Expand All @@ -105,7 +105,7 @@ func testCheckAzureRMAutomationVariableExists(resourceName string, varType strin
}

func testCheckAzureRMAutomationVariableDestroy(s *terraform.State, varType string) error {
client := testAccProvider.Meta().(*ArmClient).automationVariableClient
client := testAccProvider.Meta().(*ArmClient).automation.VariableClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext

resourceName := fmt.Sprintf("azurerm_automation_variable_%s", strings.ToLower(varType))
Expand Down
4 changes: 2 additions & 2 deletions azurerm/common_hdinsight.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema.UpdateFunc {
return func(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).hdinsightClustersClient
client := meta.(*ArmClient).hdinsight.ClustersClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down Expand Up @@ -60,7 +60,7 @@ func hdinsightClusterUpdate(clusterKind string, readFunc schema.ReadFunc) schema

func hdinsightClusterDelete(clusterKind string) schema.DeleteFunc {
return func(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).hdinsightClustersClient
client := meta.(*ArmClient).hdinsight.ClustersClient
ctx := meta.(*ArmClient).StopContext

id, err := parseAzureResourceID(d.Id())
Expand Down
4 changes: 2 additions & 2 deletions azurerm/common_hdinsight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func testCheckAzureRMHDInsightClusterDestroy(terraformResourceName string) func(
continue
}

client := testAccProvider.Meta().(*ArmClient).hdinsightClustersClient
client := testAccProvider.Meta().(*ArmClient).hdinsight.ClustersClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
name := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]
Expand Down Expand Up @@ -43,7 +43,7 @@ func testCheckAzureRMHDInsightClusterExists(resourceName string) resource.TestCh
clusterName := rs.Primary.Attributes["name"]
resourceGroup := rs.Primary.Attributes["resource_group_name"]

client := testAccProvider.Meta().(*ArmClient).hdinsightClustersClient
client := testAccProvider.Meta().(*ArmClient).hdinsight.ClustersClient
ctx := testAccProvider.Meta().(*ArmClient).StopContext
resp, err := client.Get(ctx, resourceGroup, clusterName)
if err != nil {
Expand Down
304 changes: 139 additions & 165 deletions azurerm/config.go

Large diffs are not rendered by default.

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

func dataSourceApiManagementRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).apiManagementServiceClient
client := meta.(*ArmClient).apimgmt.ServiceClient

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

func dataSourceApiManagementApiRead(d *schema.ResourceData, meta interface{}) error {
ctx := meta.(*ArmClient).StopContext
client := meta.(*ArmClient).apiManagementApiClient
client := meta.(*ArmClient).apimgmt.ApiClient

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

func dataSourceApiManagementGroupRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).apiManagementGroupClient
client := meta.(*ArmClient).apimgmt.GroupClient
ctx := meta.(*ArmClient).StopContext

resourceGroup := d.Get("resource_group_name").(string)
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_api_management_product.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func dataSourceApiManagementProduct() *schema.Resource {
}
}
func dataSourceApiManagementProductRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).apiManagementProductsClient
client := meta.(*ArmClient).apimgmt.ProductsClient
ctx := meta.(*ArmClient).StopContext

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

func dataSourceArmApiManagementUserRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).apiManagementUsersClient
client := meta.(*ArmClient).apimgmt.UsersClient
ctx := meta.(*ArmClient).StopContext

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

func dataSourceArmContainerRegistryRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).containerRegistryClient
client := meta.(*ArmClient).containers.RegistryClient
ctx := meta.(*ArmClient).StopContext

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

func dataSourceArmDnsZoneRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).zonesClient
client := meta.(*ArmClient).dns.ZonesClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
Expand Down
4 changes: 2 additions & 2 deletions azurerm/data_source_hdinsight_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func dataSourceArmHDInsightSparkCluster() *schema.Resource {
}

func dataSourceArmHDInsightClusterRead(d *schema.ResourceData, meta interface{}) error {
clustersClient := meta.(*ArmClient).hdinsightClustersClient
configurationsClient := meta.(*ArmClient).hdinsightConfigurationsClient
clustersClient := meta.(*ArmClient).hdinsight.ClustersClient
configurationsClient := meta.(*ArmClient).hdinsight.ConfigurationsClient
ctx := meta.(*ArmClient).StopContext

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

func dataSourceArmKubernetesClusterRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).kubernetesClustersClient
client := meta.(*ArmClient).containers.KubernetesClustersClient
ctx := meta.(*ArmClient).StopContext

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

func dataSourceArmKubernetesServiceVersionsRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).containerServicesClient
client := meta.(*ArmClient).containers.ServicesClient
ctx := meta.(*ArmClient).StopContext

location := azureRMNormalizeLocation(d.Get("location").(string))
Expand Down
2 changes: 1 addition & 1 deletion azurerm/data_source_log_analytics_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func dataSourceLogAnalyticsWorkspace() *schema.Resource {
}

func dataSourceLogAnalyticsWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).workspacesClient
client := meta.(*ArmClient).logAnalytics.WorkspacesClient
ctx := meta.(*ArmClient).StopContext

name := d.Get("name").(string)
Expand Down
7 changes: 2 additions & 5 deletions azurerm/feature_flags.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package azurerm

import (
"os"
"strings"
)
import "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/flags"

// NOTE: we'll need to add an infobox to MySQL|PostgreSQL Configuration when this goes live
// since these resources can't support import
// in addition the virtual resources will need adjusting

// This file contains feature flags for functionality which will prove more challenging to implement en-mass
var requireResourcesToBeImported = strings.EqualFold(os.Getenv("ARM_PROVIDER_STRICT"), "true")
var requireResourcesToBeImported = flags.RequireResourcesToBeImported
13 changes: 13 additions & 0 deletions azurerm/internal/flags/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package flags

import (
"os"
"strings"
)

// NOTE: we'll need to add an infobox to MySQL|PostgreSQL Configuration when this goes live
// since these resources can't support import
// in addition the virtual resources will need adjusting

// This file contains feature flags for functionality which will prove more challenging to implement en-mass
var RequireResourcesToBeImported = strings.EqualFold(os.Getenv("ARM_PROVIDER_STRICT"), "true")
29 changes: 29 additions & 0 deletions azurerm/internal/services/apimgmt/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package apimgmt

import "github.com/Azure/azure-sdk-for-go/services/apimanagement/mgmt/2018-01-01/apimanagement"

type Client struct {
ApiClient apimanagement.APIClient
ApiPoliciesClient apimanagement.APIPolicyClient
ApiOperationsClient apimanagement.APIOperationClient
ApiOperationPoliciesClient apimanagement.APIOperationPolicyClient
ApiSchemasClient apimanagement.APISchemaClient
ApiVersionSetClient apimanagement.APIVersionSetClient
AuthorizationServersClient apimanagement.AuthorizationServerClient
CertificatesClient apimanagement.CertificateClient
GroupClient apimanagement.GroupClient
GroupUsersClient apimanagement.GroupUserClient
LoggerClient apimanagement.LoggerClient
OpenIdConnectClient apimanagement.OpenIDConnectProviderClient
PolicyClient apimanagement.PolicyClient
ProductsClient apimanagement.ProductClient
ProductApisClient apimanagement.ProductAPIClient
ProductGroupsClient apimanagement.ProductGroupClient
ProductPoliciesClient apimanagement.ProductPolicyClient
PropertyClient apimanagement.PropertyClient
ServiceClient apimanagement.ServiceClient
SignInClient apimanagement.SignInSettingsClient
SignUpClient apimanagement.SignUpSettingsClient
SubscriptionsClient apimanagement.SubscriptionClient
UsersClient apimanagement.UserClient
}
16 changes: 16 additions & 0 deletions azurerm/internal/services/automation/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package automation

import "github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation"

type Client struct {
AccountClient automation.AccountClient
AgentRegistrationInfoClient automation.AgentRegistrationInformationClient
CredentialClient automation.CredentialClient
DscConfigurationClient automation.DscConfigurationClient
DscNodeConfigurationClient automation.DscNodeConfigurationClient
ModuleClient automation.ModuleClient
RunbookClient automation.RunbookClient
RunbookDraftClient automation.RunbookDraftClient
ScheduleClient automation.ScheduleClient
VariableClient automation.VariableClient
}
15 changes: 15 additions & 0 deletions azurerm/internal/services/containers/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package containers

import (
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-10-01/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-02-01/containerservice"
)

type Client struct {
KubernetesClustersClient containerservice.ManagedClustersClient
GroupsClient containerinstance.ContainerGroupsClient
RegistryClient containerregistry.RegistriesClient
RegistryReplicationsClient containerregistry.ReplicationsClient
ServicesClient containerservice.ContainerServicesClient
}
7 changes: 7 additions & 0 deletions azurerm/internal/services/devspace/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package devspace

import "github.com/Azure/azure-sdk-for-go/services/preview/devspaces/mgmt/2018-06-01-preview/devspaces"

type Client struct {
ControllersClient devspaces.ControllersClient
}
8 changes: 8 additions & 0 deletions azurerm/internal/services/dns/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package dns

import "github.com/Azure/azure-sdk-for-go/services/preview/dns/mgmt/2018-03-01-preview/dns"

type Client struct {
RecordSetsClient dns.RecordSetsClient
ZonesClient dns.ZonesClient
}
9 changes: 9 additions & 0 deletions azurerm/internal/services/hdinsight/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package hdinsight

import "github.com/Azure/azure-sdk-for-go/services/preview/hdinsight/mgmt/2018-06-01-preview/hdinsight"

type Client struct {
ApplicationsClient hdinsight.ApplicationsClient
ClustersClient hdinsight.ClustersClient
ConfigurationsClient hdinsight.ConfigurationsClient
}
12 changes: 12 additions & 0 deletions azurerm/internal/services/loganalytics/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package loganalytics

import (
"github.com/Azure/azure-sdk-for-go/services/preview/operationalinsights/mgmt/2015-11-01-preview/operationalinsights"
"github.com/Azure/azure-sdk-for-go/services/preview/operationsmanagement/mgmt/2015-11-01-preview/operationsmanagement"
)

type Client struct {
LinkedServicesClient operationalinsights.LinkedServicesClient
SolutionsClient operationsmanagement.SolutionsClient
WorkspacesClient operationalinsights.WorkspacesClient
}
7 changes: 7 additions & 0 deletions azurerm/internal/services/media/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package media

import "github.com/Azure/azure-sdk-for-go/services/mediaservices/mgmt/2018-07-01/media"

type Client struct {
ServicesClient media.MediaservicesClient
}
9 changes: 9 additions & 0 deletions azurerm/internal/services/redis/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package redis

import "github.com/Azure/azure-sdk-for-go/services/redis/mgmt/2018-03-01/redis"

type Client struct {
Client redis.Client
FirewallRulesClient redis.FirewallRulesClient
PatchSchedulesClient redis.PatchSchedulesClient
}
Loading

0 comments on commit d66f52a

Please sign in to comment.