Skip to content

Commit

Permalink
New Resource: aws_imagebuilder_image_pipeline (#16299)
Browse files Browse the repository at this point in the history
Reference: #11084
Reference: #13485
Reference: #16218 (required for `aws_imagebuilder_image_recipe` resource implementation)

Changes:

```
* **New Data Source:** `aws_imagebuilder_image_pipeline`
* **New Resource:** `aws_imagebuilder_image_pipeline`
```

Output from acceptance testing in AWS Commercial:

```
--- PASS: TestAccAwsImageBuilderImagePipeline_basic (36.73s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Description (59.17s)
--- PASS: TestAccAwsImageBuilderImagePipeline_disappears (28.69s)
--- PASS: TestAccAwsImageBuilderImagePipeline_DistributionConfigurationArn (62.02s)
--- PASS: TestAccAwsImageBuilderImagePipeline_EnhancedImageMetadataEnabled (61.63s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageRecipeArn (57.56s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageTestsConfiguration_ImageTestsEnabled (61.52s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageTestsConfiguration_TimeoutMinutes (61.49s)
--- PASS: TestAccAwsImageBuilderImagePipeline_InfrastructureConfigurationArn (57.93s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Schedule_PipelineExecutionStartCondition (61.29s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Schedule_ScheduleExpression (62.21s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Status (57.90s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Tags (73.01s)

--- PASS: TestAccAwsImageBuilderImagePipelineDataSource_Arn (33.95s)
```

Output from acceptance testing in AWS GovCloud (US):

```
--- PASS: TestAccAwsImageBuilderImagePipeline_basic (45.88s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Description (65.03s)
--- PASS: TestAccAwsImageBuilderImagePipeline_disappears (39.74s)
--- PASS: TestAccAwsImageBuilderImagePipeline_DistributionConfigurationArn (66.42s)
--- PASS: TestAccAwsImageBuilderImagePipeline_EnhancedImageMetadataEnabled (63.39s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageRecipeArn (66.54s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageTestsConfiguration_ImageTestsEnabled (65.08s)
--- PASS: TestAccAwsImageBuilderImagePipeline_ImageTestsConfiguration_TimeoutMinutes (61.28s)
--- PASS: TestAccAwsImageBuilderImagePipeline_InfrastructureConfigurationArn (66.96s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Schedule_PipelineExecutionStartCondition (61.44s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Schedule_ScheduleExpression (60.45s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Status (65.08s)
--- PASS: TestAccAwsImageBuilderImagePipeline_Tags (81.64s)

--- PASS: TestAccAwsImageBuilderImagePipelineDataSource_Arn (36.13s)
```

Output from sweeper in AWS Commercial:

```
2020/11/18 20:23:09 [DEBUG] Running Sweepers for region (us-west-2):
2020/11/18 20:23:09 [DEBUG] Running Sweeper (aws_imagebuilder_image_pipeline) in region (us-west-2)
2020/11/18 20:23:11 Sweeper Tests ran successfully:
  - aws_imagebuilder_image_pipeline
2020/11/18 20:23:11 [DEBUG] Running Sweepers for region (us-east-1):
2020/11/18 20:23:11 [DEBUG] Running Sweeper (aws_imagebuilder_image_pipeline) in region (us-east-1)
2020/11/18 20:23:11 Sweeper Tests ran successfully:
  - aws_imagebuilder_image_pipeline
ok    github.com/terraform-providers/terraform-provider-aws/aws 5.138s
```

Output from sweeper in AWS GovCloud (US):

```
2020/11/18 20:23:10 [DEBUG] Running Sweepers for region (us-gov-west-1):
2020/11/18 20:23:10 [DEBUG] Running Sweeper (aws_imagebuilder_image_pipeline) in region (us-gov-west-1)
2020/11/18 20:23:13 Sweeper Tests ran successfully:
  - aws_imagebuilder_image_pipeline
ok    github.com/terraform-providers/terraform-provider-aws/aws 4.805s
```

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 25, 2020
1 parent 31fa723 commit d71a43a
Show file tree
Hide file tree
Showing 7 changed files with 1,679 additions and 0 deletions.
159 changes: 159 additions & 0 deletions aws/data_source_aws_imagebuilder_image_pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
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 dataSourceAwsImageBuilderImagePipeline() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsImageBuilderImagePipelineRead,

Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
"date_created": {
Type: schema.TypeString,
Computed: true,
},
"date_last_run": {
Type: schema.TypeString,
Computed: true,
},
"date_next_run": {
Type: schema.TypeString,
Computed: true,
},
"date_updated": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"distribution_configuration_arn": {
Type: schema.TypeString,
Computed: true,
},
"enhanced_image_metadata_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"image_recipe_arn": {
Type: schema.TypeString,
Computed: true,
},
"image_tests_configuration": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"image_tests_enabled": {
Type: schema.TypeBool,
Computed: true,
},
"timeout_minutes": {
Type: schema.TypeInt,
Computed: true,
},
},
},
},
"infrastructure_configuration_arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"platform": {
Type: schema.TypeString,
Computed: true,
},
"schedule": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pipeline_execution_start_condition": {
Type: schema.TypeString,
Computed: true,
},
"schedule_expression": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"status": {
Type: schema.TypeString,
Computed: true,
},
"tags": tagsSchemaComputed(),
},
}
}

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

input := &imagebuilder.GetImagePipelineInput{}

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

output, err := conn.GetImagePipeline(input)

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

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

