Skip to content

Commit

Permalink
Merge pull request hashicorp#24007 from hashicorp/refactor/porting-te…
Browse files Browse the repository at this point in the history
…mplatespec-to-go-azure-sdk

refactor: `templatespecversions` now uses `hashicorp/go-azure-sdk` / updates to API Version `2022-02-01`
  • Loading branch information
tombuildsstuff authored Nov 23, 2023
2 parents 48adbb1 + 8a54ad0 commit e92ed23
Show file tree
Hide file tree
Showing 30 changed files with 1,217 additions and 2,270 deletions.
15 changes: 9 additions & 6 deletions internal/services/resource/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package client
import (
"fmt"

"github.com/Azure/azure-sdk-for-go/services/preview/resources/mgmt/2019-06-01-preview/templatespecs" // nolint: staticcheck
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck
"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources" // nolint: staticcheck
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/managementlocks"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/privatelinkassociation"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-05-01/resourcemanagementprivatelink"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2021-07-01/features"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2022-02-01/templatespecversions"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2022-09-01/providers"
"github.com/hashicorp/terraform-provider-azurerm/internal/common"
)
Expand All @@ -28,7 +28,7 @@ type Client struct {
ResourceProvidersClient *providers.ProvidersClient
ResourcesClient *resources.Client
TagsClient *resources.TagsClient
TemplateSpecsVersionsClient *templatespecs.VersionsClient
TemplateSpecsVersionsClient *templatespecversions.TemplateSpecVersionsClient

options *common.ClientOptions
}
Expand Down Expand Up @@ -79,8 +79,11 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
resourcesClient := resources.NewClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&resourcesClient.Client, o.ResourceManagerAuthorizer)

templatespecsVersionsClient := templatespecs.NewVersionsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&templatespecsVersionsClient.Client, o.ResourceManagerAuthorizer)
templateSpecsVersionsClient, err := templatespecversions.NewTemplateSpecVersionsClientWithBaseURI(o.Environment.ResourceManager)
if err != nil {
return nil, fmt.Errorf("building TemplateSpecVersions client: %+v", err)
}
o.Configure(templateSpecsVersionsClient.Client, o.Authorizers.ResourceManager)

tagsClient := resources.NewTagsClientWithBaseURI(o.ResourceManagerEndpoint, o.SubscriptionId)
o.ConfigureClient(&tagsClient.Client, o.ResourceManagerAuthorizer)
Expand All @@ -96,7 +99,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) {
ResourceProvidersClient: resourceProvidersClient,
ResourcesClient: &resourcesClient,
TagsClient: &tagsClient,
TemplateSpecsVersionsClient: &templatespecsVersionsClient,
TemplateSpecsVersionsClient: templateSpecsVersionsClient,

options: o,
}, nil
Expand Down
36 changes: 18 additions & 18 deletions internal/services/resource/template_spec_version_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ 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/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/resources/2022-02-01/templatespecversions"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

func dataSourceTemplateSpecVersion() *pluginsdk.Resource {
Expand Down Expand Up @@ -46,7 +46,7 @@ func dataSourceTemplateSpecVersion() *pluginsdk.Resource {
Computed: true,
},

"tags": tags.SchemaDataSource(),
"tags": commonschema.TagsDataSource(),
},
}
}
Expand All @@ -57,28 +57,28 @@ func dataSourceTemplateSpecVersionRead(d *pluginsdk.ResourceData, meta interface
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := parse.NewTemplateSpecVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string), d.Get("version").(string))

resp, err := client.Get(ctx, id.ResourceGroup, id.TemplateSpecName, id.VersionName)
id := templatespecversions.NewTemplateSpecVersionID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string), d.Get("version").(string))
resp, err := client.Get(ctx, id)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Templatespec %q, with version name %q (resource group %q) was not found: %+v", id.TemplateSpecName, id.VersionName, id.ResourceGroup, err)
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("reading Templatespec %q, with version name %q (resource group %q): %+v", id.TemplateSpecName, id.VersionName, id.ResourceGroup, err)
return fmt.Errorf("retrieving %s: %+v", id, err)
}

templateBody := "{}"
if props := resp.VersionProperties; props != nil && props.Template != nil {
templateBodyRaw, err := flattenTemplateDeploymentBody(props.Template)
d.SetId(id.ID())

if model := resp.Model; model != nil {
templateBodyRaw, err := flattenTemplateDeploymentBody(model.Properties.MainTemplate)
if err != nil {
return err
}
d.Set("template_body", templateBodyRaw)

templateBody = *templateBodyRaw
if err := tags.FlattenAndSet(d, model.Tags); err != nil {
return err
}
}
d.Set("template_body", templateBody)

d.SetId(id.ID())

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

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit e92ed23

Please sign in to comment.