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:
João Palet 2025-01-20 08:54:30 +00:00 committed by GitHub
parent fc805d8e1d
commit 1a66887c01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 438 additions and 15 deletions

View file

@ -32,6 +32,7 @@ import (
"github.com/stackitcloud/stackit-sdk-go/services/observability/wait"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/conversion"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
argusScrapeConfigResource "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/argus/scrapeconfig"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
)
@ -48,6 +49,7 @@ var (
_ resource.Resource = &scrapeConfigResource{}
_ resource.ResourceWithConfigure = &scrapeConfigResource{}
_ resource.ResourceWithImportState = &scrapeConfigResource{}
_ resource.ResourceWithMoveState = &scrapeConfigResource{}
)
type Model struct {
@ -149,6 +151,47 @@ func (r *scrapeConfigResource) Configure(ctx context.Context, req resource.Confi
tflog.Info(ctx, "Observability scrape config client configured")
}
func (r *scrapeConfigResource) MoveState(_ context.Context) []resource.StateMover {
return []resource.StateMover{
{
SourceSchema: &argusScrapeConfigResource.Schema,
StateMover: func(ctx context.Context, req resource.MoveStateRequest, resp *resource.MoveStateResponse) {
if req.SourceTypeName != "stackit_argus_scrapeconfig" {
return
}
// Checks source provider
if !strings.HasSuffix(req.SourceProviderAddress, "stackitcloud/stackit") {
return
}
var sourceStateData argusScrapeConfigResource.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,
Name: sourceStateData.Name,
MetricsPath: sourceStateData.MetricsPath,
Scheme: sourceStateData.Scheme,
ScrapeInterval: sourceStateData.ScrapeInterval,
ScrapeTimeout: sourceStateData.ScrapeTimeout,
SampleLimit: sourceStateData.SampleLimit,
SAML2: sourceStateData.SAML2,
BasicAuth: sourceStateData.BasicAuth,
Targets: sourceStateData.Targets,
}
resp.Diagnostics.Append(resp.TargetState.Set(ctx, targetStateData)...)
},
},
}
}
// Schema defines the schema for the resource.
func (r *scrapeConfigResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{