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

refactoring Dashboard, Media and ServiceBus to use hashicorp/go-azure-sdk as a base layer #20810

Merged
merged 7 commits into from
Mar 9, 2023
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.1.2
github.com/hashicorp/go-azure-helpers v0.55.0
github.com/hashicorp/go-azure-sdk v0.20230306.1165107
github.com/hashicorp/go-azure-sdk v0.20230309.1123256
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg=
github.com/hashicorp/go-azure-helpers v0.55.0 h1:2A2KWPiaDC5kQWr6tYHTD/P1k9bO0HvflEb/Nc1yLeU=
github.com/hashicorp/go-azure-helpers v0.55.0/go.mod h1:RQugkG8wEcNIjYmcBLHpuEI/u2mTJwO4r37rR/OKRpo=
github.com/hashicorp/go-azure-sdk v0.20230306.1165107 h1:DUGdCQR1MMBqTTNa12y4btFRV78bAI6skjGrQ4MbIVA=
github.com/hashicorp/go-azure-sdk v0.20230306.1165107/go.mod h1:L9JXVUcnL0GjMizCnngYUlMp1lLhDBNgSTvn6Of/5O4=
github.com/hashicorp/go-azure-sdk v0.20230309.1123256 h1:/SxgrFGJEp/jXg4/tfR+gnC+cyfKxJucjM4QTMG3dS0=
github.com/hashicorp/go-azure-sdk v0.20230309.1123256/go.mod h1:L9JXVUcnL0GjMizCnngYUlMp1lLhDBNgSTvn6Of/5O4=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg=
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
Expand Down
12 changes: 9 additions & 3 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Cosmos = cosmosdb.NewClient(o)
client.CostManagement = costmanagement.NewClient(o)
client.CustomProviders = customproviders.NewClient(o)
client.Dashboard = dashboard.NewClient(o)
if client.Dashboard, err = dashboard.NewClient(o); err != nil {
return fmt.Errorf("building clients for Dashboard: %+v", err)
}
client.DatabaseMigration = datamigration.NewClient(o)
client.DataBricks = databricks.NewClient(o)
client.DataboxEdge = databoxedge.NewClient(o)
Expand Down Expand Up @@ -340,7 +342,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
return fmt.Errorf("building clients for Maps: %+v", err)
}
client.MariaDB = mariadb.NewClient(o)
client.Media = media.NewClient(o)
if client.Media, err = media.NewClient(o); err != nil {
return fmt.Errorf("building clients for Media: %+v", err)
}
client.MixedReality = mixedreality.NewClient(o)
client.Monitor = monitor.NewClient(o)
client.MobileNetwork = mobilenetwork.NewClient(o)
Expand All @@ -366,7 +370,9 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error
client.Search = search.NewClient(o)
client.SecurityCenter = securityCenter.NewClient(o)
client.Sentinel = sentinel.NewClient(o)
client.ServiceBus = serviceBus.NewClient(o)
if client.ServiceBus, err = serviceBus.NewClient(o); err != nil {
return fmt.Errorf("building clients for ServiceBus: %+v", err)
}
client.ServiceConnector = serviceConnector.NewClient(o)
client.ServiceFabric = serviceFabric.NewClient(o)
client.ServiceFabricManaged = serviceFabricManaged.NewClient(o)
Expand Down
15 changes: 10 additions & 5 deletions internal/services/dashboard/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/dashboard/2022-08-01/grafanaresource"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand All @@ -9,11 +11,14 @@ type Client struct {
GrafanaResourceClient *grafanaresource.GrafanaResourceClient
}

func NewClient(o *common.ClientOptions) *Client {
grafanaResourceClient := grafanaresource.NewGrafanaResourceClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&grafanaResourceClient.Client, o.ResourceManagerAuthorizer)
func NewClient(o *common.ClientOptions) (*Client, error) {
grafanaResourceClient, err := grafanaresource.NewGrafanaResourceClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building GrafanaResource client: %+v", err)
}
o.Configure(grafanaResourceClient.Client, o.Authorizers.ResourceManager)

