-
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_distribution_configuration #16180
Merged
Merged
Changes from all commits
Commits
Show all changes
27 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 09e672e
service/imagebuilder: Remove non-aws_imagebuilder_distribution_config…
bflad c21b59c
New Resource: aws_imagebuilder_distribution_configuration
bflad 8649bc0
docs/resource/aws_imagebuilder_distribution_configuration: Fix typo
bflad 30b5f3a
Merge branch 'master' into f-aws_imagebuilder_distribution_configuration
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
144 changes: 144 additions & 0 deletions
144
aws/data_source_aws_imagebuilder_distribution_configuration.go
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,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 | ||
} |
53 changes: 53 additions & 0 deletions
53
aws/data_source_aws_imagebuilder_distribution_configuration_test.go
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,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) | ||
} |
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 this 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.
Treating all the fields as potentially "optional" in the Create/Update function logic will allow us to reduce code churn in the future should the APIs support other fields and gets us closer towards code generation since it can be agnostic to how the data is coming in. It is just a little awkward right now because we do (or at least should) treat everything as "optional" in the expand functions but the root attribute handling is different with
ResourceData
instead of a raw state map.I'm hoping later this week to submit more definitive documentation on ideal object/"structure" handling in the provider codebase, with an eye towards that sort of code generation in the future, so we can have clear standards where possible. 😄