-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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_recipe #16218
Merged
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
96b4232
Add aws_imagebuilder_component
Dogers 2d588c2
Add test for data_source_aws_imagebuilder_component
Dogers a5d9f8f
Add aws_imagebuilder_infrastructureconfiguration
Dogers 6414616
Add aws_imagebuilder_recipe
Dogers c29b5da
Rename to aws_imagebuilder_infrastructure_configuration
Dogers 8b53767
Fix issue with infraconfig logging
Dogers 8ce7b6b
Fix incorrect MaxItems on res
Dogers fbe7510
Fix S024
Dogers 28dfb17
Fix AWSR002
Dogers 507fe42
Fix linting
Dogers ca89e2b
[#11084] Fix the imagebuilder resource, add test and docs
blckct 195ba8a
Merge remote-tracking branch 'source/master' into image-builder
Dogers 0d050cd
Merge branch 'master' into image-builder
Dogers 26e1bb9
Fix incorrect import on error handling
Dogers df7016f
Update to v2 SDK
Dogers 89e7bdd
Fix R004 lint issue
Dogers 18dd1b0
Remove changes to aws.erb
Dogers 1b85e94
Add imagebuilder_distribution_configuration
Dogers eb8e1ed
Add imagebuilder_image_pipeline
Dogers 0402fe7
fixed some lint issues and fixed terminate_instance_on_failure not be…
wrschneider a20d120
description can be updated in place
wrschneider 10c55b6
Merge pull request #1 from wrschneider/image-builder
Dogers 7cfe977
Merge branch 'image-builder' of ssh://github.com/Dogers/terraform-pro…
bflad cd14a07
service/imagebuilder: Remove non-aws_imagebuilder_image_recipe
bflad 0b2c308
service/imagebuilder: Fix incorrectly named resource files and functi…
bflad 81ceabf
New Resource: aws_imagebuilder_image_recipe
bflad 013f185
tests/service/imagebuilder: terrafmt fixes
bflad fea46f2
Merge branch 'master' into f-aws_imagebuilder_image_recipe
bflad fae63a9
Update aws/resource_aws_imagebuilder_image_recipe_test.go
bflad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 dataSourceAwsImageBuilderImageRecipe() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsImageBuilderImageRecipeRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"arn": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ValidateFunc: validateArn, | ||
}, | ||
"block_device_mapping": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"device_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ebs": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"delete_on_termination": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"encrypted": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"iops": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"kms_key_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"snapshot_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"volume_size": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
"volume_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"no_device": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"virtual_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"component": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"component_arn": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"date_created": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"parent_image": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"platform": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"tags": tagsSchema(), | ||
"version": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsImageBuilderImageRecipeRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).imagebuilderconn | ||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
input := &imagebuilder.GetImageRecipeInput{} | ||
|
||
if v, ok := d.GetOk("arn"); ok { | ||
input.ImageRecipeArn = aws.String(v.(string)) | ||
} | ||
|
||
output, err := conn.GetImageRecipe(input) | ||
|
||
if err != nil { | ||
return fmt.Errorf("error reading Image Builder Image Recipe (%s): %w", aws.StringValue(input.ImageRecipeArn), err) | ||
} | ||
|
||
if output == nil || output.ImageRecipe == nil { | ||
return fmt.Errorf("error reading Image Builder Image Recipe (%s): empty response", aws.StringValue(input.ImageRecipeArn)) | ||
} | ||
|
||
imageRecipe := output.ImageRecipe | ||
|
||
d.SetId(aws.StringValue(imageRecipe.Arn)) | ||
d.Set("arn", imageRecipe.Arn) | ||
d.Set("block_device_mapping", flattenImageBuilderInstanceBlockDeviceMappings(imageRecipe.BlockDeviceMappings)) | ||
d.Set("component", flattenImageBuilderComponentConfigurations(imageRecipe.Components)) | ||
d.Set("date_created", imageRecipe.DateCreated) | ||
d.Set("description", imageRecipe.Description) | ||
d.Set("name", imageRecipe.Name) | ||
d.Set("owner", imageRecipe.Owner) | ||
d.Set("parent_image", imageRecipe.ParentImage) | ||
d.Set("platform", imageRecipe.Platform) | ||
d.Set("tags", keyvaluetags.ImagebuilderKeyValueTags(imageRecipe.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()) | ||
d.Set("version", imageRecipe.Version) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccAwsImageBuilderImageRecipeDataSource_Arn(t *testing.T) { | ||
rName := acctest.RandomWithPrefix("tf-acc-test") | ||
dataSourceName := "data.aws_imagebuilder_image_recipe.test" | ||
resourceName := "aws_imagebuilder_image_recipe.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProviderFactories: testAccProviderFactories, | ||
CheckDestroy: testAccCheckAwsImageBuilderImageRecipeDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAwsImageBuilderImageRecipeDataSourceConfigArn(rName), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "block_device_mapping.#", resourceName, "block_device_mapping.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "component.#", resourceName, "component.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "date_created", resourceName, "date_created"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "name", resourceName, "name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "owner", resourceName, "owner"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "parent_image", resourceName, "parent_image"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "platform", resourceName, "platform"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "version", resourceName, "version"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAwsImageBuilderImageRecipeDataSourceConfigArn(rName string) string { | ||
return fmt.Sprintf(` | ||
data "aws_region" "current" {} | ||
|
||
data "aws_partition" "current" {} | ||
|
||
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" | ||
} | ||
|
||
data "aws_imagebuilder_image_recipe" "test" { | ||
arn = aws_imagebuilder_image_recipe.test.arn | ||
} | ||
`, rName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check, since
arn
is required?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar comment applies, I think. #16180 (comment)