Skip to content

Commit

Permalink
New Resource: aws_imagebuilder_component (#16169)
Browse files Browse the repository at this point in the history
* Add aws_imagebuilder_component

* Add test for data_source_aws_imagebuilder_component

* Add aws_imagebuilder_infrastructureconfiguration

* Add aws_imagebuilder_recipe

* Rename to aws_imagebuilder_infrastructure_configuration

* Fix issue with infraconfig logging

* Fix incorrect MaxItems on res

* Fix S024

* Fix AWSR002

* Fix linting

* [#11084] Fix the imagebuilder resource, add test and docs

# Conflicts:
#	aws/provider.go

* Fix incorrect import on error handling

* Update to v2 SDK

* Fix R004 lint issue

* Remove changes to aws.erb

* Add imagebuilder_distribution_configuration

* Add imagebuilder_image_pipeline

* fixed some lint issues and fixed terminate_instance_on_failure not being set on create

* description can be updated in place

* service/imagebuilder: Remove non-aws_imagebuilder_component files

* New Resource: aws_imagebuilder_component

Reference: #11084
Reference: #13315

Changes:

```
* **New Data Source:** `aws_imagebuilder_component`
* **New Resource:** `aws_imagebuilder_component`
```

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAwsImageBuilderComponent_basic (18.98s)
--- PASS: TestAccAwsImageBuilderComponent_ChangeDescription (19.15s)
--- PASS: TestAccAwsImageBuilderComponent_Description (19.29s)
--- PASS: TestAccAwsImageBuilderComponent_disappears (15.10s)
--- PASS: TestAccAwsImageBuilderComponent_KmsKeyId (23.58s)
--- PASS: TestAccAwsImageBuilderComponent_Platform_Windows (19.22s)
--- PASS: TestAccAwsImageBuilderComponent_SupportedOsVersions (19.15s)
--- PASS: TestAccAwsImageBuilderComponent_Tags (42.96s)
--- PASS: TestAccAwsImageBuilderComponent_Uri (35.66s)

--- PASS: TestAccAwsImageBuilderComponentDataSource_Arn (18.51s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAwsImageBuilderComponent_basic (24.13s)
--- PASS: TestAccAwsImageBuilderComponent_ChangeDescription (23.39s)
--- PASS: TestAccAwsImageBuilderComponent_Description (24.43s)
--- PASS: TestAccAwsImageBuilderComponent_disappears (19.28s)
--- PASS: TestAccAwsImageBuilderComponent_KmsKeyId (28.49s)
--- PASS: TestAccAwsImageBuilderComponent_Platform_Windows (24.54s)
--- PASS: TestAccAwsImageBuilderComponent_SupportedOsVersions (24.05s)
--- PASS: TestAccAwsImageBuilderComponent_Tags (53.99s)
--- PASS: TestAccAwsImageBuilderComponent_Uri (40.78s)

--- PASS: TestAccAwsImageBuilderComponentDataSource_Arn (24.26s)
```

Output from sweeper in AWS Commercial:

```
2020/11/12 16:58:32 [DEBUG] Running Sweepers for region (us-west-2):
2020/11/12 16:58:32 [DEBUG] Running Sweeper (aws_imagebuilder_component) in region (us-west-2)
2020/11/12 16:58:45 Sweeper Tests ran successfully:
	- aws_imagebuilder_component
2020/11/12 16:58:45 [DEBUG] Running Sweepers for region (us-east-1):
2020/11/12 16:58:45 [DEBUG] Running Sweeper (aws_imagebuilder_component) in region (us-east-1)
2020/11/12 16:58:46 Sweeper Tests ran successfully:
	- aws_imagebuilder_component
ok  	github.com/terraform-providers/terraform-provider-aws/aws	18.223s
```
Output from sweeper in AWS GovCloud (US):

```
2020/11/12 16:59:00 [DEBUG] Running Sweepers for region (us-gov-west-1):
2020/11/12 16:59:00 [DEBUG] Running Sweeper (aws_imagebuilder_component) in region (us-gov-west-1)
2020/11/12 16:59:03 Sweeper Tests ran successfully:
	- aws_imagebuilder_component
ok  	github.com/terraform-providers/terraform-provider-aws/aws	5.004s
```

* resource/aws_imagebuilder_component: terrafmt fixes

* tests/data-source/aws_imagebuilder_component: terrafmt fix

* Apply suggestions from code review

Co-authored-by: Dogers <[email protected]>
Co-authored-by: Jakub Kania <[email protected]>
Co-authored-by: Bill Schneider <[email protected]>
  • Loading branch information
4 people authored Nov 17, 2020
1 parent 01f2518 commit c8c09ba
Show file tree
Hide file tree
Showing 8 changed files with 1,227 additions and 0 deletions.
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 @@ -701,6 +702,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

0 comments on commit c8c09ba

Please sign in to comment.