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

feat: add aws_imagebuilder_lifecycle_policy & Tech debt: migrate imagebuilder resources to AWS SDK for Go v2 #35674

Merged
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
5aa37d9
feat (WIP): add imagebuilder lifecycle policy
bschaatsbergen Feb 6, 2024
0cf9f00
chore: fix root schema
bschaatsbergen Feb 16, 2024
d9f4ef0
chore: fix nested schema attributes
bschaatsbergen Feb 16, 2024
7bb7cd2
feat: added read/update handlers
DanielRieske Feb 17, 2024
d3ce450
feat: added recreate on name update
DanielRieske Feb 17, 2024
854fa6c
feat: added resource attribute tyoes
DanielRieske Feb 17, 2024
182b7ea
feat: added get func and basic read handler
DanielRieske Feb 17, 2024
4177bad
feat: added flatteners
DanielRieske Feb 17, 2024
4655ace
feat: added basic test and exports
DanielRieske Feb 17, 2024
d502ea3
chore: begin migrating imagebuilder service to v2 sdk
bschaatsbergen Feb 19, 2024
ac649f7
chore: begin v2 migration of imagebuilder
bschaatsbergen Feb 22, 2024
f4cae4f
chore: go mod tidy
bschaatsbergen Feb 28, 2024
49c4063
chore: migrating to aws-sdk-v2 go
bschaatsbergen Feb 29, 2024
149c1c4
chore: migrating to aws-sdk-v2 go
bschaatsbergen Feb 29, 2024
efd6672
feat: migrated resources to v2
DanielRieske Feb 29, 2024
1499032
chore: migrate to aws-sdk-go-v2
bschaatsbergen Mar 2, 2024
124e0ac
chore: migrate to aws-sdk-go-v2
bschaatsbergen Mar 2, 2024
8cf2319
feat: fixed namevaluesfiltersv2 code generator and tests
DanielRieske Mar 2, 2024
c66f2af
feat: migrate imagebuilder sweepers to aws-sdk-go-v2
bschaatsbergen Mar 11, 2024
dbc1245
Merge branch 'main' into f/image-builder-lifecycle-policy
bschaatsbergen Mar 11, 2024
c1f37ce
chore: go mod tidy
bschaatsbergen Mar 11, 2024
de643df
chore: add 'ImageBuilder' to the test name
bschaatsbergen Mar 11, 2024
98fde52
chore: use correct caps in func name
bschaatsbergen Mar 11, 2024
1015be4
chore: use enum.Slice
bschaatsbergen Mar 12, 2024
24659bf
chore: fix caps
bschaatsbergen Mar 12, 2024
d964200
chore: fix dupe import
bschaatsbergen Mar 12, 2024
1b725d4
bug: fix incorrect cast
bschaatsbergen Mar 12, 2024
013ff6a
chore: add a role
bschaatsbergen Mar 12, 2024
a794aaa
chore: fix types
bschaatsbergen Mar 12, 2024
e958a32
fix: ci errors
bschaatsbergen Mar 12, 2024
c4a79ae
feat: fix format and redundant conversions
DanielRieske Mar 15, 2024
cab8852
feat: fixed resource not found exception
DanielRieske Mar 15, 2024
436daf5
Create imagebuilder_lifecycle_policy.html.markdown
bschaatsbergen Mar 16, 2024
92a5e53
chore: add 'resource_type' and 'policy_details' to test
bschaatsbergen Mar 16, 2024
1087365
chore: lint acc
bschaatsbergen Mar 16, 2024
68e7856
chore: fix typo
bschaatsbergen Mar 16, 2024
df91a78
chore: set tags/tagsall in struct
bschaatsbergen Mar 16, 2024
3b52dc5
chore: set 'ARN' to string type
bschaatsbergen Mar 16, 2024
fa45387
chore: revert temp makefile change
bschaatsbergen Mar 16, 2024
4dde3c6
fix: resource not found exceptions
DanielRieske Mar 25, 2024
40d3815
fix: workflow notfound exception
DanielRieske Mar 26, 2024
61c0348
fix: fix schema and test case
DanielRieske Mar 26, 2024
33462fe
fix: unit argument and computed arguments
DanielRieske Mar 26, 2024
619e2e2
feat: fix arguments in lifecycle policy test
DanielRieske Apr 3, 2024
24881e5
feat: added retry for iam propagation period
DanielRieske Apr 5, 2024
a1a7c52
Merge branch 'main' into f/image-builder-lifecycle-policy
DanielRieske Apr 6, 2024
5899610
fix: dependencies
DanielRieske Apr 6, 2024
3fe1603
feat: added tag test
DanielRieske Apr 6, 2024
2ecba2a
feat: added disappears test
DanielRieske Apr 12, 2024
f6b2408
feat: expanded basic test validation
DanielRieske Apr 13, 2024
13ccfe5
feat: added policyDetails test and fix update handler
DanielRieske Apr 13, 2024
27ba412
feat: expand policyDetails test and several fixes in amis
DanielRieske Apr 14, 2024
f21e407
chore: fmt
DanielRieske Apr 14, 2024
6cb143a
feat: added resourceSelection test scenario and validation
DanielRieske Apr 14, 2024
de3510f
chore: fmt
DanielRieske Apr 14, 2024
1d2ff7e
docs: added full example and specified acceptable values where approp…
DanielRieske Apr 14, 2024
0b9072f
docs: fix resource reference
DanielRieske Apr 14, 2024
c204a15
docs: fmt
DanielRieske Apr 14, 2024
45b5057
feat: removed const EBSVolumeTypeGP3 due to swap to sdkv2
DanielRieske Apr 14, 2024
809617e
feat: added lifecycle sweeper and cleanup
DanielRieske Apr 14, 2024
d35467f
feat: added arn attribute to lifecycle sweeper
DanielRieske Apr 14, 2024
040b70c
feat: cleanup lifecycle policy tests
DanielRieske Apr 14, 2024
86eb322
fix: imageRecipeEBS arguments
DanielRieske Apr 14, 2024
c8a4204
fix: notFoundException for Image resource
DanielRieske Apr 14, 2024
7ccee5e
Merge branch 'main' into HEAD
ewbankkit Aug 5, 2024
0f94c55
Run 'make fix-constants PKG=imagebuilder'.
ewbankkit Aug 5, 2024
625842d
Remove unsued code.
ewbankkit Aug 5, 2024
8094e23
Run 'make fmt'.
ewbankkit Aug 5, 2024
4590b1b
Import 'names'.
ewbankkit Aug 5, 2024
20d5880
r/aws_imagebuilder_component: Reduce visibility.
ewbankkit Aug 5, 2024
6edea27
d/aws_imagebuilder_component: Reduce visibility.
ewbankkit Aug 5, 2024
f51fcad
d/aws_imagebuilder_components: Reduce visibility.
ewbankkit Aug 5, 2024
1a23441
r/aws_imagebuilder_container_recipe: Reduce visibility.
ewbankkit Aug 5, 2024
504af6a
d/aws_imagebuilder_container_recipe: Reduce visibility.
ewbankkit Aug 5, 2024
fa841ad
d/aws_imagebuilder_container_recipes: Reduce visibility.
ewbankkit Aug 5, 2024
be66716
r/aws_imagebuilder_distribution_configuration: Reduce visibility.
ewbankkit Aug 5, 2024
2cf51b1
d/aws_imagebuilder_distribution_configuration: Reduce visibility.
ewbankkit Aug 5, 2024
3440411
d/aws_imagebuilder_distribution_configurations: Reduce visibility.
ewbankkit Aug 5, 2024
e1917f9
r/aws_imagebuilder_image: Reduce visibility.
ewbankkit Aug 5, 2024
9496e5f
d/aws_imagebuilder_image: Reduce visibility.
ewbankkit Aug 5, 2024
a75e6ae
r/aws_imagebuilder_image_pipeline: Reduce visibility.
ewbankkit Aug 5, 2024
8146dee
d/aws_imagebuilder_image_pipeline: Reduce visibility.
ewbankkit Aug 5, 2024
f2ee005
d/aws_imagebuilder_image_pipelines: Reduce visibility.
ewbankkit Aug 5, 2024
77432aa
r/aws_imagebuilder_image_recipe: Reduce visibility.
ewbankkit Aug 5, 2024
b98ec77
d/aws_imagebuilder_image_recipe: Reduce visibility.
ewbankkit Aug 5, 2024
a56200a
d/aws_imagebuilder_image_recipes: Reduce visibility.
ewbankkit Aug 5, 2024
3648ec2
r/aws_imagebuilder_infrastructure_configuration: Reduce visibility.
ewbankkit Aug 5, 2024
0efb770
d/aws_imagebuilder_infrastructure_configuration: Reduce visibility.
ewbankkit Aug 5, 2024
d0d38c9
d/aws_imagebuilder_infrastructure_configurations: Reduce visibility.
ewbankkit Aug 5, 2024
893bb81
r/aws_imagebuilder_image: Tidy up waiting.
ewbankkit Aug 5, 2024
b69fc23
r/aws_imagebuilder_workflow: Reduce visibility.
ewbankkit Aug 5, 2024
49214da
r/aws_imagebuilder_lifecycle_policy: Use AutoFlEx.
ewbankkit Aug 5, 2024
942ab4f
imagebuilder: Tidy up sweepers.
ewbankkit Aug 5, 2024
efe4fea
Add CHANGELOG entry.
ewbankkit Aug 5, 2024
e261457
r/aws_imagebuilder_lifecycle_policy: 'policy_details' -> 'policy_deta…
ewbankkit Aug 5, 2024
a5ea69b
r/aws_imagebuilder_lifecycle_policy: 'include_resources' -> 'include_…
ewbankkit Aug 5, 2024
0548869
r/aws_imagebuilder_lifecycle_policy: 'exclusion_rules' -> 'exclusion_…
ewbankkit Aug 5, 2024
720c1bd
r/aws_imagebuilder_lifecycle_policy: 'recipes' -> 'recipe'.
ewbankkit Aug 5, 2024
e86decf
r/aws_imagebuilder_lifecycle_policy: 'exclusion_rule' -> 'exclusion_r…
ewbankkit Aug 5, 2024
0969e5a
r/aws_imagebuilder_lifecycle_policy: 'include_resource' -> 'include_r…
ewbankkit Aug 5, 2024
8d7cfff
r/aws_imagebuilder_lifecycle_policy: Fixes after some testing.
ewbankkit Aug 5, 2024
3933223
r/aws_imagebuilder_lifecycle_policy: Use 'ParallelTest'.
ewbankkit Aug 6, 2024
2ee5141
r/aws_imagebuilder_lifecycle_policy: 'policy_detail.action.include_re…
ewbankkit Aug 6, 2024
ce9651a
r/aws_imagebuilder_lifecycle_policy: Fixes after some more testing.
ewbankkit Aug 6, 2024
7b6e117
Acceptance test output:
ewbankkit Aug 6, 2024
134e6df
imagebuilder: Use 'tfawserr.ErrCodeEquals', not 'errs.IsA'.
ewbankkit Aug 6, 2024
1af104e
Fix 'TestAccImageBuilderContainerRecipe_InstanceConfiguration_Image'.
ewbankkit Aug 6, 2024
a18d5ca
Merge branch 'main' into HEAD
ewbankkit Sep 3, 2024
30d5697
No more AWS SDK for Go v1 'namevaluesfilters'.
ewbankkit Sep 3, 2024
75da52f
Merge branch 'main' into HEAD
ewbankkit Sep 13, 2024
4aad53c
Fix semgrep 'ci.semgrep.framework.model-tag-types'.
ewbankkit Sep 13, 2024
b958507
Merge branch 'main' into HEAD
ewbankkit Sep 20, 2024
c9b6615
Fix semgrep 'ci.semgrep.framework.flex-type-from-framework'.
ewbankkit Sep 20, 2024
0f5b40c
Merge branch 'main' into HEAD
ewbankkit Sep 24, 2024
c1cfc0c
tfresource: Remove AWS SDK for Go v1 error handling.
ewbankkit Sep 24, 2024
14677ac
Merge branch 'main' into HEAD
ewbankkit Oct 8, 2024
abb7df4
Fix 'Warning: [Fixable] Interpolation-only expressions are deprecated…
ewbankkit Oct 9, 2024
58ce67c
Merge branch 'main' into HEAD
ewbankkit Oct 9, 2024
187d143
Merge branch 'main' into HEAD
ewbankkit Oct 16, 2024
1dfd05a
github.com/aws/aws-sdk-go-v2/service/imagebuilder@v1.37.3
ewbankkit Oct 16, 2024
b0d0e13
'component/update-linux/1.0.0' -> 'component/update-linux/1.0.2'.
ewbankkit Oct 16, 2024
a3d3cf6
Fix 'TestAccImageBuilderDistributionConfiguration_DistributionFastLau…
ewbankkit Oct 16, 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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/groundstation v1.26.2
github.com/aws/aws-sdk-go-v2/service/healthlake v1.23.2
github.com/aws/aws-sdk-go-v2/service/identitystore v1.23.2
github.com/aws/aws-sdk-go-v2/service/imagebuilder v1.32.1
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.24.2
github.com/aws/aws-sdk-go-v2/service/internetmonitor v1.12.2
github.com/aws/aws-sdk-go-v2/service/ivschat v1.12.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ github.com/aws/aws-sdk-go-v2/service/iam v1.30.1 h1:sCLZjJpGNMeyhyudAhipabxqwZpP
github.com/aws/aws-sdk-go-v2/service/iam v1.30.1/go.mod h1:vc5DmJnsyyX6UpZwIKT2y1hEhzHoGDjONKhDcDwA49g=
github.com/aws/aws-sdk-go-v2/service/identitystore v1.23.2 h1:1UQL8QlgDvGUwSKWhty8tbgv+QCzs/NAeCWbbuvxLDg=
github.com/aws/aws-sdk-go-v2/service/identitystore v1.23.2/go.mod h1:pH/6CBpgeQtIpuM4eDgf+OJDrZU+iG03xjy8vIRcI1k=
github.com/aws/aws-sdk-go-v2/service/imagebuilder v1.32.1 h1:5kP0+cOT2ApEUKUMM+zIP/fZpdmKeQa4Jl5iF8eHI9c=
github.com/aws/aws-sdk-go-v2/service/imagebuilder v1.32.1/go.mod h1:JUoAL2dg3oOHOv7/HB6r1z65cn9Fx34hGcMa0C4JjDc=
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.24.2 h1:/Tdn1+AYzUH4WVfDdrKc/JNOC/XP7txBHdVDYkLFlD0=
github.com/aws/aws-sdk-go-v2/service/inspector2 v1.24.2/go.mod h1:VrG1RiAI8qS4txEGSZBRVjsLdLlH9CP2UHPP3inKL9c=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.1 h1:EyBZibRTVAs6ECHZOw5/wlylS9OcTzwyjeQMudmREjE=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const filename = `service_filters_v2_gen.go`
// Representing types such as []*ec2.Filter, []*rds.Filter, ...
var sliceServiceNames = []string{
"secretsmanager",
"imagebuilder",
}

