Skip to content

Commit

Permalink
fix bugs persistenceSettings versioningStrategy connectivityPolicy no…
Browse files Browse the repository at this point in the history
…t return from API
  • Loading branch information
HuyPhanNguyen committed Jul 30, 2024
1 parent 054be94 commit 7a11f03
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions octopusdeploy_framework/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
}

project := expandProject(ctx, plan)
// Following value not return after create project or getById so need to save here and add back to stage later
persistenceSettings := project.PersistenceSettings
versioningStrategy := project.VersioningStrategy
connectivityPolicy := project.ConnectivityPolicy
createdProject, err := projects.Add(r.Client, project)

if err != nil {
resp.Diagnostics.AddError("Error creating project", err.Error())
return
Expand Down Expand Up @@ -70,6 +73,10 @@ func (r *projectResource) Create(ctx context.Context, req resource.CreateRequest
createdProject.VersioningStrategy = versioningStrategy
}

if connectivityPolicy != nil {
createdProject.ConnectivityPolicy = connectivityPolicy
}

flattenedProject, diags := flattenProject(ctx, createdProject, &plan)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
Expand All @@ -88,11 +95,26 @@ func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, re
return
}

stateProject := expandProject(ctx, state)
// Following value not return after create project or getById so need to save here and add back to stage later
persistenceSettings := stateProject.PersistenceSettings
versioningStrategy := stateProject.VersioningStrategy
connectivityPolicy := stateProject.ConnectivityPolicy

project, err := projects.GetByID(r.Client, state.SpaceID.ValueString(), state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("Error reading project", err.Error())
return
}
if persistenceSettings != nil {
project.PersistenceSettings = persistenceSettings
}
if versioningStrategy != nil {
project.VersioningStrategy = versioningStrategy
}
if connectivityPolicy != nil {
project.ConnectivityPolicy = connectivityPolicy
}

flattenedProject, diags := flattenProject(ctx, project, &state)
resp.Diagnostics.Append(diags...)
Expand Down Expand Up @@ -120,6 +142,10 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
updatedProject := expandProject(ctx, plan)
updatedProject.ID = existingProject.ID
updatedProject.Links = existingProject.Links
// Following value not return after create project or getById so need to save here and add back to stage later
persistenceSettings := updatedProject.PersistenceSettings
versioningStrategy := updatedProject.VersioningStrategy
connectivityPolicy := updatedProject.ConnectivityPolicy

if updatedProject.PersistenceSettings != nil && updatedProject.PersistenceSettings.Type() == projects.PersistenceSettingsTypeVersionControlled {
if existingProject.PersistenceSettings == nil || existingProject.PersistenceSettings.Type() != projects.PersistenceSettingsTypeVersionControlled {
Expand All @@ -137,6 +163,15 @@ func (r *projectResource) Update(ctx context.Context, req resource.UpdateRequest
resp.Diagnostics.AddError("Error updating project", err.Error())
return
}
if persistenceSettings != nil {
updatedProject.PersistenceSettings = persistenceSettings
}
if versioningStrategy != nil {
updatedProject.VersioningStrategy = versioningStrategy
}
if connectivityPolicy != nil {
updatedProject.ConnectivityPolicy = connectivityPolicy
}

flattenedProject, diags := flattenProject(ctx, updatedProject, &plan)
resp.Diagnostics.Append(diags...)
Expand Down

0 comments on commit 7a11f03

Please sign in to comment.