Skip to content

Commit

Permalink
Merge pull request #39389 from hskiba/td-migrate_region_data_source_s…
Browse files Browse the repository at this point in the history
…dkv2

[AWS SDK for Go Migration] Meta Data Sources (Region) Service
  • Loading branch information
ewbankkit authored Sep 20, 2024
2 parents 9ca54a6 + 3ea85cc commit 77cd6ed
Show file tree
Hide file tree
Showing 15 changed files with 296 additions and 261 deletions.
3 changes: 3 additions & 0 deletions .changelog/39389.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
data-source/aws_region: Fix lookups for the `ap-southeast-5` Region
```
42 changes: 17 additions & 25 deletions internal/service/meta/arn_data_source.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

// Code generated by tools/tfsdk2fw/main.go. Manual editing is required.

package meta

import (
Expand All @@ -12,30 +10,28 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource
func newDataSourceARN(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &dataSourceARN{}
// @FrameworkDataSource(name="ARN")
func newARNDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &arnDataSource{}

return d, nil
}

type dataSourceARN struct {
type arnDataSource struct {
framework.DataSourceWithConfigure
}

// Metadata should return the full name of the data source, such as
// examplecloud_thing.
func (d *dataSourceARN) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (*arnDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
response.TypeName = "aws_arn"
}

// Schema returns the schema for this data source.
func (d *dataSourceARN) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
func (d *arnDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"account": schema.StringAttribute{
Computed: true,
Expand Down Expand Up @@ -64,30 +60,26 @@ func (d *dataSourceARN) Schema(ctx context.Context, req datasource.SchemaRequest
}
}

// Read is called when the provider must read data source values in order to update state.
// Config values should be read from the ReadRequest and new state values set on the ReadResponse.
func (d *dataSourceARN) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data dataSourceARNData

func (d *arnDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data arnDataSourceModel
response.Diagnostics.Append(request.Config.Get(ctx, &data)...)

if response.Diagnostics.HasError() {
return
}

arn := data.ARN.ValueARN()

data.Account = types.StringValue(arn.AccountID)
data.ID = types.StringValue(arn.String())
data.Partition = types.StringValue(arn.Partition)
data.Region = types.StringValue(arn.Region)
data.Resource = types.StringValue(arn.Resource)
data.Service = types.StringValue(arn.Service)
data.Account = fwflex.StringValueToFrameworkLegacy(ctx, arn.AccountID)
data.ID = fwflex.StringValueToFrameworkLegacy(ctx, arn.String())
data.Partition = fwflex.StringValueToFrameworkLegacy(ctx, arn.Partition)
data.Region = fwflex.StringValueToFrameworkLegacy(ctx, arn.Region)
data.Resource = fwflex.StringValueToFrameworkLegacy(ctx, arn.Resource)
data.Service = fwflex.StringValueToFrameworkLegacy(ctx, arn.Service)

response.Diagnostics.Append(response.State.Set(ctx, &data)...)
}

type dataSourceARNData struct {
type arnDataSourceModel struct {
Account types.String `tfsdk:"account"`
ARN fwtypes.ARN `tfsdk:"arn"`
ID types.String `tfsdk:"id"`
Expand Down
33 changes: 13 additions & 20 deletions internal/service/meta/billing_service_account_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource
func newDataSourceBillingServiceAccount(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &dataSourceBillingServiceAccount{}
// @FrameworkDataSource(name="Billing Service Account")
func newBillingServiceAccountDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &billingServiceAccountDataSource{}

return d, nil
}

type dataSourceBillingServiceAccount struct {
type billingServiceAccountDataSource struct {
framework.DataSourceWithConfigure
}

// Metadata should return the full name of the data source, such as
// examplecloud_thing.
func (d *dataSourceBillingServiceAccount) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (*billingServiceAccountDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
response.TypeName = "aws_billing_service_account"
}

// Schema returns the schema for this data source.
func (d *dataSourceBillingServiceAccount) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
func (d *billingServiceAccountDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrARN: schema.StringAttribute{
Computed: true,
Expand All @@ -46,13 +44,9 @@ func (d *dataSourceBillingServiceAccount) Schema(ctx context.Context, req dataso
}
}

// Read is called when the provider must read data source values in order to update state.
// Config values should be read from the ReadRequest and new state values set on the ReadResponse.
func (d *dataSourceBillingServiceAccount) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data dataSourceBillingServiceAccountData

func (d *billingServiceAccountDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data billingServiceAccountDataSourceModel
response.Diagnostics.Append(request.Config.Get(ctx, &data)...)

if response.Diagnostics.HasError() {
return
}
Expand All @@ -66,14 +60,13 @@ func (d *dataSourceBillingServiceAccount) Read(ctx context.Context, request data
AccountID: billingAccountID,
Resource: "root",
}

data.ARN = types.StringValue(arn.String())
data.ID = types.StringValue(billingAccountID)
data.ARN = fwflex.StringValueToFrameworkLegacy(ctx, arn.String())
data.ID = fwflex.StringValueToFrameworkLegacy(ctx, billingAccountID)

response.Diagnostics.Append(response.State.Set(ctx, &data)...)
}

type dataSourceBillingServiceAccountData struct {
type billingServiceAccountDataSourceModel struct {
ARN types.String `tfsdk:"arn"`
ID types.String `tfsdk:"id"`
}
32 changes: 12 additions & 20 deletions internal/service/meta/default_tags_data_source.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

// Code generated by tools/tfsdk2fw/main.go. Manual editing is required.

package meta

import (
Expand All @@ -12,30 +10,28 @@ import (
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-provider-aws/internal/framework"
fwflex "github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @FrameworkDataSource
func newDataSourceDefaultTags(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &dataSourceDefaultTags{}
// @FrameworkDataSource(name="Default Tags")
func newDefaultTagsDataSource(context.Context) (datasource.DataSourceWithConfigure, error) {
d := &defaultTagsDataSource{}

return d, nil
}

type dataSourceDefaultTags struct {
type defaultTagsDataSource struct {
framework.DataSourceWithConfigure
}

// Metadata should return the full name of the data source, such as
// examplecloud_thing.
func (d *dataSourceDefaultTags) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (*defaultTagsDataSource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
response.TypeName = "aws_default_tags"
}

// Schema returns the schema for this data source.
func (d *dataSourceDefaultTags) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
func (d *defaultTagsDataSource) Schema(ctx context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrID: schema.StringAttribute{
Optional: true,
Expand All @@ -46,13 +42,9 @@ func (d *dataSourceDefaultTags) Schema(ctx context.Context, req datasource.Schem
}
}

// Read is called when the provider must read data source values in order to update state.
// Config values should be read from the ReadRequest and new state values set on the ReadResponse.
func (d *dataSourceDefaultTags) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data dataSourceDefaultTagsData

func (d *defaultTagsDataSource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var data defaultTagsDataSourceModel
response.Diagnostics.Append(request.Config.Get(ctx, &data)...)

if response.Diagnostics.HasError() {
return
}
Expand All @@ -61,13 +53,13 @@ func (d *dataSourceDefaultTags) Read(ctx context.Context, request datasource.Rea
ignoreTagsConfig := d.Meta().IgnoreTagsConfig
tags := defaultTagsConfig.GetTags()

data.ID = types.StringValue(d.Meta().Partition)
data.ID = fwflex.StringValueToFrameworkLegacy(ctx, d.Meta().Partition)
data.Tags = tftags.FlattenStringValueMap(ctx, tags.IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map())

response.Diagnostics.Append(response.State.Set(ctx, &data)...)
}

type dataSourceDefaultTagsData struct {
type defaultTagsDataSourceModel struct {
ID types.String `tfsdk:"id"`
Tags tftags.Map `tfsdk:"tags"`
}
10 changes: 10 additions & 0 deletions internal/service/meta/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package meta

// Exports for use in tests only.
var (
FindRegionByEC2Endpoint = findRegionByEC2Endpoint
FindRegionByName = findRegionByName
)
Loading

0 comments on commit 77cd6ed

Please sign in to comment.