type TemplateData struct {
Expand Down Expand Up @@ -82,18 +83,17 @@ var templateBody = `
package namevaluesfiltersv2

import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports
"github.com/aws/aws-sdk-go-v2/aws"
{{- range .SliceServiceNames }}
{{- if eq . (. | FilterPackage) }}
{{ . }}
{{- end }}
{{ . | FilterPackage }}
{{- end }}
)

// []*SERVICE.Filter handling
{{- range .SliceServiceNames }}

// {{ . | Title }}Filters returns {{ . }} service filters.
func (filters NameValuesFilters) {{ . | Title }}Filters() []*{{ . | FilterPackagePrefix }}.{{ . | FilterType }} {
func (filters NameValuesFilters) {{ . | Title }}Filters() []{{ . | FilterPackagePrefix }}.{{ . | FilterType }} {
m := filters.Map()

if len(m) == 0 {
Expand All @@ -104,7 +104,7 @@ func (filters NameValuesFilters) {{ . | Title }}Filters() []*{{ . | FilterPackag

for k, v := range m {
filter := {{ . | FilterPackagePrefix }}.{{ . | FilterType }}{
{{ . | FilterTypeNameField }}: { . | FilterPackagePrefix }}.FilterNameStringType(k),
{{ . | FilterTypeNameField }}: {{ . | FilterPackagePrefix }}.FilterNameStringType(k),
{{ . | FilterTypeValuesField }}: v,
}

Expand Down
36 changes: 36 additions & 0 deletions internal/generate/namevaluesfiltersv2/imagebuilder_filters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build !generate
// +build !generate

package namevaluesfiltersv2

import ( // nosemgrep:ci.semgrep.aws.multiple-service-imports
"github.com/aws/aws-sdk-go-v2/aws"
imagebuildertypes "github.com/aws/aws-sdk-go-v2/service/imagebuilder/types"
)

// []*SERVICE.Filter handling

// ImagebuilderFilters returns imagebuilder service filters.
func (filters NameValuesFilters) ImagebuilderFilters() []imagebuildertypes.Filter {
m := filters.Map()

if len(m) == 0 {
return nil
}

result := make([]imagebuildertypes.Filter, 0, len(m))

for k, v := range m {
filter := imagebuildertypes.Filter{
Name: aws.String(k),
Values: v,
}

result = append(result, filter)
}

return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,33 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfilters"
"github.com/hashicorp/terraform-provider-aws/internal/generate/namevaluesfiltersv2"
)

func TestNameValuesFiltersMap(t *testing.T) {
t.Parallel()

testCases := []struct {
name string
filters namevaluesfilters.NameValuesFilters
filters namevaluesfiltersv2.NameValuesFilters
want map[string][]string
}{
{
name: "empty",
filters: namevaluesfilters.New(map[string][]string{}),
filters: namevaluesfiltersv2.New(map[string][]string{}),
want: map[string][]string{},
},
{
name: "empty_strings",
filters: namevaluesfilters.New(map[string][]string{
filters: namevaluesfiltersv2.New(map[string][]string{
"name1": {""},
"name2": {"", ""},
}),
want: map[string][]string{},
},
{
name: "duplicates",
filters: namevaluesfilters.New(map[string][]string{
filters: namevaluesfiltersv2.New(map[string][]string{
"name1": {"value1"},
"name2": {"value2a", "value2b", "", "value2a", "value2c", "value2c"},
}),
Expand Down
40 changes: 21 additions & 19 deletions internal/service/imagebuilder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ import (
"context"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/imagebuilder"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/imagebuilder"
awstypes "github.com/aws/aws-sdk-go-v2/service/imagebuilder/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
Expand Down Expand Up @@ -84,10 +86,10 @@ func ResourceComponent() *schema.Resource {
Computed: true,
},
"platform": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(imagebuilder.Platform_Values(), false),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateDiagFunc: enum.Validate[awstypes.Platform](),
},
"skip_destroy": {
Type: schema.TypeBool,
Expand Down Expand Up @@ -131,7 +133,7 @@ func ResourceComponent() *schema.Resource {

func resourceComponentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)
ewbankkit marked this conversation as resolved.
Show resolved Hide resolved

input := &imagebuilder.CreateComponentInput{
ClientToken: aws.String(id.UniqueId()),
Expand Down Expand Up @@ -159,11 +161,11 @@ func resourceComponentCreate(ctx context.Context, d *schema.ResourceData, meta i
}

if v, ok := d.GetOk("platform"); ok {
input.Platform = aws.String(v.(string))
input.Platform = awstypes.Platform(v.(string))
}

if v, ok := d.GetOk("supported_os_versions"); ok && v.(*schema.Set).Len() > 0 {
input.SupportedOsVersions = flex.ExpandStringSet(v.(*schema.Set))
input.SupportedOsVersions = flex.ExpandStringValueSet(v.(*schema.Set))
}

if v, ok := d.GetOk("uri"); ok {
Expand All @@ -174,7 +176,7 @@ func resourceComponentCreate(ctx context.Context, d *schema.ResourceData, meta i
input.SemanticVersion = aws.String(v.(string))
}

output, err := conn.CreateComponentWithContext(ctx, input)
output, err := conn.CreateComponent(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating Image Builder Component: %s", err)
Expand All @@ -184,22 +186,22 @@ func resourceComponentCreate(ctx context.Context, d *schema.ResourceData, meta i
return sdkdiag.AppendErrorf(diags, "creating Image Builder Component: empty result")
}

d.SetId(aws.StringValue(output.ComponentBuildVersionArn))
d.SetId(aws.ToString(output.ComponentBuildVersionArn))

return append(diags, resourceComponentRead(ctx, d, meta)...)
}

func resourceComponentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)

input := &imagebuilder.GetComponentInput{
ComponentBuildVersionArn: aws.String(d.Id()),
}

output, err := conn.GetComponentWithContext(ctx, input)
output, err := conn.GetComponent(ctx, input)

if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, imagebuilder.ErrCodeResourceNotFoundException) {
if !d.IsNewResource() && errs.MessageContains(err, ResourceNotFoundException, "cannot be found") {
log.Printf("[WARN] Image Builder Component (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
Expand All @@ -225,7 +227,7 @@ func resourceComponentRead(ctx context.Context, d *schema.ResourceData, meta int
d.Set("name", component.Name)
d.Set("owner", component.Owner)
d.Set("platform", component.Platform)
d.Set("supported_os_versions", aws.StringValueSlice(component.SupportedOsVersions))
d.Set("supported_os_versions", component.SupportedOsVersions)

setTagsOut(ctx, component.Tags)

Expand All @@ -251,15 +253,15 @@ func resourceComponentDelete(ctx context.Context, d *schema.ResourceData, meta i
return diags
}

conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)

input := &imagebuilder.DeleteComponentInput{
ComponentBuildVersionArn: aws.String(d.Id()),
}

_, err := conn.DeleteComponentWithContext(ctx, input)
_, err := conn.DeleteComponent(ctx, input)

if tfawserr.ErrCodeEquals(err, imagebuilder.ErrCodeResourceNotFoundException) {
if errs.MessageContains(err, ResourceNotFoundException, "cannot be found") {
return diags
}

Expand Down
17 changes: 7 additions & 10 deletions internal/service/imagebuilder/component_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ package imagebuilder
import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/imagebuilder"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/imagebuilder"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
Expand Down Expand Up @@ -83,16 +83,15 @@ func DataSourceComponent() *schema.Resource {

func dataSourceComponentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)

input := &imagebuilder.GetComponentInput{}

if v, ok := d.GetOk("arn"); ok {
input.ComponentBuildVersionArn = aws.String(v.(string))
}

output, err := conn.GetComponentWithContext(ctx, input)
output, err := conn.GetComponent(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "getting Image Builder Component: %s", err)
Expand All @@ -104,7 +103,7 @@ func dataSourceComponentRead(ctx context.Context, d *schema.ResourceData, meta i

component := output.Component

d.SetId(aws.StringValue(component.Arn))
d.SetId(aws.ToString(component.Arn))

d.Set("arn", component.Arn)
d.Set("change_description", component.ChangeDescription)
Expand All @@ -116,11 +115,9 @@ func dataSourceComponentRead(ctx context.Context, d *schema.ResourceData, meta i
d.Set("name", component.Name)
d.Set("owner", component.Owner)
d.Set("platform", component.Platform)
d.Set("supported_os_versions", aws.StringValueSlice(component.SupportedOsVersions))
d.Set("supported_os_versions", component.SupportedOsVersions)

if err := d.Set("tags", KeyValueTags(ctx, component.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)
}
setTagsOut(ctx, component.Tags)

d.Set("type", component.Type)
d.Set("version", component.Version)
Expand Down
Loading