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

Added managed execution config to stacksets #31400

Merged
merged 5 commits into from
May 30, 2023
Merged
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
3 changes: 3 additions & 0 deletions .changelog/25210.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_cloudformation_stack_set: Add `managed_execution` argument
```
57 changes: 56 additions & 1 deletion internal/service/cloudformation/stack_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"log"
"regexp"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudformation"
Expand Down Expand Up @@ -35,7 +36,7 @@ func ResourceStackSet() *schema.Resource {
},

Timeouts: &schema.ResourceTimeout{
Update: schema.DefaultTimeout(StackSetUpdatedDefaultTimeout),
Update: schema.DefaultTimeout(30 * time.Minute),
},

Schema: map[string]*schema.Schema{
Expand Down Expand Up @@ -97,6 +98,21 @@ 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,
},
},
},
DiffSuppressFunc: verify.SuppressMissingOptionalConfigurationBlock,
},
"name": {
Type: schema.TypeString,
Required: true,
Expand Down Expand Up @@ -221,6 +237,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{}))
}
Expand Down Expand Up @@ -283,6 +303,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)

Expand Down Expand Up @@ -326,6 +351,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{}))
}
Expand Down Expand Up @@ -418,6 +447,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{}{}
Expand All @@ -430,3 +473,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}
}
Loading