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

Add skip_destroy to ImageBuilder Container/Image Recipes #30531

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .changelog/30531.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
resource/aws_imagebuilder_container_recipe: Add optional skip_destroy argument
```

```release-note:enhancement
resource/aws_imagebuilder_image_recipe: Add optional skip_destroy argument
```
11 changes: 11 additions & 0 deletions internal/service/imagebuilder/container_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ func ResourceContainerRecipe() *schema.Resource {
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{"Linux", "Windows"}, false),
},
"skip_destroy": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
names.AttrTags: tftags.TagsSchema(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
"target_repository": {
Expand Down Expand Up @@ -424,6 +429,12 @@ func resourceContainerRecipeUpdate(ctx context.Context, d *schema.ResourceData,

func resourceContainerRecipeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) {
log.Printf("[DEBUG] Retaining Imagebuilder Container Recipe version %q", d.Id())
return diags
}

conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)

input := &imagebuilder.DeleteContainerRecipeInput{
Expand Down
139 changes: 79 additions & 60 deletions internal/service/imagebuilder/container_recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ func TestAccImageBuilderContainerRecipe_basic(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -112,9 +113,10 @@ func TestAccImageBuilderContainerRecipe_component(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -144,9 +146,10 @@ func TestAccImageBuilderContainerRecipe_componentParameter(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -171,9 +174,10 @@ func TestAccImageBuilderContainerRecipe_description(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -201,7 +205,7 @@ func TestAccImageBuilderContainerRecipe_dockerfileTemplateURI(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"dockerfile_template_uri"},
ImportStateVerifyIgnore: []string{"dockerfile_template_uri", "skip_destroy"},
},
},
})
Expand All @@ -228,9 +232,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -258,9 +263,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -288,9 +294,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -318,9 +325,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -349,9 +357,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -380,9 +389,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -410,9 +420,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -440,9 +451,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -470,9 +482,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -499,9 +512,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -528,9 +542,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_BlockDeviceMapping
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -557,9 +572,10 @@ func TestAccImageBuilderContainerRecipe_InstanceConfiguration_Image(t *testing.T
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -585,9 +601,10 @@ func TestAccImageBuilderContainerRecipe_kmsKeyID(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand All @@ -613,9 +630,10 @@ func TestAccImageBuilderContainerRecipe_tags(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
{
Config: testAccContainerRecipeConfig_tags2(rName, "key1", "value1updated", "key2", "value2"),
Expand Down Expand Up @@ -657,9 +675,10 @@ func TestAccImageBuilderContainerRecipe_workingDirectory(t *testing.T) {
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"skip_destroy"},
},
},
})
Expand Down Expand Up @@ -688,7 +707,7 @@ func TestAccImageBuilderContainerRecipe_platformOverride(t *testing.T) {
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"platform_override"},
ImportStateVerifyIgnore: []string{"platform_override", "skip_destroy"},
},
},
})
Expand Down Expand Up @@ -841,7 +860,7 @@ parameters:
- Parameter1:
type: string
- Parameter2:
type: string
type: string
schemaVersion: 1.0
EOF

Expand Down
11 changes: 11 additions & 0 deletions internal/service/imagebuilder/image_recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func ResourceImageRecipe() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"skip_destroy": {
Type: schema.TypeBool,
Default: false,
Optional: true,
},
"systems_manager_agent": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -363,6 +368,12 @@ func resourceImageRecipeUpdate(ctx context.Context, d *schema.ResourceData, meta

func resourceImageRecipeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics

if v, ok := d.GetOk("skip_destroy"); ok && v.(bool) {
log.Printf("[DEBUG] Retaining Imagebuilder Image Recipe version %q", d.Id())
return diags
}

conn := meta.(*conns.AWSClient).ImageBuilderConn(ctx)

input := &imagebuilder.DeleteImageRecipeInput{
Expand Down
Loading
Loading