return &Client{
GrafanaResourceClient: &grafanaResourceClient,
}
GrafanaResourceClient: grafanaResourceClient,
}, nil
}
26 changes: 17 additions & 9 deletions internal/services/media/client/client.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package client

import (
"github.com/Azure/go-autorest/autorest"
"fmt"

mediaV20211101 "github.com/hashicorp/go-azure-sdk/resource-manager/media/2021-11-01"
mediaV20220801 "github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01"
"github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)

Expand All @@ -12,17 +14,23 @@ type Client struct {
V20220801Client *mediaV20220801.Client
}

func NewClient(o *common.ClientOptions) *Client {
V20211101Client := mediaV20211101.NewClientWithBaseURI(o.ResourceManagerEndpoint, func(c *autorest.Client) {
c.Authorizer = o.ResourceManagerAuthorizer
func NewClient(o *common.ClientOptions) (*Client, error) {
v20211101Client, err := mediaV20211101.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)
})
if err != nil {
return nil, fmt.Errorf("building 2021-11-01 client: %+v", err)
}

V20220801Client := mediaV20220801.NewClientWithBaseURI(o.ResourceManagerEndpoint, func(c *autorest.Client) {
c.Authorizer = o.ResourceManagerAuthorizer
v20220801Client, err := mediaV20220801.NewClientWithBaseURI(o.Environment.ResourceManager, func(c *resourcemanager.Client) {
o.Configure(c, o.Authorizers.ResourceManager)
})
if err != nil {
return nil, fmt.Errorf("building 2022-08-01 client: %+v", err)
}

return &Client{
V20211101Client: &V20211101Client,
V20220801Client: &V20220801Client,
}
V20211101Client: v20211101Client,
V20220801Client: v20220801Client,
}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"regexp"
"time"

"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-sdk/resource-manager/media/2022-08-01/contentkeypolicies"
Expand Down Expand Up @@ -1118,7 +1117,7 @@ func expandPlayReadyLicenses(input []interface{}) (*[]contentkeypolicies.Content
}

if v := license["begin_date"]; v != nil && v != "" {
beginDate, err := date.ParseTime(time.RFC3339, v.(string))
beginDate, err := time.Parse(time.RFC3339, v.(string))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1146,7 +1145,7 @@ func expandPlayReadyLicenses(input []interface{}) (*[]contentkeypolicies.Content
}

if v := license["expiration_date"]; v != nil && v != "" {
expirationDate, err := date.ParseTime(time.RFC3339, v.(string))
expirationDate, err := time.Parse(time.RFC3339, v.(string))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"time"

"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -537,7 +536,7 @@ func expandAccessControl(d *pluginsdk.ResourceData) (*streamingendpoints.Streami
Identifier: utils.String(identifier),
}
if expirationRaw != "" {
expiration, err := date.ParseTime(time.RFC3339, expirationRaw)
expiration, err := time.Parse(time.RFC3339, expirationRaw)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions internal/services/media/media_streaming_locator_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"regexp"
"time"

"github.com/Azure/go-autorest/autorest/date"
"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -220,7 +219,7 @@ func resourceMediaStreamingLocatorCreate(d *pluginsdk.ResourceData, meta interfa

if endTimeRaw, ok := d.GetOk("end_time"); ok {
if endTimeRaw.(string) != "" {
endTime, err := date.ParseTime(time.RFC3339, endTimeRaw.(string))
endTime, err := time.Parse(time.RFC3339, endTimeRaw.(string))
if err != nil {
return err
}
Expand All @@ -234,7 +233,7 @@ func resourceMediaStreamingLocatorCreate(d *pluginsdk.ResourceData, meta interfa

if startTimeRaw, ok := d.GetOk("start_time"); ok {
if startTimeRaw.(string) != "" {
startTime, err := date.ParseTime(time.RFC3339, startTimeRaw.(string))
startTime, err := time.Parse(time.RFC3339, startTimeRaw.(string))
if err != nil {
return err
}
Expand Down
18 changes: 11 additions & 7 deletions internal/services/portal/portal_dashboard_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonids"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
Expand Down Expand Up @@ -60,13 +62,13 @@ func dataSourcePortalDashboardRead(d *pluginsdk.ResourceData, meta interface{})
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

displayName, displayNameOk := d.GetOk("display_name")
displayName := d.Get("display_name")

id := dashboard.NewDashboardID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

props := dashboard.Dashboard{}

if !displayNameOk {
if displayName == "" {
resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
Expand All @@ -81,9 +83,10 @@ func dataSourcePortalDashboardRead(d *pluginsdk.ResourceData, meta interface{})
} else {
dashboards := make([]dashboard.Dashboard, 0)

iterator, err := client.ListByResourceGroupComplete(ctx, commonids.NewResourceGroupID(id.SubscriptionId, id.ResourceGroupName))
resourceGroupId := commonids.NewResourceGroupID(id.SubscriptionId, id.ResourceGroupName)
iterator, err := client.ListByResourceGroupComplete(ctx, resourceGroupId)
if err != nil {
return fmt.Errorf("getting list of Portal Dashboards for %s: %+v", id, err)
return fmt.Errorf("getting list of Portal Dashboards within %s: %+v", resourceGroupId, err)
}

log.Printf("portal_debug iterator: %+v", iterator.Items)
Expand All @@ -98,15 +101,16 @@ func dataSourcePortalDashboardRead(d *pluginsdk.ResourceData, meta interface{})
}
}

if 1 > len(dashboards) {
return fmt.Errorf("no Portal Dashboards were found for %s", id)
if len(dashboards) == 0 {
return fmt.Errorf("no Portal Dashboards were found within %s", resourceGroupId)
}

if len(dashboards) > 1 {
return fmt.Errorf("multiple Portal Dashboards were found for %s", id)
return fmt.Errorf("multiple (%d) Portal Dashboards were found within %s", len(dashboards), resourceGroupId)
}

props = dashboards[0]
id.DashboardName = pointer.From(props.Name)
}

d.SetId(id.ID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ data "azurerm_portal_dashboard" "test" {
}

func (PortalDashboardDataSource) displayName(data acceptance.TestData) string {
resourceName := "azurerm_portal_dashboard"
return fmt.Sprintf(`

%s
Expand All @@ -88,7 +87,7 @@ data "azurerm_portal_dashboard" "test" {
display_name = "Test Display Name"
resource_group_name = azurerm_resource_group.test.name

depends_on = ["%s.test"]
depends_on = ["azurerm_portal_dashboard.test"]
}
`, PortalDashboardResource{}.hiddenTitle(data), resourceName)
`, PortalDashboardResource{}.hiddenTitle(data))
}
87 changes: 58 additions & 29 deletions internal/services/servicebus/client/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package client

import (
"fmt"

"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/disasterrecoveryconfigs"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/namespacesauthorizationrule"
"github.com/hashicorp/go-azure-sdk/resource-manager/servicebus/2021-06-01-preview/queues"
Expand All @@ -25,43 +27,70 @@ type Client struct {
TopicsClient *topics.TopicsClient
}

func NewClient(o *common.ClientOptions) *Client {
DisasterRecoveryConfigsClient := disasterrecoveryconfigs.NewDisasterRecoveryConfigsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&DisasterRecoveryConfigsClient.Client, o.ResourceManagerAuthorizer)
func NewClient(o *common.ClientOptions) (*Client, error) {
disasterRecoveryConfigsClient, err := disasterrecoveryconfigs.NewDisasterRecoveryConfigsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building DisasterRecoveryConfigs client: %+v", err)
}
o.Configure(disasterRecoveryConfigsClient.Client, o.Authorizers.ResourceManager)

NamespacesAuthClient := namespacesauthorizationrule.NewNamespacesAuthorizationRuleClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&NamespacesAuthClient.Client, o.ResourceManagerAuthorizer)
namespacesAuthClient, err := namespacesauthorizationrule.NewNamespacesAuthorizationRuleClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building NamespacesAuthorizationRule client: %+v", err)
}
o.Configure(namespacesAuthClient.Client, o.Authorizers.ResourceManager)

NamespacesClient := namespaces.NewNamespacesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&NamespacesClient.Client, o.ResourceManagerAuthorizer)
namespacesClient, err := namespaces.NewNamespacesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Namespaces client: %+v", err)
}
o.Configure(namespacesClient.Client, o.Authorizers.ResourceManager)

QueuesAuthClient := queuesauthorizationrule.NewQueuesAuthorizationRuleClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&QueuesAuthClient.Client, o.ResourceManagerAuthorizer)
queuesAuthClient, err := queuesauthorizationrule.NewQueuesAuthorizationRuleClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building QueuesAuthorizationRule client: %+v", err)
}
o.Configure(queuesAuthClient.Client, o.Authorizers.ResourceManager)

QueuesClient := queues.NewQueuesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&QueuesClient.Client, o.ResourceManagerAuthorizer)
queuesClient, err := queues.NewQueuesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Queues client: %+v", err)
}
o.Configure(queuesClient.Client, o.Authorizers.ResourceManager)

SubscriptionsClient := subscriptions.NewSubscriptionsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&SubscriptionsClient.Client, o.ResourceManagerAuthorizer)
subscriptionsClient, err := subscriptions.NewSubscriptionsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Subscriptions client: %+v", err)
}
o.Configure(subscriptionsClient.Client, o.Authorizers.ResourceManager)

SubscriptionRulesClient := rules.NewRulesClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&SubscriptionRulesClient.Client, o.ResourceManagerAuthorizer)
subscriptionRulesClient, err := rules.NewRulesClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Rules client: %+v", err)
}
o.Configure(subscriptionRulesClient.Client, o.Authorizers.ResourceManager)

TopicsAuthClient := topicsauthorizationrule.NewTopicsAuthorizationRuleClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&TopicsAuthClient.Client, o.ResourceManagerAuthorizer)
topicsAuthClient, err := topicsauthorizationrule.NewTopicsAuthorizationRuleClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building TopicsAuthorizationRule client: %+v", err)
}
o.Configure(topicsAuthClient.Client, o.Authorizers.ResourceManager)

TopicsClient := topics.NewTopicsClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&TopicsClient.Client, o.ResourceManagerAuthorizer)
topicsClient, err := topics.NewTopicsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building Topics client: %+v", err)
}
o.Configure(topicsClient.Client, o.Authorizers.ResourceManager)

return &Client{
DisasterRecoveryConfigsClient: &DisasterRecoveryConfigsClient,
NamespacesAuthClient: &NamespacesAuthClient,
NamespacesClient: &NamespacesClient,
QueuesAuthClient: &QueuesAuthClient,
QueuesClient: &QueuesClient,
SubscriptionsClient: &SubscriptionsClient,
SubscriptionRulesClient: &SubscriptionRulesClient,
TopicsAuthClient: &TopicsAuthClient,
TopicsClient: &TopicsClient,
}
DisasterRecoveryConfigsClient: disasterRecoveryConfigsClient,
NamespacesAuthClient: namespacesAuthClient,
NamespacesClient: namespacesClient,
QueuesAuthClient: queuesAuthClient,
QueuesClient: queuesClient,
SubscriptionsClient: subscriptionsClient,
SubscriptionRulesClient: subscriptionRulesClient,
TopicsAuthClient: topicsAuthClient,
TopicsClient: topicsClient,
}, nil
}
Loading