Skip to content

Commit

Permalink
Merge pull request #117 from Scalingo/fix/116/app-stack-id
Browse files Browse the repository at this point in the history
resource(app) Correctly handle stack change by modifying 'stack_id' field, add extra logging also
  • Loading branch information
Soulou authored Jan 23, 2023
2 parents 4f06fad + 55be922 commit 1c3aea5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
16 changes: 8 additions & 8 deletions scalingo/data_scalingo_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package scalingo

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand Down Expand Up @@ -35,11 +37,6 @@ func dataSourceScStack() *schema.Resource {
Computed: true,
Description: "Is it the current default stack?",
},
"id": {
Type: schema.TypeString,
Computed: true,
Description: "ID of the stack",
},
"deprecated_at": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -75,13 +72,16 @@ func dataSourceScStackRead(ctx context.Context, d *schema.ResourceData, meta int
return diag.Errorf("fail to find stack with name '%s'", name)
}

d.SetId(selected.ID)
err = SetAll(d, map[string]interface{}{
stackFields := map[string]interface{}{
"name": selected.Name,
"description": selected.Description,
"base_image": selected.BaseImage,
"default": selected.Default,
})
}
tflog.Info(ctx, fmt.Sprintf("Fetched stack '%v' with ID %v", name, selected.ID), stackFields)

d.SetId(selected.ID)
err = SetAll(d, stackFields)
if err != nil {
return diag.Errorf("fail to save stack information: %v", err)
}
Expand Down
18 changes: 9 additions & 9 deletions scalingo/resource_scalingo_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

Expand Down Expand Up @@ -54,15 +55,9 @@ func resourceScalingoApp() *schema.Resource {
Type: schema.TypeString,
// Either set by the user, either set automatically by server if
// no value is provided
Optional: true,
Computed: true,
DiffSuppressFunc: func(k, oldValue, newValue string, d *schema.ResourceData) bool {
if newValue == "" {
return true
}
return true
},
Description: "ID of the base stack to use (scalingo-18/scalingo-20)",
Optional: true,
Computed: true,
Description: "ID of the base stack to use (scalingo-18/scalingo-20/scalingo-22)",
},
},

Expand All @@ -86,6 +81,10 @@ func resourceAppCreate(ctx context.Context, d *schema.ResourceData, meta interfa
createOpts.StackID = stackID
}

tflog.Info(ctx, "Creating Scalingo application", map[string]interface{}{
"name": createOpts.Name,
"stack_id": createOpts.StackID,
})
app, err := client.AppsCreate(ctx, createOpts)
if err != nil {
return diag.Errorf("fail to create app: %v", err)
Expand All @@ -97,6 +96,7 @@ func resourceAppCreate(ctx context.Context, d *schema.ResourceData, meta interfa
"git_url": app.GitURL,
"stack_id": app.StackID,
})

if err != nil {
return diag.Errorf("fail to store application attributes: %v", err)
}
Expand Down

0 comments on commit 1c3aea5

Please sign in to comment.