Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions .changelog/45366.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```release-note:enhancement
resource/aws_imagebuilder_component: Add latest version ARN attributes
```

```release-note:enhancement
resource/aws_imagebuilder_container_recipe: Add latest version ARN attributes
```

```release-note:enhancement
resource/aws_imagebuilder_image: Add latest version ARN attributes
```

```release-note:enhancement
resource/aws_imagebuilder_image_recipe: Add latest version ARN attributes
```

```release-note:enhancement
resource/aws_imagebuilder_workflow: Add latest version ARN attributes
```
37 changes: 34 additions & 3 deletions internal/service/imagebuilder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ func resourceComponent() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 128),
},
"latest_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_major_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_minor_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_patch_version_arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -184,14 +200,21 @@ func resourceComponentCreate(ctx context.Context, d *schema.ResourceData, meta a

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

if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}

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

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

component, err := findComponentByARN(ctx, conn, d.Id())
output, err := findComponentByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Image Builder Component (%s) not found, removing from state", d.Id())
Expand All @@ -203,6 +226,7 @@ func resourceComponentRead(ctx context.Context, d *schema.ResourceData, meta any
return sdkdiag.AppendErrorf(diags, "reading Image Builder Component (%s): %s", d.Id(), err)
}

component := output.Component
d.Set(names.AttrARN, component.Arn)
d.Set("change_description", component.ChangeDescription)
d.Set("data", component.Data)
Expand All @@ -217,6 +241,13 @@ func resourceComponentRead(ctx context.Context, d *schema.ResourceData, meta any
d.Set(names.AttrType, component.Type)
d.Set(names.AttrVersion, component.Version)

if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}

setTagsOut(ctx, component.Tags)

return diags
Expand Down Expand Up @@ -255,7 +286,7 @@ func resourceComponentDelete(ctx context.Context, d *schema.ResourceData, meta a
return diags
}

func findComponentByARN(ctx context.Context, conn *imagebuilder.Client, arn string) (*awstypes.Component, error) {
func findComponentByARN(ctx context.Context, conn *imagebuilder.Client, arn string) (*imagebuilder.GetComponentOutput, error) {
input := &imagebuilder.GetComponentInput{
ComponentBuildVersionArn: aws.String(arn),
}
Expand All @@ -277,5 +308,5 @@ func findComponentByARN(ctx context.Context, conn *imagebuilder.Client, arn stri
return nil, tfresource.NewEmptyResultError(input)
}

return output.Component, nil
return output, nil
}
26 changes: 25 additions & 1 deletion internal/service/imagebuilder/component_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ func dataSourceComponent() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"latest_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_major_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_minor_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_patch_version_arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand All @@ -87,12 +103,13 @@ func dataSourceComponentRead(ctx context.Context, d *schema.ResourceData, meta a
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)

arn := d.Get(names.AttrARN).(string)
component, err := findComponentByARN(ctx, conn, arn)
output, err := findComponentByARN(ctx, conn, arn)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Image Builder Component (%s): %s", arn, err)
}

component := output.Component
arn = aws.ToString(component.Arn)
d.SetId(arn)
d.Set(names.AttrARN, arn)
Expand All @@ -109,6 +126,13 @@ func dataSourceComponentRead(ctx context.Context, d *schema.ResourceData, meta a
d.Set(names.AttrType, component.Type)
d.Set(names.AttrVersion, component.Version)

if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}

setTagsOut(ctx, component.Tags)

return diags
Expand Down
4 changes: 4 additions & 0 deletions internal/service/imagebuilder/component_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func TestAccImageBuilderComponentDataSource_arn(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, acctest.CtTagsPercent, resourceName, acctest.CtTagsPercent),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrType, resourceName, names.AttrType),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrVersion, resourceName, names.AttrVersion),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_major_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_minor_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_patch_version_arn"),
),
},
},
Expand Down
4 changes: 4 additions & 0 deletions internal/service/imagebuilder/component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func TestAccImageBuilderComponent_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, acctest.CtTagsPercent, "0"),
resource.TestCheckResourceAttr(resourceName, names.AttrType, string(awstypes.ComponentTypeBuild)),
resource.TestCheckResourceAttr(resourceName, names.AttrVersion, "1.0.0"),
resource.TestCheckResourceAttrSet(resourceName, "latest_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_major_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_minor_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_patch_version_arn"),
),
},
{
Expand Down
38 changes: 35 additions & 3 deletions internal/service/imagebuilder/container_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,22 @@ func resourceContainerRecipe() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 1024),
},
"latest_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_major_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_minor_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_patch_version_arn": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -360,14 +376,21 @@ func resourceContainerRecipeCreate(ctx context.Context, d *schema.ResourceData,

d.SetId(aws.ToString(output.ContainerRecipeArn))

if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}

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

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

