feat: Allow move state on new Observability resources (#593)
* feat: Allow move state on new Observability resources * Extend description to explain how to move a argus resource to observability * Update argus docs with examples how to move a resource to observability --------- Co-authored-by: Marcel Jacek <Marcel.Jacek@stackit.cloud>
This commit is contained in:
parent
fc805d8e1d
commit
1a66887c01
12 changed files with 438 additions and 15 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
|
||||
"github.com/stackitcloud/stackit-sdk-go/services/observability"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
|
||||
argusCredentialResource "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/argus/credential"
|
||||
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
|
||||
)
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ import (
|
|||
var (
|
||||
_ resource.Resource = &credentialResource{}
|
||||
_ resource.ResourceWithConfigure = &credentialResource{}
|
||||
_ resource.ResourceWithMoveState = &credentialResource{}
|
||||
)
|
||||
|
||||
type Model struct {
|
||||
|
|
@ -86,6 +88,40 @@ func (r *credentialResource) Configure(ctx context.Context, req resource.Configu
|
|||
tflog.Info(ctx, "Observability credential client configured")
|
||||
}
|
||||
|
||||
func (r *credentialResource) MoveState(_ context.Context) []resource.StateMover {
|
||||
return []resource.StateMover{
|
||||
{
|
||||
SourceSchema: &argusCredentialResource.Schema,
|
||||
StateMover: func(ctx context.Context, req resource.MoveStateRequest, resp *resource.MoveStateResponse) {
|
||||
if req.SourceTypeName != "stackit_argus_credential" {
|
||||
return
|
||||
}
|
||||
|
||||
// Checks source provider
|
||||
if !strings.HasSuffix(req.SourceProviderAddress, "stackitcloud/stackit") {
|
||||
return
|
||||
}
|
||||
|
||||
var sourceStateData argusCredentialResource.Model
|
||||
resp.Diagnostics.Append(req.SourceState.Get(ctx, &sourceStateData)...)
|
||||
if resp.Diagnostics.HasError() {
|
||||
return
|
||||
}
|
||||
|
||||
targetStateData := Model{
|
||||
Id: sourceStateData.Id,
|
||||
ProjectId: sourceStateData.ProjectId,
|
||||
InstanceId: sourceStateData.InstanceId,
|
||||
Username: sourceStateData.Username,
|
||||
Password: sourceStateData.Password,
|
||||
}
|
||||
|
||||
resp.Diagnostics.Append(resp.TargetState.Set(ctx, targetStateData)...)
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *credentialResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
|
||||
resp.Schema = schema.Schema{
|
||||
Description: "Observability credential resource schema. Must have a `region` specified in the provider configuration.",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue