-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Implements extra API Calls for AdvancedCluster TPF #2852
Changes from all commits
22a1cfb
7dd94e0
c4ef033
91134ff
f29a751
9f14110
8329f46
d7f2c89
e219aae
f0603cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
package constant | ||
|
||
const ( | ||
AWS = "AWS" | ||
AZURE = "AZURE" | ||
GCP = "GCP" | ||
AWS = "AWS" | ||
AZURE = "AZURE" | ||
GCP = "GCP" | ||
TENANT = "TENANT" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,7 +101,24 @@ func (r *rs) Update(ctx context.Context, req resource.UpdateRequest, resp *resou | |
if diags.HasError() { | ||
return | ||
} | ||
cluster := r.applyClusterChanges(ctx, diags, &state, &plan) | ||
stateReq := normalizeFromTFModel(ctx, &state, diags, false) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactored some applyClusterChanges logic here, to have the distinction between tenantUpgrade/ClusterChanges more clear |
||
planReq := normalizeFromTFModel(ctx, &plan, diags, false) | ||
if diags.HasError() { | ||
return | ||
} | ||
normalizePatchState(stateReq) | ||
patchReq, err := update.PatchPayload(stateReq, planReq) | ||
if err != nil { | ||
diags.AddError("errorPatchPayload", err.Error()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more human-friendly summary There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will handle as part of next ticket |
||
return | ||
} | ||
upgradeRequest := getTenantUpgradeRequest(stateReq, patchReq) | ||
var cluster *admin.ClusterDescription20240805 | ||
if upgradeRequest != nil { | ||
cluster = r.applyTenantUpgrade(ctx, &plan, upgradeRequest, diags) | ||
} else { | ||
cluster = r.applyClusterChanges(ctx, diags, &state, &plan, patchReq) | ||
} | ||
if diags.HasError() { | ||
return | ||
} | ||
|
@@ -233,18 +250,7 @@ func (r *rs) applyAdvancedConfigurationChanges(ctx context.Context, diags *diag. | |
return legacyAdvConfig, advConfig | ||
} | ||
|
||
func (r *rs) applyClusterChanges(ctx context.Context, diags *diag.Diagnostics, state, plan *TFModel) *admin.ClusterDescription20240805 { | ||
stateReq := normalizeFromTFModel(ctx, state, diags, false) | ||
planReq := normalizeFromTFModel(ctx, plan, diags, false) | ||
if diags.HasError() { | ||
return nil | ||
} | ||
normalizePatchState(stateReq) | ||
patchReq, err := update.PatchPayload(stateReq, planReq) | ||
if err != nil { | ||
diags.AddError("errorPatchPayload", err.Error()) | ||
return nil | ||
} | ||
func (r *rs) applyClusterChanges(ctx context.Context, diags *diag.Diagnostics, state, plan *TFModel, patchReq *admin.ClusterDescription20240805) *admin.ClusterDescription20240805 { | ||
var cluster *admin.ClusterDescription20240805 | ||
if usingLegacySchema(ctx, plan.ReplicationSpecs, diags) { | ||
// Only updates of replication specs will be done with legacy API | ||
|
@@ -344,6 +350,19 @@ func (r *rs) updateAndWaitLegacy(ctx context.Context, patchReq *admin20240805.Cl | |
return AwaitChanges(ctx, r.Client.AtlasV2.ClustersApi, &tfModel.Timeouts, diags, projectID, clusterName, changeReasonUpdate) | ||
} | ||
|
||
func (r *rs) applyTenantUpgrade(ctx context.Context, plan *TFModel, upgradeRequest *admin.LegacyAtlasTenantClusterUpgradeRequest, diags *diag.Diagnostics) *admin.ClusterDescription20240805 { | ||
api := r.Client.AtlasV2.ClustersApi | ||
oarbusi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
projectID := plan.ProjectID.ValueString() | ||
clusterName := plan.Name.ValueString() | ||
upgradeRequest.Name = clusterName | ||
_, _, err := api.UpgradeSharedCluster(ctx, projectID, upgradeRequest).Execute() | ||
if err != nil { | ||
diags.AddError("errorTenantUpgrade", fmt.Sprintf(errorUpdate, clusterName, err.Error())) | ||
return nil | ||
} | ||
return AwaitChanges(ctx, api, &plan.Timeouts, diags, projectID, clusterName, changeReasonUpdate) | ||
} | ||
|
||
func (r *rs) convertClusterAddAdvConfig(ctx context.Context, legacyAdvConfig *admin20240530.ClusterDescriptionProcessArgs, advConfig *admin.ClusterDescriptionProcessArgs20240805, cluster *admin.ClusterDescription20240805, modelIn *TFModel, diags *diag.Diagnostics) *TFModel { | ||
api := r.Client.AtlasV2.ClustersApi | ||
api20240530 := r.Client.AtlasV220240530.ClustersApi | ||
|
@@ -365,7 +384,12 @@ func (r *rs) convertClusterAddAdvConfig(ctx context.Context, legacyAdvConfig *ad | |
} | ||
} | ||
legacyInfo := resolveLegacyInfo(ctx, modelIn, diags, cluster, api20240530) | ||
modelOut := NewTFModel(ctx, cluster, modelIn.Timeouts, diags, legacyInfo) | ||
apiInfo, err := resolveExtraAPIInfo(ctx, projectID, cluster, r.Client.AtlasV2.NetworkPeeringApi) | ||
if err != nil { | ||
diags.AddError("errorExtraApiInfo", err.Error()) | ||
return nil | ||
} | ||
modelOut := NewTFModel(ctx, cluster, modelIn.Timeouts, diags, legacyInfo, *apiInfo) | ||
if diags.HasError() { | ||
return nil | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ import ( | |
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setdefault" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes to the
|
||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" | ||
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/schemafunc" | ||
|
@@ -128,10 +127,7 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |
}, | ||
}, | ||
"create_date": schema.StringAttribute{ | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it makes sense to remove |
||
}, | ||
Computed: true, | ||
MarkdownDescription: "Date and time when MongoDB Cloud created this cluster. This parameter expresses its value in ISO 8601 format in UTC.", | ||
}, | ||
"encryption_at_rest_provider": schema.StringAttribute{ | ||
|
@@ -149,10 +145,7 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies your project. Use the [/groups](#tag/Projects/operation/listProjects) endpoint to retrieve all projects to which the authenticated user has access.\n\n**NOTE**: Groups and projects are synonymous terms. Your group id is the same as your project id. For existing groups, your group/project id remains the same. The resource and corresponding endpoints use the term groups.", | ||
}, | ||
"cluster_id": schema.StringAttribute{ // TODO: was generated as id | ||
EspenAlbert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), | ||
}, | ||
Computed: true, | ||
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the cluster.", | ||
}, | ||
"labels": schema.SetNestedAttribute{ | ||
|
@@ -276,9 +269,8 @@ func ResourceSchema(ctx context.Context) schema.Schema { | |
MarkdownDescription: "Unique 24-hexadecimal digit string that identifies the zone in a Global Cluster. This value can be used to configure Global Cluster backup policies.", | ||
}, | ||
"zone_name": schema.StringAttribute{ | ||
Computed: true, // must be computed to have a Default | ||
Computed: true, | ||
Optional: true, | ||
Default: stringdefault.StaticString("ZoneName managed by Terraform"), // TODO: as in current resource | ||
MarkdownDescription: "Human-readable label that describes the zone this shard belongs to in a Global Cluster. Provide this value only if \"clusterType\" : \"GEOSHARDED\" but not \"selfManagedSharding\" : true.", | ||
}, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although we could define only
containerIDs map[string]string
as a parameter, I think this is more "future-proof".(Couldn't use LegacySchemaInfo, as that is only meant for numShards > 1 configurations)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have mixed feelings about anticipating future needs as it can create overcomplexity but it's ok here.