From ae1e34e923c8fce1dce2f65baabac3737366d1a0 Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Thu, 20 Apr 2023 14:45:18 +0700 Subject: [PATCH] resource/migration: fixed version warning when no change (#63) --- internal/provider/atlas_migration_data_source.go | 4 ++-- internal/provider/atlas_migration_data_source_test.go | 2 +- internal/provider/atlas_migration_resource.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/provider/atlas_migration_data_source.go b/internal/provider/atlas_migration_data_source.go index 702a755..63bdeae 100644 --- a/internal/provider/atlas_migration_data_source.go +++ b/internal/provider/atlas_migration_data_source.go @@ -123,12 +123,12 @@ func (d *MigrationDataSource) Read(ctx context.Context, req datasource.ReadReque } data.Status = types.String{Value: r.Status} if r.Status == "PENDING" && r.Current == noMigration { - data.Current = types.String{Null: true} + data.Current = types.String{Value: ""} } else { data.Current = types.String{Value: r.Current} } if r.Status == "OK" && r.Next == latestVersion { - data.Next = types.String{Null: true} + data.Next = types.String{Value: ""} } else { data.Next = types.String{Value: r.Next} } diff --git a/internal/provider/atlas_migration_data_source_test.go b/internal/provider/atlas_migration_data_source_test.go index 675a68c..df9ac98 100644 --- a/internal/provider/atlas_migration_data_source_test.go +++ b/internal/provider/atlas_migration_data_source_test.go @@ -25,7 +25,7 @@ func TestAccMigrationDataSource(t *testing.T) { Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("data.atlas_migration.hello", "id", "migrations?format=atlas"), resource.TestCheckResourceAttr("data.atlas_migration.hello", "status", "PENDING"), - resource.TestCheckNoResourceAttr("data.atlas_migration.hello", "current"), + resource.TestCheckResourceAttr("data.atlas_migration.hello", "current", ""), resource.TestCheckResourceAttr("data.atlas_migration.hello", "next", "20221101163823"), resource.TestCheckResourceAttr("data.atlas_migration.hello", "latest", "20221101165415"), ), diff --git a/internal/provider/atlas_migration_resource.go b/internal/provider/atlas_migration_resource.go index ca1e230..a283735 100644 --- a/internal/provider/atlas_migration_resource.go +++ b/internal/provider/atlas_migration_resource.go @@ -187,7 +187,7 @@ func (r MigrationResource) ValidateConfig(ctx context.Context, req resource.Vali return } resp.Diagnostics.Append(r.validateConfig(ctx, req.Config)...) - if !data.Version.IsUnknown() && data.Version.Value == "" { + if data.Version.IsNull() { resp.Diagnostics.AddAttributeWarning( path.Root("version"), "version is unset", @@ -224,7 +224,7 @@ func (r *MigrationResource) ModifyPlan(ctx context.Context, req resource.ModifyP resp.Diagnostics.Append(atlas.ErrorDiagnostic(err, "Failed to read migration status")) return } - if plan.Version.IsNull() { + if plan.Version.Value == "" { v := report.LatestVersion() plan.Version = types.String{Value: v, Null: v == ""} }