containerRecipe, err := findContainerRecipeByARN(ctx, conn, d.Id())
output, err := findContainerRecipeByARN(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Image Builder Container Recipe (%s) not found, removing from state", d.Id())
Expand All @@ -379,6 +402,8 @@ func resourceContainerRecipeRead(ctx context.Context, d *schema.ResourceData, me
return sdkdiag.AppendErrorf(diags, "reading Image Builder Container Recipe (%s): %s", d.Id(), err)
}

containerRecipe := output.ContainerRecipe

d.Set(names.AttrARN, containerRecipe.Arn)
if err := d.Set("component", flattenComponentConfigurations(containerRecipe.Components)); err != nil {
return sdkdiag.AppendErrorf(diags, "setting component: %s", err)
Expand Down Expand Up @@ -406,6 +431,13 @@ func resourceContainerRecipeRead(ctx context.Context, d *schema.ResourceData, me
d.Set(names.AttrVersion, containerRecipe.Version)
d.Set("working_directory", containerRecipe.WorkingDirectory)

if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}

setTagsOut(ctx, containerRecipe.Tags)

return diags
Expand Down Expand Up @@ -439,7 +471,7 @@ func resourceContainerRecipeDelete(ctx context.Context, d *schema.ResourceData,
return diags
}

func findContainerRecipeByARN(ctx context.Context, conn *imagebuilder.Client, arn string) (*awstypes.ContainerRecipe, error) {
func findContainerRecipeByARN(ctx context.Context, conn *imagebuilder.Client, arn string) (*imagebuilder.GetContainerRecipeOutput, error) {
input := &imagebuilder.GetContainerRecipeInput{
ContainerRecipeArn: aws.String(arn),
}
Expand All @@ -461,7 +493,7 @@ func findContainerRecipeByARN(ctx context.Context, conn *imagebuilder.Client, ar
return nil, tfresource.NewEmptyResultError(input)
}

return output.ContainerRecipe, nil
return output, nil
}

func expandInstanceConfiguration(tfMap map[string]any) *awstypes.InstanceConfiguration {
Expand Down
25 changes: 24 additions & 1 deletion internal/service/imagebuilder/container_recipe_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,22 @@ func dataSourceContainerRecipe() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"latest_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_major_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_minor_version_arn": {
Type: schema.TypeString,
Computed: true,
},
"latest_patch_version_arn": {
Type: schema.TypeString,
Computed: true,
},
names.AttrName: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -202,12 +218,13 @@ func dataSourceContainerRecipeRead(ctx context.Context, d *schema.ResourceData,
conn := meta.(*conns.AWSClient).ImageBuilderClient(ctx)

arn := d.Get(names.AttrARN).(string)
containerRecipe, err := findContainerRecipeByARN(ctx, conn, arn)
output, err := findContainerRecipeByARN(ctx, conn, arn)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading Image Builder Container Recipe (%s): %s", arn, err)
}

containerRecipe := output.ContainerRecipe
arn = aws.ToString(containerRecipe.Arn)
d.SetId(arn)
d.Set(names.AttrARN, arn)
Expand All @@ -227,6 +244,12 @@ func dataSourceContainerRecipeRead(ctx context.Context, d *schema.ResourceData,
d.Set("instance_configuration", nil)
}
d.Set(names.AttrKMSKeyID, containerRecipe.KmsKeyId)
if output.LatestVersionReferences != nil {
d.Set("latest_version_arn", aws.ToString(output.LatestVersionReferences.LatestVersionArn))
d.Set("latest_major_version_arn", aws.ToString(output.LatestVersionReferences.LatestMajorVersionArn))
d.Set("latest_minor_version_arn", aws.ToString(output.LatestVersionReferences.LatestMinorVersionArn))
d.Set("latest_patch_version_arn", aws.ToString(output.LatestVersionReferences.LatestPatchVersionArn))
}
d.Set(names.AttrName, containerRecipe.Name)
d.Set(names.AttrOwner, containerRecipe.Owner)
d.Set("parent_image", containerRecipe.ParentImage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ func TestAccImageBuilderContainerRecipeDataSource_arn(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrEncrypted, resourceName, names.AttrEncrypted),
resource.TestCheckResourceAttrPair(dataSourceName, "instance_configuration.#", resourceName, "instance_configuration.#"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrKMSKeyID, resourceName, names.AttrKMSKeyID),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_major_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_minor_version_arn"),
resource.TestCheckResourceAttrSet(dataSourceName, "latest_patch_version_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrName, resourceName, names.AttrName),
resource.TestCheckResourceAttrPair(dataSourceName, names.AttrOwner, resourceName, names.AttrOwner),
resource.TestCheckResourceAttrPair(dataSourceName, "parent_image", resourceName, "parent_image"),
Expand Down
4 changes: 4 additions & 0 deletions internal/service/imagebuilder/container_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ func TestAccImageBuilderContainerRecipe_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, names.AttrEncrypted, acctest.CtTrue),
resource.TestCheckResourceAttr(resourceName, "instance_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, names.AttrKMSKeyID, ""),
resource.TestCheckResourceAttrSet(resourceName, "latest_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_major_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_minor_version_arn"),
resource.TestCheckResourceAttrSet(resourceName, "latest_patch_version_arn"),
resource.TestCheckResourceAttr(resourceName, names.AttrName, rName),
acctest.CheckResourceAttrAccountID(ctx, resourceName, names.AttrOwner),
acctest.CheckResourceAttrRegionalARNAccountID(resourceName, "parent_image", "imagebuilder", "aws", "image/amazon-linux-x86-2/x.x.x"),
Expand Down
Loading
Loading