From aed44a1bea44ff43c73ad7d345cf1bdf485a3aff Mon Sep 17 00:00:00 2001 From: EC2 Default User Date: Sun, 14 May 2023 10:13:17 +0000 Subject: [PATCH 1/5] Added managed execution config to stacksets --- .changelog/25210.txt | 3 ++ internal/service/cloudformation/stack_set.go | 53 +++++++++++++++++++ .../service/cloudformation/stack_set_test.go | 6 +++ .../r/cloudformation_stack_set.html.markdown | 2 + 4 files changed, 64 insertions(+) create mode 100644 .changelog/25210.txt diff --git a/.changelog/25210.txt b/.changelog/25210.txt new file mode 100644 index 000000000000..55c0476e12a0 --- /dev/null +++ b/.changelog/25210.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_cloudformation_stack_set: Add `managed_execution` argument +``` \ No newline at end of file diff --git a/internal/service/cloudformation/stack_set.go b/internal/service/cloudformation/stack_set.go index c368f17b5948..83c8d025055d 100644 --- a/internal/service/cloudformation/stack_set.go +++ b/internal/service/cloudformation/stack_set.go @@ -97,6 +97,20 @@ func ResourceStackSet() *schema.Resource { Computed: true, ConflictsWith: []string{"auto_deployment"}, }, + "managed_execution": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "active": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, + }, + }, + }, "name": { Type: schema.TypeString, Required: true, @@ -221,6 +235,10 @@ func resourceStackSetCreate(ctx context.Context, d *schema.ResourceData, meta in input.ExecutionRoleName = aws.String(v.(string)) } + if v, ok := d.GetOk("managed_execution"); ok { + input.ManagedExecution = expandManagedExecution(v.([]interface{})) + } + if v, ok := d.GetOk("parameters"); ok { input.Parameters = expandParameters(v.(map[string]interface{})) } @@ -283,6 +301,11 @@ func resourceStackSetRead(ctx context.Context, d *schema.ResourceData, meta inte d.Set("description", stackSet.Description) d.Set("execution_role_name", stackSet.ExecutionRoleName) + + if err := d.Set("managed_execution", flattenStackSetManagedExecution(stackSet.ManagedExecution)); err != nil { + return sdkdiag.AppendErrorf(diags, "setting managed_execution: %s", err) + } + d.Set("name", stackSet.StackSetName) d.Set("permission_model", stackSet.PermissionModel) @@ -326,6 +349,10 @@ func resourceStackSetUpdate(ctx context.Context, d *schema.ResourceData, meta in input.ExecutionRoleName = aws.String(v.(string)) } + if v, ok := d.GetOk("managed_execution"); ok { + input.ManagedExecution = expandManagedExecution(v.([]interface{})) + } + if v, ok := d.GetOk("operation_preferences"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil { input.OperationPreferences = expandOperationPreferences(v.([]interface{})[0].(map[string]interface{})) } @@ -418,6 +445,20 @@ func expandAutoDeployment(l []interface{}) *cloudformation.AutoDeployment { return autoDeployment } +func expandManagedExecution(l []interface{}) *cloudformation.ManagedExecution { + if len(l) == 0 { + return nil + } + + m := l[0].(map[string]interface{}) + + managedExecution := &cloudformation.ManagedExecution{ + Active: aws.Bool(m["active"].(bool)), + } + + return managedExecution +} + func flattenStackSetAutoDeploymentResponse(autoDeployment *cloudformation.AutoDeployment) []map[string]interface{} { if autoDeployment == nil { return []map[string]interface{}{} @@ -430,3 +471,15 @@ func flattenStackSetAutoDeploymentResponse(autoDeployment *cloudformation.AutoDe return []map[string]interface{}{m} } + +func flattenStackSetManagedExecution(managedExecution *cloudformation.ManagedExecution) []map[string]interface{} { + if managedExecution == nil { + return []map[string]interface{}{} + } + + m := map[string]interface{}{ + "active": aws.BoolValue(managedExecution.Active), + } + + return []map[string]interface{}{m} +} diff --git a/internal/service/cloudformation/stack_set_test.go b/internal/service/cloudformation/stack_set_test.go index e48ddcdab96e..fbce5c812ceb 100644 --- a/internal/service/cloudformation/stack_set_test.go +++ b/internal/service/cloudformation/stack_set_test.go @@ -41,6 +41,8 @@ func TestAccCloudFormationStackSet_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "call_as", "SELF"), resource.TestCheckResourceAttr(resourceName, "description", ""), resource.TestCheckResourceAttr(resourceName, "execution_role_name", "AWSCloudFormationStackSetExecutionRole"), + resource.TestCheckResourceAttr(resourceName, "managed_execution.#", "1"), + resource.TestCheckResourceAttr(resourceName, "managed_execution.0.active", "true"), resource.TestCheckResourceAttr(resourceName, "name", rName), resource.TestCheckResourceAttr(resourceName, "operation_preferences.#", "0"), resource.TestCheckResourceAttr(resourceName, "parameters.%", "0"), @@ -1129,6 +1131,10 @@ resource "aws_cloudformation_stack_set" "test" { administration_role_arn = aws_iam_role.test.arn name = %[1]q + managed_execution { + active = true + } + template_body = <