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

New Resource: aws_imagebuilder_component #16169

Merged
merged 28 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
96b4232
Add aws_imagebuilder_component
Dogers Feb 21, 2020
2d588c2
Add test for data_source_aws_imagebuilder_component
Dogers Feb 22, 2020
a5d9f8f
Add aws_imagebuilder_infrastructureconfiguration
Dogers Feb 22, 2020
6414616
Add aws_imagebuilder_recipe
Dogers Mar 3, 2020
c29b5da
Rename to aws_imagebuilder_infrastructure_configuration
Dogers May 6, 2020
8b53767
Fix issue with infraconfig logging
Dogers May 25, 2020
8ce7b6b
Fix incorrect MaxItems on res
Dogers May 25, 2020
fbe7510
Fix S024
Dogers May 25, 2020
28dfb17
Fix AWSR002
Dogers May 25, 2020
507fe42
Fix linting
Dogers May 25, 2020
ca89e2b
[#11084] Fix the imagebuilder resource, add test and docs
blckct Jul 12, 2020
195ba8a
Merge remote-tracking branch 'source/master' into image-builder
Dogers Aug 2, 2020
0d050cd
Merge branch 'master' into image-builder
Dogers Aug 19, 2020
26e1bb9
Fix incorrect import on error handling
Dogers Aug 19, 2020
df7016f
Update to v2 SDK
Dogers Aug 19, 2020
89e7bdd
Fix R004 lint issue
Dogers Aug 19, 2020
18dd1b0
Remove changes to aws.erb
Dogers Aug 19, 2020
1b85e94
Add imagebuilder_distribution_configuration
Dogers Aug 2, 2020
eb8e1ed
Add imagebuilder_image_pipeline
Dogers Aug 25, 2020
0402fe7
fixed some lint issues and fixed terminate_instance_on_failure not be…
wrschneider Aug 28, 2020
a20d120
description can be updated in place
wrschneider Aug 28, 2020
10c55b6
Merge pull request #1 from wrschneider/image-builder
Dogers Aug 28, 2020
7cfe977
Merge branch 'image-builder' of ssh://github.com/Dogers/terraform-pro…
bflad Nov 12, 2020
0a7cf06
service/imagebuilder: Remove non-aws_imagebuilder_component files
bflad Nov 12, 2020
aed6234
New Resource: aws_imagebuilder_component
bflad Nov 12, 2020
462e324
resource/aws_imagebuilder_component: terrafmt fixes
bflad Nov 13, 2020
068c4fd
tests/data-source/aws_imagebuilder_component: terrafmt fix
bflad Nov 13, 2020
45e7450
Apply suggestions from code review
bflad Nov 17, 2020
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
120 changes: 120 additions & 0 deletions aws/data_source_aws_imagebuilder_component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package aws

import (
"fmt"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/imagebuilder"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags"
)

func dataSourceAwsImageBuilderComponent() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsImageBuilderComponentRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
"change_description": {
Type: schema.TypeString,
Computed: true,
},
"data": {
Type: schema.TypeString,
Computed: true,
},
"date_created": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"encrypted": {
Type: schema.TypeBool,
Computed: true,
},
"kms_key_id": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"owner": {
Type: schema.TypeString,
Computed: true,
},
"platform": {
Type: schema.TypeString,
Computed: true,
},
"supported_os_versions": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"tags": tagsSchemaComputed(),
"type": {
Type: schema.TypeString,
Computed: true,
},
"version": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceAwsImageBuilderComponentRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).imagebuilderconn
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig

input := &imagebuilder.GetComponentInput{}

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

output, err := conn.GetComponent(input)

if err != nil {
return fmt.Errorf("error getting Image Builder Component: %w", err)
}

if output == nil || output.Component == nil {
return fmt.Errorf("error getting Image Builder Component: empty result")
}

component := output.Component

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

d.Set("arn", component.Arn)
d.Set("change_description", component.ChangeDescription)
d.Set("data", component.Data)
d.Set("date_created", component.DateCreated)
d.Set("description", component.Description)
d.Set("encrypted", component.Encrypted)
d.Set("kms_key_id", component.KmsKeyId)
d.Set("name", component.Name)
d.Set("owner", component.Owner)
d.Set("platform", component.Platform)
d.Set("supported_os_versions", aws.StringValueSlice(component.SupportedOsVersions))

if err := d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(component.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return fmt.Errorf("error setting tags: %w", err)
}

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

return nil
}
70 changes: 70 additions & 0 deletions aws/data_source_aws_imagebuilder_component_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package aws

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccAwsImageBuilderComponentDataSource_Arn(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
dataSourceName := "data.aws_imagebuilder_component.test"
resourceName := "aws_imagebuilder_component.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckAwsImageBuilderComponentDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderComponentDataSourceConfigBuildVersionArn(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "change_description", resourceName, "change_description"),
resource.TestCheckResourceAttrPair(dataSourceName, "data", resourceName, "data"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_created", resourceName, "date_created"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "encrypted", resourceName, "encrypted"),
resource.TestCheckResourceAttrPair(dataSourceName, "kms_key_id", resourceName, "kms_key_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "owner", resourceName, "owner"),
resource.TestCheckResourceAttrPair(dataSourceName, "platform", resourceName, "platform"),
resource.TestCheckResourceAttrPair(dataSourceName, "supported_os_versions.#", resourceName, "supported_os_versions.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "type", resourceName, "type"),
resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"),
),
},
},
})
}

func testAccAwsImageBuilderComponentDataSourceConfigBuildVersionArn(rName string) string {
return fmt.Sprintf(`
resource "aws_imagebuilder_component" "test" {
data = yamlencode({
phases = [{
name = "build"
steps = [{
action = "ExecuteBash"
inputs = {
commands = ["echo 'hello world'"]
}
name = "example"
onFailure = "Continue"
}]
}]
schemaVersion = 1.0
})
name = %[1]q
platform = "Linux"
version = "1.0.0"
}

data "aws_imagebuilder_component" "test" {
arn = aws_imagebuilder_component.test.arn
}
`, rName)
}
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func Provider() *schema.Provider {
"aws_iam_role": dataSourceAwsIAMRole(),
"aws_iam_server_certificate": dataSourceAwsIAMServerCertificate(),
"aws_iam_user": dataSourceAwsIAMUser(),
"aws_imagebuilder_component": dataSourceAwsImageBuilderComponent(),
"aws_internet_gateway": dataSourceAwsInternetGateway(),
"aws_iot_endpoint": dataSourceAwsIotEndpoint(),
"aws_inspector_rules_packages": dataSourceAwsInspectorRulesPackages(),
Expand Down Expand Up @@ -698,6 +699,7 @@ func Provider() *schema.Provider {
"aws_iam_user_ssh_key": resourceAwsIamUserSshKey(),
"aws_iam_user": resourceAwsIamUser(),
"aws_iam_user_login_profile": resourceAwsIamUserLoginProfile(),
"aws_imagebuilder_component": resourceAwsImageBuilderComponent(),
"aws_inspector_assessment_target": resourceAWSInspectorAssessmentTarget(),
"aws_inspector_assessment_template": resourceAWSInspectorAssessmentTemplate(),
"aws_inspector_resource_group": resourceAWSInspectorResourceGroup(),
Expand Down
Loading