Skip to content

Commit

Permalink
New Resource: aws_imagebuilder_distribution_configuration (#16180)
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_distribution_configuration files

* New Resource: aws_imagebuilder_distribution_configuration

Reference: #11084
Reference: #13316
Reference: #13485

Changes:

```
* **New Data Source:** `aws_imagebuilder_distribution_configuration`
* **New Resource:** `aws_imagebuilder_distribution_configuration`
```

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_basic (23.95s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Description (39.52s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_disappears (18.57s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution (42.99s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_AmiTags (40.02s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_Description (39.36s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_KmsKeyId (46.31s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_LaunchPermission_UserGroups (23.66s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_LaunchPermission_UserIds (40.12s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_Name (39.12s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_TargetAccountIds (40.12s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_LicenseConfigurationArns (40.75s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Tags (49.75s)

--- PASS: TestAccAwsImageBuilderDistributionConfigurationDataSource_Arn (18.52s)
```

Output from acceptance testing in AWS GovCloud (US) (failure information: #16178):

```
--- FAIL: TestAccAwsImageBuilderDistributionConfiguration_Distribution_LicenseConfigurationArns (10.88s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_basic (27.00s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Description (40.22s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_disappears (21.76s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_AmiTags (42.09s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_Description (42.89s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_KmsKeyId (51.80s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_LaunchPermission_UserGroups (26.70s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_LaunchPermission_UserIds (41.44s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_Name (42.32s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Distribution_AmiDistributionConfiguration_TargetAccountIds (42.42s)
--- PASS: TestAccAwsImageBuilderDistributionConfiguration_Tags (55.37s)

--- PASS: TestAccAwsImageBuilderDistributionConfigurationDataSource_Arn (25.62s)
```

Output from sweeper in AWS Commercial:

```
2020/11/13 09:11:34 [DEBUG] Running Sweepers for region (us-west-2):
2020/11/13 09:11:34 [DEBUG] Running Sweeper (aws_imagebuilder_distribution_configuration) in region (us-west-2)
2020/11/13 09:11:37 Sweeper Tests ran successfully:
  - aws_imagebuilder_distribution_configuration
2020/11/13 09:11:37 [DEBUG] Running Sweepers for region (us-east-1):
2020/11/13 09:11:37 [DEBUG] Running Sweeper (aws_imagebuilder_distribution_configuration) in region (us-east-1)
2020/11/13 09:11:39 Sweeper Tests ran successfully:
  - aws_imagebuilder_distribution_configuration
ok    github.com/terraform-providers/terraform-provider-aws/aws 7.724s
```
Output from sweeper in AWS GovCloud (US):

```
2020/11/13 09:30:11 [DEBUG] Running Sweepers for region (us-gov-west-1):
2020/11/13 09:30:11 [DEBUG] Running Sweeper (aws_imagebuilder_distribution_configuration) in region (us-gov-west-1)
2020/11/13 09:30:14 Sweeper Tests ran successfully:
  - aws_imagebuilder_distribution_configuration
ok    github.com/terraform-providers/terraform-provider-aws/aws 4.971s
```

* docs/resource/aws_imagebuilder_distribution_configuration: Fix typo

Co-authored-by: Dogers <Dogers@users.noreply.github.com>
Co-authored-by: Jakub Kania <jakubkania@blackcat.rocks>
Co-authored-by: Bill Schneider <bill.schneider@optum.com>
  • Loading branch information
4 people authored Nov 17, 2020
1 parent e230bf4 commit ad0c7de
Show file tree
Hide file tree
Showing 7 changed files with 1,668 additions and 0 deletions.
144 changes: 144 additions & 0 deletions aws/data_source_aws_imagebuilder_distribution_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
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 datasourceAwsImageBuilderDistributionConfiguration() *schema.Resource {
return &schema.Resource{
Read: datasourceAwsImageBuilderDistributionConfigurationRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
"date_created": {
Type: schema.TypeString,
Computed: true,
},
"date_updated": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"distribution": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ami_distribution_configuration": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ami_tags": tagsSchemaComputed(),
"description": {
Type: schema.TypeString,
Computed: true,
},
"kms_key_id": {
Type: schema.TypeString,
Computed: true,
},
"launch_permission": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user_groups": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"user_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"target_account_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"license_configuration_arns": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"region": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchemaComputed(),
},
}
}

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

input := &imagebuilder.GetDistributionConfigurationInput{}

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

output, err := conn.GetDistributionConfiguration(input)

if err != nil {
return fmt.Errorf("error getting Image Builder Distribution Configuration (%s): %w", d.Id(), err)
}

if output == nil || output.DistributionConfiguration == nil {
return fmt.Errorf("error getting Image Builder Distribution Configuration (%s): empty response", d.Id())
}

distributionConfiguration := output.DistributionConfiguration

d.SetId(aws.StringValue(distributionConfiguration.Arn))
d.Set("arn", distributionConfiguration.Arn)
d.Set("date_created", distributionConfiguration.DateCreated)
d.Set("date_updated", distributionConfiguration.DateUpdated)
d.Set("description", distributionConfiguration.Description)
d.Set("distribution", flattenImageBuilderDistributions(distributionConfiguration.Distributions))
d.Set("name", distributionConfiguration.Name)
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(distributionConfiguration.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map())

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package aws

import (
"fmt"
"testing"

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

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckAwsImageBuilderDistributionConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderDistributionConfigurationDataSourceConfigArn(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_created", resourceName, "date_created"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_updated", resourceName, "date_updated"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "distribution.#", resourceName, "distribution.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
),
},
},
})
}

func testAccAwsImageBuilderDistributionConfigurationDataSourceConfigArn(rName string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
resource "aws_imagebuilder_distribution_configuration" "test" {
name = %[1]q
distribution {
region = data.aws_region.current.name
}
}
data "aws_imagebuilder_distribution_configuration" "test" {
arn = aws_imagebuilder_distribution_configuration.test.arn
}
`, rName)
}
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func Provider() *schema.Provider {
"aws_iam_server_certificate": dataSourceAwsIAMServerCertificate(),
"aws_iam_user": dataSourceAwsIAMUser(),
"aws_imagebuilder_component": dataSourceAwsImageBuilderComponent(),
"aws_imagebuilder_distribution_configuration": datasourceAwsImageBuilderDistributionConfiguration(),
"aws_internet_gateway": dataSourceAwsInternetGateway(),
"aws_iot_endpoint": dataSourceAwsIotEndpoint(),
"aws_inspector_rules_packages": dataSourceAwsInspectorRulesPackages(),
Expand Down Expand Up @@ -703,6 +704,7 @@ func Provider() *schema.Provider {
"aws_iam_user": resourceAwsIamUser(),
"aws_iam_user_login_profile": resourceAwsIamUserLoginProfile(),
"aws_imagebuilder_component": resourceAwsImageBuilderComponent(),
"aws_imagebuilder_distribution_configuration": resourceAwsImageBuilderDistributionConfiguration(),
"aws_inspector_assessment_target": resourceAWSInspectorAssessmentTarget(),
"aws_inspector_assessment_template": resourceAWSInspectorAssessmentTemplate(),
"aws_inspector_resource_group": resourceAWSInspectorResourceGroup(),
Expand Down
Loading

0 comments on commit ad0c7de

Please sign in to comment.