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

Support the update of KxCluster databases and code configuration #34220

Merged
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/34220.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_finspace_kx_cluster: In-place updates are now supported for the `code`, `database`, and `initialization_script` arguments. The update timeout has been increased to 30 minutes.
```
97 changes: 81 additions & 16 deletions internal/service/finspace/kx_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func ResourceKxCluster() *schema.Resource {

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(45 * time.Minute),
Update: schema.DefaultTimeout(2 * time.Minute), // Tags only
Update: schema.DefaultTimeout(30 * time.Minute),
Delete: schema.DefaultTimeout(60 * time.Minute),
},

Expand Down Expand Up @@ -155,26 +155,22 @@ func ResourceKxCluster() *schema.Resource {
"code": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"s3_bucket": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(3, 255),
},
"s3_key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(3, 1024),
},
"s3_object_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(3, 63),
},
},
Expand All @@ -184,7 +180,6 @@ func ResourceKxCluster() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
ForceNew: true,
ValidateDiagFunc: validation.AllDiag(
validation.MapKeyLenBetween(1, 50),
validation.MapValueLenBetween(1, 50),
Expand All @@ -197,13 +192,11 @@ func ResourceKxCluster() *schema.Resource {
"database": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cache_configurations": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cache_type": {
Expand All @@ -217,15 +210,13 @@ func ResourceKxCluster() *schema.Resource {
Type: schema.TypeString,
},
Optional: true,
ForceNew: true,
},
},
},
},
"changeset_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 26),
},
"database_name": {
Expand Down Expand Up @@ -258,7 +249,6 @@ func ResourceKxCluster() *schema.Resource {
"initialization_script": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: validation.StringLenBetween(1, 255),
},
"last_modified_timestamp": {
Expand Down Expand Up @@ -509,10 +499,8 @@ func resourceKxClusterRead(ctx context.Context, d *schema.ResourceData, meta int
return append(diags, create.DiagError(names.FinSpace, create.ErrActionSetting, ResNameKxCluster, d.Id(), err)...)
}

if d.IsNewResource() {
if err := d.Set("database", flattenDatabases(out.Databases)); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionSetting, ResNameKxCluster, d.Id(), err)...)
}
if err := d.Set("database", flattenDatabases(out.Databases)); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionSetting, ResNameKxCluster, d.Id(), err)...)
}

if err := d.Set("command_line_arguments", flattenCommandLineArguments(out.CommandLineArguments)); err != nil {
Expand All @@ -537,7 +525,66 @@ func resourceKxClusterRead(ctx context.Context, d *schema.ResourceData, meta int

func resourceKxClusterUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
// Tags only.
conn := meta.(*conns.AWSClient).FinSpaceClient(ctx)

updateDb := false
updateCode := false

CodeConfigIn := &finspace.UpdateKxClusterCodeConfigurationInput{
EnvironmentId: aws.String(d.Get("environment_id").(string)),
ClusterName: aws.String(d.Get("name").(string)),
}

DatabaseConfigIn := &finspace.UpdateKxClusterDatabasesInput{
EnvironmentId: aws.String(d.Get("environment_id").(string)),
ClusterName: aws.String(d.Get("name").(string)),
}

if v, ok := d.GetOk("database"); ok && len(v.([]interface{})) > 0 && d.HasChanges("database") {
DatabaseConfigIn.Databases = expandDatabases(d.Get("database").([]interface{}))
updateDb = true
}

if v, ok := d.GetOk("code"); ok && len(v.([]interface{})) > 0 && v.([]interface{})[0] != nil && d.HasChanges("code") {
CodeConfigIn.Code = expandCode(v.([]interface{}))
updateCode = true
}

if v, ok := d.GetOk("initialization_script"); ok && d.HasChanges("initialization_script") {
CodeConfigIn.Code = expandCode(d.Get("code").([]interface{}))
CodeConfigIn.InitializationScript = aws.String(v.(string))
updateCode = true
}

if v, ok := d.GetOk("command_line_arguments"); ok && len(v.(map[string]interface{})) > 0 && d.HasChanges("command_line_arguments") {
CodeConfigIn.Code = expandCode(d.Get("code").([]interface{}))
CodeConfigIn.CommandLineArguments = expandCommandLineArguments(v.(map[string]interface{}))
updateCode = true
}

if updateDb {
log.Printf("[DEBUG] Updating FinSpace KxClusterDatabases (%s): %#v", d.Id(), DatabaseConfigIn)
if _, err := conn.UpdateKxClusterDatabases(ctx, DatabaseConfigIn); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxCluster, d.Id(), err)...)
}
if _, err := waitKxClusterUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxCluster, d.Id(), err)...)
}
}

if updateCode {
log.Printf("[DEBUG] Updating FinSpace KxClusterCodeConfiguration (%s): %#v", d.Id(), CodeConfigIn)
if _, err := conn.UpdateKxClusterCodeConfiguration(ctx, CodeConfigIn); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxCluster, d.Id(), err)...)
}
if _, err := waitKxClusterUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
return append(diags, create.DiagError(names.FinSpace, create.ErrActionUpdating, ResNameKxCluster, d.Id(), err)...)
}
}

if !updateCode && !updateDb {
return diags
}
return append(diags, resourceKxClusterRead(ctx, d, meta)...)
}

Expand Down Expand Up @@ -585,6 +632,24 @@ func waitKxClusterCreated(ctx context.Context, conn *finspace.Client, id string,
return nil, err
}

func waitKxClusterUpdated(ctx context.Context, conn *finspace.Client, id string, timeout time.Duration) (*finspace.GetKxClusterOutput, error) { //nolint:unparam
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(types.KxClusterStatusPending, types.KxClusterStatusUpdating),
Target: enum.Slice(types.KxClusterStatusRunning),
Refresh: statusKxCluster(ctx, conn, id),
Timeout: timeout,
NotFoundChecks: 20,
ContinuousTargetOccurence: 2,
}

outputRaw, err := stateConf.WaitForStateContext(ctx)
if out, ok := outputRaw.(*finspace.GetKxClusterOutput); ok {
return out, err
}

return nil, err
}

func waitKxClusterDeleted(ctx context.Context, conn *finspace.Client, id string, timeout time.Duration) (*finspace.GetKxClusterOutput, error) {
stateConf := &retry.StateChangeConf{
Pending: enum.Slice(types.KxClusterStatusDeleting),
Expand Down
Loading
Loading