Skip to content

Commit

Permalink
New Resource: aws_imagebuilder_infrastructure_configuration
Browse files Browse the repository at this point in the history
Reference: #11084
Reference: #13485
Reference: #14347

Changes:

```
* **New Data Source:** `aws_imagebuilder_infrastructure_configuration`
* **New Resource:** `aws_imagebuilder_infrastructure_configuration`
```

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_basic (47.25s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Description (56.76s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_disappears (34.25s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_InstanceProfileName (75.52s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_InstanceTypes (63.65s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_KeyPair (63.67s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Logging_S3Logs_S3BucketName (82.86s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Logging_S3Logs_S3KeyPrefix (76.12s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_ResourceTags (62.22s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SecurityGroupIds (76.90s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SnsTopicArn (69.00s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SubnetId (76.21s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Tags (74.09s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_TerminateInstanceOnFailure (62.45s)

--- PASS: TestAccAwsImageBuilderInfrastructureConfigurationDataSource_Arn (26.62s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_basic (51.08s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Description (66.77s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_disappears (44.79s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_InstanceProfileName (76.02s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_InstanceTypes (71.91s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_KeyPair (73.11s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Logging_S3Logs_S3BucketName (88.93s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Logging_S3Logs_S3KeyPrefix (84.10s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_ResourceTags (71.55s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SecurityGroupIds (81.06s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SnsTopicArn (69.43s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_SubnetId (83.06s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_Tags (87.65s)
--- PASS: TestAccAwsImageBuilderInfrastructureConfiguration_TerminateInstanceOnFailure (71.96s)

--- PASS: TestAccAwsImageBuilderInfrastructureConfigurationDataSource_Arn (33.51s)
```

Output from sweeper in AWS Commercial:

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

```
2020/11/13 14:24:10 [DEBUG] Running Sweepers for region (us-gov-west-1):
2020/11/13 14:24:10 [DEBUG] Running Sweeper (aws_imagebuilder_infrastructure_configuration) in region (us-gov-west-1)
2020/11/13 14:24:12 Sweeper Tests ran successfully:
  - aws_imagebuilder_infrastructure_configuration
ok    github.com/terraform-providers/terraform-provider-aws/aws 4.976s
```
  • Loading branch information
bflad committed Nov 13, 2020
1 parent e0dd8f7 commit c6ef225
Show file tree
Hide file tree
Showing 7 changed files with 1,424 additions and 390 deletions.
142 changes: 142 additions & 0 deletions aws/data_source_aws_imagebuilder_infrastructure_configuration.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
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 datasourceAwsImageBuilderInfrastructureConfiguration() *schema.Resource {
return &schema.Resource{
Read: datasourceAwsImageBuilderInfrastructureConfigurationRead,

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,
},
"instance_profile_name": {
Type: schema.TypeString,
Computed: true,
},
"instance_types": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"key_pair": {
Type: schema.TypeString,
Computed: true,
},
"logging": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_logs": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_bucket_name": {
Type: schema.TypeString,
Computed: true,
},
"s3_key_prefix": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"resource_tags": tagsSchemaComputed(),
"security_group_ids": {
Type: schema.TypeSet,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
"sns_topic_arn": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchemaComputed(),
"terminate_instance_on_failure": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}

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

input := &imagebuilder.GetInfrastructureConfigurationInput{}

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

output, err := conn.GetInfrastructureConfiguration(input)

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

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

infrastructureConfiguration := output.InfrastructureConfiguration

d.SetId(aws.StringValue(infrastructureConfiguration.Arn))
d.Set("arn", infrastructureConfiguration.Arn)
d.Set("date_created", infrastructureConfiguration.DateCreated)
d.Set("date_updated", infrastructureConfiguration.DateUpdated)
d.Set("description", infrastructureConfiguration.Description)
d.Set("instance_profile_name", infrastructureConfiguration.InstanceProfileName)
d.Set("instance_types", aws.StringValueSlice(infrastructureConfiguration.InstanceTypes))
d.Set("key_pair", infrastructureConfiguration.KeyPair)
if infrastructureConfiguration.Logging != nil {
d.Set("logging", []interface{}{flattenImageBuilderLogging(infrastructureConfiguration.Logging)})
} else {
d.Set("logging", nil)
}
d.Set("name", infrastructureConfiguration.Name)
d.Set("resource_tags", keyvaluetags.ImagebuilderKeyValueTags(infrastructureConfiguration.ResourceTags).Map())
d.Set("security_group_ids", aws.StringValueSlice(infrastructureConfiguration.SecurityGroupIds))
d.Set("sns_topic_arn", infrastructureConfiguration.SnsTopicArn)
d.Set("subnet_id", infrastructureConfiguration.SubnetId)
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(infrastructureConfiguration.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map())
d.Set("terminate_instance_on_failure", infrastructureConfiguration.TerminateInstanceOnFailure)

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

import (
"fmt"
"testing"

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

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckAwsImageBuilderInfrastructureConfigurationDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderInfrastructureConfigurationDataSourceConfigArn(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, "instance_profile_name", resourceName, "instance_profile_name"),
resource.TestCheckResourceAttrPair(dataSourceName, "instance_types.#", resourceName, "instance_types.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "key_pair", resourceName, "key_pair"),
resource.TestCheckResourceAttrPair(dataSourceName, "logging.#", resourceName, "logging.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "resource_tags.%", resourceName, "resource_tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "security_group_ids.#", resourceName, "security_group_ids.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "sns_topic_arn", resourceName, "sns_topic_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "subnet_id", resourceName, "subnet_id"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
resource.TestCheckResourceAttrPair(dataSourceName, "terminate_instance_on_failure", resourceName, "terminate_instance_on_failure"),
),
},
},
})
}

func testAccAwsImageBuilderInfrastructureConfigurationDataSourceConfigArn(rName string) string {
return fmt.Sprintf(`
data "aws_partition" "current" {}
resource "aws_iam_instance_profile" "test" {
name = aws_iam_role.role.name
role = aws_iam_role.role.name
}
resource "aws_iam_role" "role" {
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "ec2.${data.aws_partition.current.dns_suffix}"
}
Sid = ""
}]
})
name = %[1]q
}
resource "aws_imagebuilder_infrastructure_configuration" "test" {
instance_profile_name = aws_iam_instance_profile.test.name
name = %[1]q
}
data "aws_imagebuilder_infrastructure_configuration" "test" {
arn = aws_imagebuilder_infrastructure_configuration.test.arn
}
`, rName)
}
1 change: 1 addition & 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_infrastructure_configuration": datasourceAwsImageBuilderInfrastructureConfiguration(),
"aws_internet_gateway": dataSourceAwsInternetGateway(),
"aws_iot_endpoint": dataSourceAwsIotEndpoint(),
"aws_inspector_rules_packages": dataSourceAwsInspectorRulesPackages(),
Expand Down
Loading

0 comments on commit c6ef225

Please sign in to comment.