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

[AWS SDK for Go Migration] Meta Data Sources (Region) Service #39389

Merged
merged 31 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
6019d42
[AWS SDK for Go Migration] Meta Data Sources (Region) Service
hskiba Sep 19, 2024
97c6521
restore prior formatting, convert unit tests to acceptance tests
hskiba Sep 19, 2024
7c08b2a
more formatting
hskiba Sep 19, 2024
933af5c
fix check for multiple region matching
hskiba Sep 19, 2024
54a4a42
update test names
hskiba Sep 19, 2024
ee34887
add partition checks to service principal data source tests
hskiba Sep 19, 2024
07827d3
add changelog entry
hskiba Sep 19, 2024
877bcc9
Revert "add partition checks to service principal data source tests"
ewbankkit Sep 20, 2024
aca0cd3
Revert "update test names"
ewbankkit Sep 20, 2024
cd55c11
Revert "fix check for multiple region matching"
ewbankkit Sep 20, 2024
cfc57f9
Revert "more formatting"
ewbankkit Sep 20, 2024
90cc1fa
Revert "restore prior formatting, convert unit tests to acceptance te…
ewbankkit Sep 20, 2024
b6e1768
Revert "[AWS SDK for Go Migration] Meta Data Sources (Region) Service"
ewbankkit Sep 20, 2024
0a0c5da
Merge branch 'main' into HEAD
ewbankkit Sep 20, 2024
226da0c
Tweak CHANGELOG entry.
ewbankkit Sep 20, 2024
d3e8e4b
d/aws_arn: Tidy up.
ewbankkit Sep 20, 2024
c615372
d/aws_billing_service_account: Tidy up.
ewbankkit Sep 20, 2024
0f5222a
d/aws_default_tags: Tidy up.
ewbankkit Sep 20, 2024
08e29a6
d/aws_ip_ranges: Tidy up.
ewbankkit Sep 20, 2024
a04ae1a
d/aws_partition: Tidy up.
ewbankkit Sep 20, 2024
2a60e94
d/aws_regions: Tidy up.
ewbankkit Sep 20, 2024
6ba5d5b
d/aws_region: Tidy up and use 'endpoints' from 'aws-sdk-go-base'.
ewbankkit Sep 20, 2024
628b6e7
d/aws_service_principal: Tidy up.
ewbankkit Sep 20, 2024
296f89e
d/aws_service: Start tidy up.
ewbankkit Sep 20, 2024
62bc6b0
Add 'TestAccMetaServiceDataSource_irregularServiceID'.
ewbankkit Sep 20, 2024
57522f6
Add 'TestAccMetaServiceDataSource_irregularServiceIDUnsupported'.
ewbankkit Sep 20, 2024
762f098
d/aws_region: Use EndpointsV2.
ewbankkit Sep 20, 2024
99aa28a
Acceptance test output:
ewbankkit Sep 20, 2024
a5133fe
d/aws_service: Revert to AWS SDK for Go v1 endpoints package -- no mi…
ewbankkit Sep 20, 2024
c6152c0
d/aws_service_principal: Correct acceptance test function names.
ewbankkit Sep 20, 2024
3ea85cc
Fix typo.
ewbankkit Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading