-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SCALRCORE-26654 Provider > Migrate scalr_tag resource and datasource (#…
…365) * SCALRCORE-26653 Introduce internal packages * SCALRCORE-26653 Implement provider server muxing * SCALRCORE-26653 Resolve conflicts * SCALRCORE-26653 CI: bump Go to 1.23 * SCALRCORE-26653 CI: bump golangci-lint * SCALRCORE-26653 Remove deprecated rand.Seed calls * SCALRCORE-26653 Doc formatting * SCALRCORE-26653 Fix goveralls CI step * SCALRCORE-26654 Move existing provider modules to internal/provider package * SCALRCORE-26654 Move existing provider modules to internal/provider package * SCALRCORE-26654 Inject version in SDK provider * SCALRCORE-26654 Fix refactoring typos * SCALRCORE-26654 Get rid of terraform-plugin-sdk logging package in http client * SCALRCORE-26654 Rename datasource files * SCALRCORE-26654 Add tag datasource; replace SDK imports in test modules with framework substitutes * SCALRCORE-26654 * wip * SCALRCORE-26654 * wip * SCALRCORE-26654 * wip * SCALRCORE-26654 * wip - preserve file move history * SCALRCORE-26654 Replace legacy pointer fns with generic ptr() * SCALRCORE-26654 Add tag resource * SCALRCORE-26654 Add tag resource * SCALRCORE-26654 Fix linter * SCALRCORE-26654 Implement skaffolding generator * SCALRCORE-26654 Add skaff readme * SCALRCORE-26654 Add sdk->framework upgrade tests
- Loading branch information
1 parent
92e388f
commit 002158c
Showing
141 changed files
with
2,448 additions
and
1,847 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
|
||
"github.com/scalr/go-scalr" | ||
) | ||
|
||
type DataSourceWithScalrClient struct { | ||
Client *scalr.Client | ||
} | ||
|
||
func (d *DataSourceWithScalrClient) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
c, ok := req.ProviderData.(*scalr.Client) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Data Source Configure Type", | ||
fmt.Sprintf("Expected *scalr.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
d.Client = c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package defaults | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/defaults" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
) | ||
|
||
const CurrentAccountIDEnvVar = "SCALR_ACCOUNT_ID" | ||
|
||
func GetDefaultScalrAccountID() (string, diag.Diagnostics) { | ||
var diags diag.Diagnostics | ||
v := os.Getenv(CurrentAccountIDEnvVar) | ||
if v == "" { | ||
diags.AddError( | ||
"Cannot infer current account", | ||
fmt.Sprintf( | ||
"Default value for `account_id` could not be computed."+ | ||
"\nIf you are using Scalr Provider for local runs, please set the attribute in resources explicitly,"+ | ||
"\nor export `%s` environment variable prior the run.", | ||
CurrentAccountIDEnvVar, | ||
), | ||
) | ||
} | ||
return v, diags | ||
} | ||
|
||
// AccountIDRequired returns a default account id value handler. | ||
// | ||
// Use AccountIDRequired when a default value for account id must be set. | ||
func AccountIDRequired() defaults.String { | ||
return accountIDRequiredDefault{} | ||
} | ||
|
||
// accountIDRequiredDefault implements defaults.String | ||
type accountIDRequiredDefault struct{} | ||
|
||
func (r accountIDRequiredDefault) Description(_ context.Context) string { | ||
return "value defaults to current Scalr account id" | ||
} | ||
|
||
func (r accountIDRequiredDefault) MarkdownDescription(ctx context.Context) string { | ||
return r.Description(ctx) | ||
} | ||
|
||
func (r accountIDRequiredDefault) DefaultString(_ context.Context, _ defaults.StringRequest, resp *defaults.StringResponse) { | ||
s, diags := GetDefaultScalrAccountID() | ||
resp.Diagnostics.Append(diags...) | ||
resp.PlanValue = types.StringValue(s) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package framework | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/resource" | ||
|
||
"github.com/scalr/go-scalr" | ||
) | ||
|
||
type ResourceWithScalrClient struct { | ||
Client *scalr.Client | ||
} | ||
|
||
func (r *ResourceWithScalrClient) Configure(_ context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
c, ok := req.ProviderData.(*scalr.Client) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Resource Configure Type", | ||
fmt.Sprintf("Expected *scalr.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
|
||
return | ||
} | ||
|
||
r.Client = c | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag" | ||
"github.com/hashicorp/terraform-plugin-framework/schema/validator" | ||
) | ||
|
||
// Compile-time interface check | ||
var _ validator.String = stringIsNotWhiteSpaceValidator{} | ||
|
||
type stringIsNotWhiteSpaceValidator struct{} | ||
|
||
func (v stringIsNotWhiteSpaceValidator) Description(_ context.Context) string { | ||
return "must not be empty or consisting entirely of whitespace characters" | ||
} | ||
|
||
func (v stringIsNotWhiteSpaceValidator) MarkdownDescription(ctx context.Context) string { | ||
return v.Description(ctx) | ||
} | ||
|
||
func (v stringIsNotWhiteSpaceValidator) ValidateString(ctx context.Context, req validator.StringRequest, resp *validator.StringResponse) { | ||
if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() { | ||
return | ||
} | ||
|
||
value := req.ConfigValue.ValueString() | ||
|
||
if strings.TrimSpace(value) == "" { | ||
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic( | ||
req.Path, | ||
v.Description(ctx), | ||
fmt.Sprintf("%q", value), | ||
)) | ||
|
||
return | ||
} | ||
} | ||
|
||
func StringIsNotWhiteSpace() validator.String { | ||
return stringIsNotWhiteSpaceValidator{} | ||
} |
Oops, something went wrong.