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_image_pipeline #16299

Merged
merged 28 commits into from
Nov 25, 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
0a5114d
service/imagebuilder: Remove non-aws_imagebuilder_image_pipeline reso…
bflad Nov 18, 2020
b3836a5
New Resource: aws_imagebuilder_image_pipeline
bflad Nov 19, 2020
aa97c2f
Merge branch 'master' into f-aws_imagebuilder_image_pipeline
bflad Nov 19, 2020
5526d4e
service/imagebuilder: terrafmt fixes and aws_imagebuilder_image_pipel…
bflad Nov 19, 2020
9bbd6cf
Merge branch 'master' into f-aws_imagebuilder_image_pipeline
bflad Nov 24, 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
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 @@ -710,6 +711,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