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

fix imagebuilder-pipeline image_recipe_arn ForceNew #17137

Conversation

Goryudyuma
Copy link
Contributor

@Goryudyuma Goryudyuma commented Jan 15, 2021

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #0000

Release note for CHANGELOG:

fix: "ForceNew" in "aws_imagebuilder_image_pipeline.image_recipe_arn" changed to "True".

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

If you keep the previous settings, you will get an error when you change "image_recipe".

Error: error deleting Image Builder Image Recipe (arn:aws:imagebuilder:ap-northeast-1:12345:image-recipe/example/1.0.0): ResourceDependencyException: Resource dependency error: The resource ARN 'arn:aws:imagebuilder:ap-northeast-1:12345:image-recipe/example/1.0.0' has other resources depended on it.

This is a phenomenon that occurs when "image_recipe" cannot be deleted because "ImagePipeline" depends on "image_recipe".
After making this change, the "ImagePipeline" will be recreated and no error will occur.

What I want is that changing "image_recipe" doesn't cause "ImagePipeline" to be an error.
This PR can do that, but if there's a better way, that's fine.
Please tell me what to do after this.

@Goryudyuma Goryudyuma requested a review from a team as a code owner January 15, 2021 17:13
@ghost ghost added size/XS Managed by automation to categorize the size of a PR. service/imagebuilder Issues and PRs that pertain to the imagebuilder service. labels Jan 15, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Jan 15, 2021
@bflad bflad self-assigned this Jan 15, 2021
@bflad
Copy link
Contributor

bflad commented Jan 15, 2021

Hi @Goryudyuma 👋 Thank you for submitting this.

Unfortunately this change is not valid -- the aws_imagebuilder_image_pipeline Terraform resource implements in-place update support for the image_recipe_arn attribute by calling the UpdateImagePipeline API:

if d.HasChanges(
"description",
"distribution_configuration_arn",
"enhanced_image_metadata_enabled",
"image_recipe_arn",
"image_tests_configuration",
"infrastructure_configuration_arn",
"schedule",
"status",
) {
input := &imagebuilder.UpdateImagePipelineInput{
ClientToken: aws.String(resource.UniqueId()),
EnhancedImageMetadataEnabled: aws.Bool(d.Get("enhanced_image_metadata_enabled").(bool)),
ImagePipelineArn: aws.String(d.Id()),
}
if v, ok := d.GetOk("description"); ok {
input.Description = aws.String(v.(string))
}
if v, ok := d.GetOk("distribution_configuration_arn"); ok {
input.DistributionConfigurationArn = aws.String(v.(string))
}
if v, ok := d.GetOk("image_recipe_arn"); ok {
input.ImageRecipeArn = aws.String(v.(string))
}
if v, ok := d.GetOk("image_tests_configuration"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.ImageTestsConfiguration = expandImageBuilderImageTestConfiguration(v.([]interface{})[0].(map[string]interface{}))
}
if v, ok := d.GetOk("infrastructure_configuration_arn"); ok {
input.InfrastructureConfigurationArn = aws.String(v.(string))
}
if v, ok := d.GetOk("schedule"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil {
input.Schedule = expandImageBuilderPipelineSchedule(v.([]interface{})[0].(map[string]interface{}))
}
if v, ok := d.GetOk("status"); ok {
input.Status = aws.String(v.(string))
}
_, err := conn.UpdateImagePipeline(input)
if err != nil {
return fmt.Errorf("error updating Image Builder Image Pipeline (%s): %w", d.Id(), err)
}
}

Which is verified with the TestAccAwsImageBuilderImagePipeline_ImageRecipeArn acceptance test:

func TestAccAwsImageBuilderImagePipeline_ImageRecipeArn(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test")
imageRecipeResourceName := "aws_imagebuilder_image_recipe.test"
imageRecipeResourceName2 := "aws_imagebuilder_image_recipe.test2"
resourceName := "aws_imagebuilder_image_pipeline.test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAwsImageBuilderImagePipelineDestroy,
Steps: []resource.TestStep{
{
Config: testAccAwsImageBuilderImagePipelineConfigName(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsImageBuilderImagePipelineExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "image_recipe_arn", imageRecipeResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAwsImageBuilderImagePipelineConfigImageRecipeArn2(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAwsImageBuilderImagePipelineExists(resourceName),
resource.TestCheckResourceAttrPair(resourceName, "image_recipe_arn", imageRecipeResourceName2, "arn"),
),
},
},
})
}

So while Terraform may not be operating as you expect in this situation, the resource and schema are currently valid. My best suggestion would be to potentially open a GitHub issue following the issue template so the maintainers can attempt to troubleshoot any potential bugs or if you have a question about how Terraform is operating to use the HashiCorp Community Forums where there are far more people ready to help, whereas the GitHub issues here are generally monitored only by the small set of code maintainers.

Very briefly though, you may want to see if your configuration should be using the lifecycle block create_before_destroy argument in this situation -- that can invert the order of operations in Terraform.

@bflad bflad closed this Jan 15, 2021
@Goryudyuma
Copy link
Contributor Author

Hi @bflad !
Thank you for your comment!
As you advised, I wrote "create_before_destroy" in "aws_imagebuilder_image_recipe" and it worked as intended.
I am very happy!
Thank you very much for your help!

@ghost
Copy link

ghost commented Feb 15, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Feb 15, 2021
@breathingdust breathingdust removed the needs-triage Waiting for first response or review from a maintainer. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
service/imagebuilder Issues and PRs that pertain to the imagebuilder service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants