Skip to content

Commit

Permalink
containerinstance: refactoring to use hashicorp/go-azure-sdk (#17499)
Browse files Browse the repository at this point in the history
  • Loading branch information
magodo authored Jul 5, 2022
1 parent 9ad7bda commit 7fe1b73
Show file tree
Hide file tree
Showing 88 changed files with 3,440 additions and 4,337 deletions.
11 changes: 6 additions & 5 deletions internal/services/containers/client/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package client

import (
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2021-03-01/containerinstance"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-03-01/containerinstance"

legacy "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-08-01/containerservice"
legacyacr "github.com/Azure/azure-sdk-for-go/services/preview/containerregistry/mgmt/2019-06-01-preview/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/preview/containerregistry/mgmt/2021-08-01-preview/containerregistry"
Expand All @@ -13,7 +14,7 @@ import (
type Client struct {
AgentPoolsClient *containerservice.AgentPoolsClient
ContainerRegistryAgentPoolsClient *containerregistry.AgentPoolsClient
GroupsClient *containerinstance.ContainerGroupsClient
ContainerInstanceClient *containerinstance.ContainerInstanceClient
KubernetesClustersClient *containerservice.ManagedClustersClient
MaintenanceConfigurationsClient *containerservice.MaintenanceConfigurationsClient
RegistriesClient *containerregistry.RegistriesClient
Expand Down Expand Up @@ -50,8 +51,8 @@ func NewClient(o *common.ClientOptions) *Client {
tasksClient := legacyacr.NewTasksClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&tasksClient.Client, o.ResourceManagerAuthorizer)

groupsClient := containerinstance.NewContainerGroupsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&groupsClient.Client, o.ResourceManagerAuthorizer)
containerInstanceClient := containerinstance.NewContainerInstanceClientWithBaseURI(o.ResourceManagerEndpoint)
o.ConfigureClient(&containerInstanceClient.Client, o.ResourceManagerAuthorizer)

// AKS
kubernetesClustersClient := containerservice.NewManagedClustersClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
Expand All @@ -73,7 +74,7 @@ func NewClient(o *common.ClientOptions) *Client {
AgentPoolsClient: &agentPoolsClient,
ContainerRegistryAgentPoolsClient: &registryAgentPoolsClient,
KubernetesClustersClient: &kubernetesClustersClient,
GroupsClient: &groupsClient,
ContainerInstanceClient: &containerInstanceClient,
MaintenanceConfigurationsClient: &maintenanceConfigurationsClient,
RegistriesClient: &registriesClient,
WebhooksClient: &webhooksClient,
Expand Down
34 changes: 19 additions & 15 deletions internal/services/containers/container_group_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerinstance/2021-03-01/containerinstance"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/containers/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceContainerGroup() *pluginsdk.Resource {
Expand Down Expand Up @@ -44,39 +44,43 @@ func dataSourceContainerGroup() *pluginsdk.Resource {
Computed: true,
},

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}

func dataSourceContainerGroupRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).Containers.GroupsClient
client := meta.(*clients.Client).Containers.ContainerInstanceClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewContainerGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
id := containerinstance.NewContainerGroupID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

resp, err := client.Get(ctx, id.ResourceGroup, id.Name)
resp, err := client.ContainerGroupsGet(ctx, id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("making Read request on %s: %+v", id, err)
}

d.SetId(id.ID())
d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))
d.Set("name", id.ContainerGroupName)
d.Set("resource_group_name", id.ResourceGroupName)

if props := resp.ContainerGroupProperties; props != nil {
if address := props.IPAddress; address != nil {
d.Set("ip_address", address.IP)
if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))
if err := tags.FlattenAndSet(d, model.Tags); err != nil {
return err
}
props := model.Properties
if address := props.IpAddress; address != nil {
d.Set("ip_address", address.Ip)
d.Set("fqdn", address.Fqdn)
}
}

return tags.FlattenAndSet(d, resp.Tags)
return nil
}
Loading

0 comments on commit 7fe1b73

Please sign in to comment.