From 5da4372f67857e832acf4b890d1d4c570b01623f Mon Sep 17 00:00:00 2001 From: David Bloss Date: Thu, 21 Nov 2024 08:15:07 -0600 Subject: [PATCH 1/2] note field on service_dependency correctly takes empty string --- .changes/unreleased/Bugfix-20241121-081407.yaml | 3 +++ opslevel/resource_opslevel_service_dependency.go | 11 +++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changes/unreleased/Bugfix-20241121-081407.yaml diff --git a/.changes/unreleased/Bugfix-20241121-081407.yaml b/.changes/unreleased/Bugfix-20241121-081407.yaml new file mode 100644 index 00000000..c83f4faf --- /dev/null +++ b/.changes/unreleased/Bugfix-20241121-081407.yaml @@ -0,0 +1,3 @@ +kind: Bugfix +body: '"note" field on service_dependency correctly takes empty string' +time: 2024-11-21T08:14:07.471282-06:00 diff --git a/opslevel/resource_opslevel_service_dependency.go b/opslevel/resource_opslevel_service_dependency.go index ace7fbcb..81ce5df3 100644 --- a/opslevel/resource_opslevel_service_dependency.go +++ b/opslevel/resource_opslevel_service_dependency.go @@ -117,13 +117,16 @@ func (r *ServiceDependencyResource) Create(ctx context.Context, req resource.Cre return } - serviceDependency, err := r.client.CreateServiceDependency(opslevel.ServiceDependencyCreateInput{ + serviceDependencyCreateInput := opslevel.ServiceDependencyCreateInput{ DependencyKey: opslevel.ServiceDependencyKey{ DestinationIdentifier: opslevel.NewIdentifier(planModel.DependsUpon.ValueString()), SourceIdentifier: opslevel.NewIdentifier(planModel.Service.ValueString()), }, - Notes: planModel.Note.ValueStringPointer(), - }) + } + if !planModel.Note.IsNull() && !planModel.Note.IsUnknown() { + serviceDependencyCreateInput.Notes = planModel.Note.ValueStringPointer() + } + serviceDependency, err := r.client.CreateServiceDependency(serviceDependencyCreateInput) if err != nil || serviceDependency == nil { resp.Diagnostics.AddError("opslevel client error", fmt.Sprintf("Unable to create serviceDependency, got error: %s", err)) return @@ -200,7 +203,7 @@ func extractServiceDependency(id string, serviceDependencies opslevel.ServiceDep func (r *ServiceDependencyResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { resp.Diagnostics.AddError("terraform plugin error", - "property assignments should never be updated, only replaced.\nplease file a bug report including your .tf file at: github.com/OpsLevel/terraform-provider-opslevel") + "service dependencies should never be updated, only replaced.\nplease file a bug report including your .tf file at: github.com/OpsLevel/terraform-provider-opslevel") } func (r *ServiceDependencyResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { From f156edb31151ce29789d813c5d0ae6c384bae7bd Mon Sep 17 00:00:00 2001 From: David Bloss Date: Mon, 25 Nov 2024 10:25:20 -0600 Subject: [PATCH 2/2] update submodules and service_dependency test --- submodules/opslevel-go | 2 +- tests/opslevel_modules | 2 +- tests/service_dependency.tftest.hcl | 11 ++++++++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/submodules/opslevel-go b/submodules/opslevel-go index eae2d575..46f295bb 160000 --- a/submodules/opslevel-go +++ b/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit eae2d575f301097bee0e39d0ac1579536346db77 +Subproject commit 46f295bb05a397b0516b2f01d4b5c2d5814355d6 diff --git a/tests/opslevel_modules b/tests/opslevel_modules index 5f465503..2e324c9b 160000 --- a/tests/opslevel_modules +++ b/tests/opslevel_modules @@ -1 +1 @@ -Subproject commit 5f4655030cd0542546e761c9f49477283384ee59 +Subproject commit 2e324c9b86182d69b0de279ef27cdf2703b0a110 diff --git a/tests/service_dependency.tftest.hcl b/tests/service_dependency.tftest.hcl index 0b7d3b3c..9ee057b5 100644 --- a/tests/service_dependency.tftest.hcl +++ b/tests/service_dependency.tftest.hcl @@ -73,7 +73,7 @@ run "resource_service_dependency_create_with_service_id" { } -run "resource_service_dependency_update_unset_optional_fields" { +run "resource_service_dependency_update_does_force_recreate" { variables { depends_upon = run.from_service_module.all.services[0].id @@ -81,6 +81,15 @@ run "resource_service_dependency_update_unset_optional_fields" { note = null } + assert { + condition = run.resource_service_dependency_create_with_service_id.this.id != opslevel_service_dependency.this.id + error_message = format( + "expected old id '%v' to be different from new id '%v'", + run.resource_service_dependency_create_with_service_id.this.id, + opslevel_service_dependency.this.id, + ) + } + module { source = "./opslevel_modules/modules/service/dependency" }