Skip to content

Commit

Permalink
fix: resolve issues with naming scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Ismayil Mirzali <[email protected]>
  • Loading branch information
Volatus committed Jan 13, 2025
1 parent c607684 commit 452a2d1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
30 changes: 15 additions & 15 deletions internal/service/ec2/aws_vpc_ipam_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ import (
)

// @FrameworkDataSource("aws_vpc_ipam", name="AWS IPAM")
func newDataSourceAwsVpcIpam(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceAwsVpcIpam{}, nil
func newDataSourceVPCIPAM(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceVPCIPAM{}, nil
}

const (
DSNameAwsVpcIpam = "AWS IPAM Data Source"
DSNameVPCIPAM = "AWS IPAM Data Source"
)

type dataSourceAwsVpcIpam struct {
type dataSourceVPCIPAM struct {
framework.DataSourceWithConfigure
}

func (d *dataSourceAwsVpcIpam) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (d *dataSourceVPCIPAM) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
resp.TypeName = "aws_vpc_ipam"
}

func (d *dataSourceAwsVpcIpam) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceVPCIPAM) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
names.AttrARN: framework.ARNAttributeComputedOnly(),
Expand All @@ -62,11 +62,11 @@ func (d *dataSourceAwsVpcIpam) Schema(ctx context.Context, req datasource.Schema
"enable_private_gua": schema.BoolAttribute{
Computed: true,
},
"region": schema.StringAttribute{
names.AttrRegion: schema.StringAttribute{
Computed: true,
},
"operating_regions": framework.DataSourceComputedListOfObjectAttribute[ipamOperatingRegionModel](ctx),
"owner_id": schema.StringAttribute{
names.AttrOwnerID: schema.StringAttribute{
Computed: true,
},
"private_default_scope_id": schema.StringAttribute{
Expand All @@ -78,7 +78,7 @@ func (d *dataSourceAwsVpcIpam) Schema(ctx context.Context, req datasource.Schema
"resource_discovery_association_count": schema.Int32Attribute{
Computed: true,
},
"state": schema.StringAttribute{
names.AttrState: schema.StringAttribute{
Computed: true,
CustomType: fwtypes.StringEnumType[awstypes.IpamState](),
},
Expand All @@ -89,10 +89,10 @@ func (d *dataSourceAwsVpcIpam) Schema(ctx context.Context, req datasource.Schema
}
}

func (d *dataSourceAwsVpcIpam) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *dataSourceVPCIPAM) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
conn := d.Meta().EC2Client(ctx)

var data dataSourceAwsVpcIpamModel
var data dataSourceVPCIPAMModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
Expand All @@ -101,7 +101,7 @@ func (d *dataSourceAwsVpcIpam) Read(ctx context.Context, req datasource.ReadRequ
ipam, err := findIPAMByID(ctx, conn, data.IpamId.ValueString())
if err != nil {
resp.Diagnostics.AddError(
create.ProblemStandardMessage(names.EC2, create.ErrActionReading, DSNameAwsVpcIpam, data.IpamId.String(), err),
create.ProblemStandardMessage(names.EC2, create.ErrActionReading, DSNameVPCIPAM, data.IpamId.String(), err),
err.Error(),
)
return
Expand All @@ -120,7 +120,7 @@ func (d *dataSourceAwsVpcIpam) Read(ctx context.Context, req datasource.ReadRequ
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}

type dataSourceAwsVpcIpamSummaryModel struct {
type dataSourceVPCIPAMSummaryModel struct {
Description types.String `tfsdk:"description"`
DefaultResourceDiscoveryAssociationId types.String `tfsdk:"default_resource_discovery_association_id"`
DefaultResourceDiscoveryId types.String `tfsdk:"default_resource_discovery_id"`
Expand All @@ -139,8 +139,8 @@ type dataSourceAwsVpcIpamSummaryModel struct {
Tier fwtypes.StringEnum[awstypes.IpamTier] `tfsdk:"tier"`
}

type dataSourceAwsVpcIpamModel struct {
dataSourceAwsVpcIpamSummaryModel
type dataSourceVPCIPAMModel struct {
dataSourceVPCIPAMSummaryModel
Tags tftags.Map `tfsdk:"tags"`
}

Expand Down
8 changes: 4 additions & 4 deletions internal/service/ec2/aws_vpc_ipam_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccEC2AwsVpcIpamDataSourceBasic(t *testing.T) {
func TestAccEC2VPCIPAMDataSource_Basic(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_vpc_ipam.test"
dataSourceName := "data.aws_vpc_ipam.test"
Expand All @@ -26,7 +26,7 @@ func TestAccEC2AwsVpcIpamDataSourceBasic(t *testing.T) {
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccAwsVpcIpamDataSourceConfig_basic(),
Config: testAccVPCIPAMDataSourceConfig_basic(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "operating_regions.0.region_name", resourceName, "operating_regions.0.region_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.Test", resourceName, "tags.Test"),
Expand All @@ -36,7 +36,7 @@ func TestAccEC2AwsVpcIpamDataSourceBasic(t *testing.T) {
})
}

func testAccAwsVpcIpamDataSourceConfig_basic() string {
func testAccVPCIPAMDataSourceConfig_basic() string {
return `
data "aws_region" "current" {}
Expand All @@ -52,7 +52,7 @@ resource "aws_vpc_ipam" "test" {
}
data "aws_vpc_ipam" "test" {
id = aws_vpc_ipam.test.id
id = aws_vpc_ipam.test.id
}
`
}
32 changes: 16 additions & 16 deletions internal/service/ec2/aws_vpc_ipams_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,26 @@ import (
)

// @FrameworkDataSource("aws_vpc_ipams", name="AWS IPAM")
func newDataSourceAwsVpcIpams(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceAwsVpcIpams{}, nil
func newDataSourceVPCIPAMs(context.Context) (datasource.DataSourceWithConfigure, error) {
return &dataSourceVPCIPAMs{}, nil
}

const (
DSNameAwsVpcIpams = "AWS IPAMs Data Source"
DSNameVPCIPAMs = "AWS IPAMs Data Source"
)

type dataSourceAwsVpcIpams struct {
type dataSourceVPCIPAMs struct {
framework.DataSourceWithConfigure
}

func (d *dataSourceAwsVpcIpams) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
func (d *dataSourceVPCIPAMs) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { // nosemgrep:ci.meta-in-func-name
resp.TypeName = "aws_vpc_ipams"
}

func (d *dataSourceAwsVpcIpams) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
func (d *dataSourceVPCIPAMs) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schema.Schema{
Attributes: map[string]schema.Attribute{
"ipams": framework.DataSourceComputedListOfObjectAttribute[dataSourceAwsVpcIpamSummaryModel](ctx),
"ipams": framework.DataSourceComputedListOfObjectAttribute[dataSourceVPCIPAMSummaryModel](ctx),
"ipam_ids": schema.ListAttribute{
Optional: true,
ElementType: types.StringType,
Expand All @@ -63,7 +63,7 @@ func (d *dataSourceAwsVpcIpams) Schema(ctx context.Context, req datasource.Schem
}
}

func findAwsVpcIpams(ctx context.Context, conn *ec2.Client, input *ec2.DescribeIpamsInput) ([]awstypes.Ipam, error) {
func findVPCIPAMs(ctx context.Context, conn *ec2.Client, input *ec2.DescribeIpamsInput) ([]awstypes.Ipam, error) {
var output []awstypes.Ipam

pages := ec2.NewDescribeIpamsPaginator(conn, input)
Expand All @@ -77,10 +77,10 @@ func findAwsVpcIpams(ctx context.Context, conn *ec2.Client, input *ec2.DescribeI
return output, nil
}

func (d *dataSourceAwsVpcIpams) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
func (d *dataSourceVPCIPAMs) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
conn := d.Meta().EC2Client(ctx)

var data dataSourceAwsVpcIpamsModel
var data dataSourceVPCIPAMsModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
Expand All @@ -92,10 +92,10 @@ func (d *dataSourceAwsVpcIpams) Read(ctx context.Context, req datasource.ReadReq
return
}

output, err := findAwsVpcIpams(ctx, conn, &input)
output, err := findVPCIPAMs(ctx, conn, &input)
if err != nil {
resp.Diagnostics.AddError(
create.ProblemStandardMessage(names.EC2, create.ErrActionReading, DSNameAwsVpcIpams, "", err),
create.ProblemStandardMessage(names.EC2, create.ErrActionReading, DSNameVPCIPAMs, "", err),
err.Error(),
)
return
Expand All @@ -114,8 +114,8 @@ type filterModel struct {
Values fwtypes.SetOfString `tfsdk:"values"`
}

type dataSourceAwsVpcIpamsModel struct {
Ipams fwtypes.ListNestedObjectValueOf[dataSourceAwsVpcIpamSummaryModel] `tfsdk:"ipams"`
Filters fwtypes.ListNestedObjectValueOf[filterModel] `tfsdk:"filter"`
IpamIds types.List `tfsdk:"ipam_ids"`
type dataSourceVPCIPAMsModel struct {
Ipams fwtypes.ListNestedObjectValueOf[dataSourceVPCIPAMSummaryModel] `tfsdk:"ipams"`
Filters fwtypes.ListNestedObjectValueOf[filterModel] `tfsdk:"filter"`
IpamIds types.List `tfsdk:"ipam_ids"`
}
33 changes: 16 additions & 17 deletions internal/service/ec2/aws_vpc_ipams_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"

"github.com/hashicorp/terraform-provider-aws/names"
)

func TestAccEC2AwsVpcIpamsDataSourceTiered(t *testing.T) {
func TestAccEC2VPCIPAMsDataSource_Tiered(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_vpc_ipam.test"
dataSourceName := "data.aws_vpc_ipams.test"
Expand All @@ -30,7 +29,7 @@ func TestAccEC2AwsVpcIpamsDataSourceTiered(t *testing.T) {
CheckDestroy: acctest.CheckDestroyNoop,
Steps: []resource.TestStep{
{
Config: testAccAwsVpcIpamsDataSourceConfig_filterWithTiers(),
Config: testAccVPCIPAMsDataSourceConfig_filterWithTiers(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "ipams.0.operating_regions.0.region_name", resourceName, "operating_regions.0.region_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "ipams.0.tags.#", resourceName, "tags.#"),
Expand All @@ -42,26 +41,26 @@ func TestAccEC2AwsVpcIpamsDataSourceTiered(t *testing.T) {
})
}

func testAccAwsVpcIpamsDataSourceConfig_filterWithTiers() string {
func testAccVPCIPAMsDataSourceConfig_filterWithTiers() string {
return acctest.ConfigCompose(testAccIPAMConfig_tags("Some", "Value"), `
data "aws_vpc_ipams" "test" {
ipam_ids = [aws_vpc_ipam.test.id]
ipam_ids = [aws_vpc_ipam.test.id]
}
data "aws_vpc_ipams" "advanced" {
ipam_ids = [aws_vpc_ipam.test.id]
filter {
name = "tier"
values = ["advanced"]
}
ipam_ids = [aws_vpc_ipam.test.id]
filter {
name = "tier"
values = ["advanced"]
}
}
data "aws_vpc_ipams" "free" {
ipam_ids = [aws_vpc_ipam.test.id]
filter {
name = "tier"
values = ["free"]
}
}
`)
ipam_ids = [aws_vpc_ipam.test.id]
filter {
name = "tier"
values = ["free"]
}
}
`)}
10 changes: 5 additions & 5 deletions internal/service/ec2/service_package_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 452a2d1

Please sign in to comment.