imagePipeline := output.ImagePipeline

d.SetId(aws.StringValue(imagePipeline.Arn))
d.Set("arn", imagePipeline.Arn)
d.Set("date_created", imagePipeline.DateCreated)
d.Set("date_last_run", imagePipeline.DateLastRun)
d.Set("date_next_run", imagePipeline.DateNextRun)
d.Set("date_updated", imagePipeline.DateUpdated)
d.Set("description", imagePipeline.Description)
d.Set("distribution_configuration_arn", imagePipeline.DistributionConfigurationArn)
d.Set("enhanced_image_metadata_enabled", imagePipeline.EnhancedImageMetadataEnabled)
d.Set("image_recipe_arn", imagePipeline.ImageRecipeArn)

if imagePipeline.ImageTestsConfiguration != nil {
d.Set("image_tests_configuration", []interface{}{flattenImageBuilderImageTestsConfiguration(imagePipeline.ImageTestsConfiguration)})
} else {
d.Set("image_tests_configuration", nil)
}

d.Set("infrastructure_configuration_arn", imagePipeline.InfrastructureConfigurationArn)
d.Set("name", imagePipeline.Name)
d.Set("platform", imagePipeline.Platform)

if imagePipeline.Schedule != nil {
d.Set("schedule", []interface{}{flattenImageBuilderSchedule(imagePipeline.Schedule)})
} else {
d.Set("schedule", nil)
}

d.Set("status", imagePipeline.Status)
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(imagePipeline.Tags).IgnoreAws().IgnoreConfig(meta.(*AWSClient).IgnoreTagsConfig).Map())

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

import (
"fmt"
"testing"

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

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckAwsImageBuilderImagePipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderImagePipelineDataSourceConfigArn(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_created", resourceName, "date_created"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_last_run", resourceName, "date_last_run"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_next_run", resourceName, "date_next_run"),
resource.TestCheckResourceAttrPair(dataSourceName, "date_updated", resourceName, "date_updated"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "distribution_configuration_arn", resourceName, "distribution_configuration_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "enhanced_image_metadata_enabled", resourceName, "enhanced_image_metadata_enabled"),
resource.TestCheckResourceAttrPair(dataSourceName, "image_recipe_arn", resourceName, "image_recipe_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "image_tests_configuration.#", resourceName, "image_tests_configuration.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "infrastructure_configuration_arn", resourceName, "infrastructure_configuration_arn"),
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"),
resource.TestCheckResourceAttrPair(dataSourceName, "platform", resourceName, "platform"),
resource.TestCheckResourceAttrPair(dataSourceName, "schedule.#", resourceName, "schedule.#"),
resource.TestCheckResourceAttrPair(dataSourceName, "status", resourceName, "status"),
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"),
),
},
},
})
}

func testAccAwsImageBuilderImagePipelineDataSourceConfigArn(rName string) string {
return fmt.Sprintf(`
data "aws_region" "current" {}
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_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"
}
resource "aws_imagebuilder_image_recipe" "test" {
component {
component_arn = aws_imagebuilder_component.test.arn
}
name = %[1]q
parent_image = "arn:${data.aws_partition.current.partition}:imagebuilder:${data.aws_region.current.name}:aws:image/amazon-linux-2-x86/x.x.x"
version = "1.0.0"
}
resource "aws_imagebuilder_infrastructure_configuration" "test" {
instance_profile_name = aws_iam_instance_profile.test.name
name = %[1]q
}
resource "aws_imagebuilder_image_pipeline" "test" {
image_recipe_arn = aws_imagebuilder_image_recipe.test.arn
infrastructure_configuration_arn = aws_imagebuilder_infrastructure_configuration.test.arn
name = %[1]q
}
data "aws_imagebuilder_image_pipeline" "test" {
arn = aws_imagebuilder_image_pipeline.test.arn
}
`, rName)
}
2 changes: 2 additions & 0 deletions aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ func Provider() *schema.Provider {
"aws_iam_user": dataSourceAwsIAMUser(),
"aws_imagebuilder_component": dataSourceAwsImageBuilderComponent(),
"aws_imagebuilder_distribution_configuration": datasourceAwsImageBuilderDistributionConfiguration(),
"aws_imagebuilder_image_pipeline": dataSourceAwsImageBuilderImagePipeline(),
"aws_imagebuilder_image_recipe": dataSourceAwsImageBuilderImageRecipe(),
"aws_imagebuilder_infrastructure_configuration": datasourceAwsImageBuilderInfrastructureConfiguration(),
"aws_internet_gateway": dataSourceAwsInternetGateway(),
Expand Down Expand Up @@ -711,6 +712,7 @@ func Provider() *schema.Provider {
"aws_iam_user_login_profile": resourceAwsIamUserLoginProfile(),
"aws_imagebuilder_component": resourceAwsImageBuilderComponent(),
"aws_imagebuilder_distribution_configuration": resourceAwsImageBuilderDistributionConfiguration(),
"aws_imagebuilder_image_pipeline": resourceAwsImageBuilderImagePipeline(),
"aws_imagebuilder_image_recipe": resourceAwsImageBuilderImageRecipe(),
"aws_imagebuilder_infrastructure_configuration": resourceAwsImageBuilderInfrastructureConfiguration(),
"aws_inspector_assessment_target": resourceAWSInspectorAssessmentTarget(),
Expand Down
Loading

0 comments on commit d71a43a

Please sign in to comment.