Skip to content

Commit 24c0163

Browse files
committed
work
1 parent 7bd4eb3 commit 24c0163

13 files changed

+122
-93
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,4 @@ require (
103103
gopkg.in/yaml.v3 v3.0.1 // indirect
104104
)
105105

106-
replace github.com/datastax/astra-client-go/v2 => github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251014131947-9665c4fa0857
106+
replace github.com/datastax/astra-client-go/v2 => github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251021175718-3845575ecf48

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN
8181
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
8282
github.com/aws/aws-sdk-go v1.38.67 h1:OCeXMKiiM8X7HAKPCE5yD+t+sEsRaj8EwDs2tlgvX2c=
8383
github.com/aws/aws-sdk-go v1.38.67/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
84-
github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251014131947-9665c4fa0857 h1:isVQFmmNsi+zo0FPGiKugP7QPXfe8JIi64XYEYUH0CQ=
85-
github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251014131947-9665c4fa0857/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
84+
github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251021175718-3845575ecf48 h1:PtyhHp3Lsq5BKgCp7j/Ns78sFzLt2mdKq9wyyS21MBI=
85+
github.com/bdunn313/astra-client-go/v2 v2.2.64-0.20251021175718-3845575ecf48/go.mod h1:piBMy3fnDcLN8+MDQfvjZr8ejcP2oh+CXkQYwNy8blA=
8686
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
8787
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
8888
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=

internal/provider/data_source_access_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func listAccessList(ctx context.Context, client *astra.ClientWithResponses, data
9595
}
9696

9797
// If the database is terminated then the access list has been deleted.
98-
if db.Status == astra.StatusEnumTERMINATING || db.Status == astra.StatusEnumTERMINATED {
98+
if db.Status == astra.TERMINATING || db.Status == astra.TERMINATED {
9999
return nil, nil
100100
}
101101

internal/provider/data_source_keyspaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func listKeyspaces(ctx context.Context, client *astra.ClientWithResponses, datab
7575
}
7676

7777
// If the database is terminated then the keyspaces have been deleted.
78-
if db.Status == astra.StatusEnumTERMINATING || db.Status == astra.StatusEnumTERMINATED {
78+
if db.Status == astra.TERMINATING || db.Status == astra.TERMINATED {
7979
return nil, nil
8080
}
8181

internal/provider/data_source_private_link_endpoints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func listPrivateLinkEndpoints(ctx context.Context, client *astra.ClientWithRespo
108108
}
109109

110110
// If the database is terminated then the private links have been deleted.
111-
if db.Status == astra.StatusEnumTERMINATING || db.Status == astra.StatusEnumTERMINATED {
111+
if db.Status == astra.TERMINATING || db.Status == astra.TERMINATED {
112112
return nil, nil
113113
}
114114

internal/provider/data_source_private_links.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func listPrivateLinks(ctx context.Context, client *astra.ClientWithResponses, da
109109
}
110110

111111
// If the database is terminated then the private links have been deleted.
112-
if db.Status == astra.StatusEnumTERMINATING || db.Status == astra.StatusEnumTERMINATED {
112+
if db.Status == astra.TERMINATING || db.Status == astra.TERMINATED {
113113
return nil, nil
114114
}
115115

internal/provider/resource_cdc_v3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,10 @@ func waitForDatabaseActive(ctx context.Context, client *astra.ClientWithResponse
444444
// Success fetching database
445445
dbStatus := res.JSON200.Status
446446
switch dbStatus {
447-
case astra.StatusEnumERROR, astra.StatusEnumTERMINATED, astra.StatusEnumTERMINATING:
447+
case astra.ERROR, astra.TERMINATED, astra.TERMINATING:
448448
// If the database reached a terminal state it will never become active
449449
return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status='%s'", dbStatus))
450-
case astra.StatusEnumACTIVE:
450+
case astra.ACTIVE:
451451
return nil
452452
default:
453453
return retry.RetryableError(fmt.Errorf("waiting database to be active but is '%s'", dbStatus))

internal/provider/resource_database.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ func resourceDatabaseRead(ctx context.Context, resourceData *schema.ResourceData
265265
}
266266

267267
// If the database is TERMINATING or TERMINATED then remove it from the state
268-
if db.Status == astra.StatusEnumTERMINATING || db.Status == astra.StatusEnumTERMINATED {
268+
if db.Status == astra.TERMINATING || db.Status == astra.TERMINATED {
269269
resourceData.SetId("")
270270
return nil
271271
}
@@ -369,7 +369,7 @@ func resourceDatabaseDelete(ctx context.Context, resourceData *schema.ResourceDa
369369

370370
// Return when the database is in a TERMINATED state
371371
db := res.JSON200
372-
if db.Status == astra.StatusEnumTERMINATED {
372+
if db.Status == astra.TERMINATED {
373373
return nil
374374
}
375375

@@ -524,10 +524,10 @@ func waitForDatabaseAndUpdateResource(ctx context.Context, resourceData *schema.
524524
// Success fetching database
525525
db := res.JSON200
526526
switch db.Status {
527-
case astra.StatusEnumERROR, astra.StatusEnumTERMINATED, astra.StatusEnumTERMINATING:
527+
case astra.ERROR, astra.TERMINATED, astra.TERMINATING:
528528
// If the database reached a terminal state it will never become active
529529
return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status=%s", db.Status))
530-
case astra.StatusEnumACTIVE:
530+
case astra.ACTIVE:
531531
if err := setDatabaseResourceData(resourceData, db); err != nil {
532532
return retry.NonRetryableError(err)
533533
}

internal/provider/resource_keyspace.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ func resourceKeyspaceCreate(ctx context.Context, d *schema.ResourceData, meta in
7777
// Success fetching database
7878
db := res.JSON200
7979
switch db.Status {
80-
case astra.StatusEnumERROR, astra.StatusEnumTERMINATED, astra.StatusEnumTERMINATING:
80+
case astra.ERROR, astra.TERMINATED, astra.TERMINATING:
8181
// If the database reached a terminal state it will never become active
8282
return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status=%s", db.Status))
83-
case astra.StatusEnumACTIVE:
83+
case astra.ACTIVE:
8484
keyspaceMutex.Lock()
8585
resp, err := client.AddKeyspaceWithResponse(ctx, astra.DatabaseIdParam(databaseID), astra.KeyspaceNameParam(keyspaceName))
8686
keyspaceMutex.Unlock()
@@ -169,10 +169,10 @@ func resourceKeyspaceDelete(ctx context.Context, d *schema.ResourceData, meta in
169169
// Success fetching database
170170
db := res.JSON200
171171
switch db.Status {
172-
case astra.StatusEnumERROR, astra.StatusEnumTERMINATED, astra.StatusEnumTERMINATING:
172+
case astra.ERROR, astra.TERMINATED, astra.TERMINATING:
173173
// If the database reached a terminal state it will never become active
174174
return retry.NonRetryableError(fmt.Errorf("database failed to reach active status: status=%s", db.Status))
175-
case astra.StatusEnumACTIVE:
175+
case astra.ACTIVE:
176176
keyspaceMutex.Lock()
177177
resp, err := client.DropKeyspaceWithResponse(ctx, astra.DatabaseIdParam(databaseID), astra.KeyspaceNameParam(keyspaceName))
178178
keyspaceMutex.Unlock()

internal/provider/resource_pcu_group.go

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
8383
PcuAttrCacheType: schema.StringAttribute{
8484
Optional: true,
8585
Computed: true,
86-
Default: stringdefault.StaticString(string(astra.InstanceTypeStandard)), // TODO do we validate the enum? Or let any string go?
86+
Default: stringdefault.StaticString(string(astra.PcuInstanceTypeStandard)), // TODO do we validate the enum? Or let any string go?
8787
PlanModifiers: []planmodifier.String{
8888
stringplanmodifier.UseStateForUnknown(),
8989
stringplanmodifier.RequiresReplace(),
@@ -92,7 +92,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
9292
PcuAttrProvisionType: schema.StringAttribute{
9393
Optional: true,
9494
Computed: true,
95-
Default: stringdefault.StaticString(string(astra.Shared)), // TODO do we validate the enum? Or let any string go?
95+
Default: stringdefault.StaticString(string(astra.PcuProvisionTypeShared)), // TODO do we validate the enum? Or let any string go?
9696
PlanModifiers: []planmodifier.String{
9797
stringplanmodifier.UseStateForUnknown(),
9898
stringplanmodifier.RequiresReplace(),
@@ -136,7 +136,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
136136
PcuAttrStatus: schema.StringAttribute{
137137
Computed: true,
138138
PlanModifiers: []planmodifier.String{
139-
mkPcuStatusOnlyActiveOrParkedPlanModifier(),
139+
inferPcuGroupStatusPlanModifier(),
140140
},
141141
},
142142
"park": schema.BoolAttribute{ // This should technically be a WriteOnly param but that requires TF 1.12+
@@ -148,7 +148,7 @@ func (r *pcuGroupResource) Schema(_ context.Context, _ resource.SchemaRequest, r
148148
},
149149
},
150150
},
151-
MkPcuResourceCreatedUpdatedAttributes(mkPcuUpdateFieldsOnlyUnknownWhenChangesOccurPlanModifier()),
151+
MkPcuResourceCreatedUpdatedAttributes(mkPcuUpdateFieldsKnownIfNoChangesOccurPlanModifier()),
152152
MkPcuResourceProtectionAttribute("deletion"),
153153
MkPcuResourceProtectionAttribute("rcu"),
154154
),
@@ -175,9 +175,11 @@ func (r *pcuGroupResource) Create(ctx context.Context, req resource.CreateReques
175175
}
176176
}
177177

178-
plan.updateGroupModel(created)
179-
180-
res.Diagnostics.Append(res.State.Set(ctx, &plan)...)
178+
res.Diagnostics.Append(res.State.Set(ctx, mkPcuGroupResourceModel(
179+
*created,
180+
plan.DeletionProtection,
181+
plan.RCUProtection,
182+
))...)
181183
}
182184

183185
func (r *pcuGroupResource) Read(ctx context.Context, req resource.ReadRequest, res *resource.ReadResponse) {
@@ -198,12 +200,11 @@ func (r *pcuGroupResource) Read(ctx context.Context, req resource.ReadRequest, r
198200
return
199201
}
200202

201-
state.updateGroupModel(group)
202-
203-
state.DeletionProtection = ElvisTF(&state.DeletionProtection, types.BoolValue(true))
204-
state.RCUProtection = ElvisTF(&state.RCUProtection, types.BoolValue(true))
205-
206-
res.Diagnostics.Append(res.State.Set(ctx, &state)...)
203+
res.Diagnostics.Append(res.State.Set(ctx, mkPcuGroupResourceModel(
204+
*group,
205+
state.DeletionProtection,
206+
state.RCUProtection,
207+
))...)
207208
}
208209

209210
func (r *pcuGroupResource) Update(ctx context.Context, req resource.UpdateRequest, res *resource.UpdateResponse) {
@@ -221,11 +222,11 @@ func (r *pcuGroupResource) Update(ctx context.Context, req resource.UpdateReques
221222
return
222223
}
223224

224-
updated := &plan.PcuGroupModel
225+
updated := &state.PcuGroupModel
225226
diags := diag.Diagnostics{}
226227

227228
if shouldUpdatePcuGroup(state, plan) {
228-
updated, diags = r.groups.Update(ctx, plan.PcuGroupSpecModel)
229+
updated, diags = r.groups.Update(ctx, plan.Id, plan.PcuGroupSpecModel)
229230

230231
if res.Diagnostics.Append(diags...); res.Diagnostics.HasError() {
231232
return
@@ -244,9 +245,11 @@ func (r *pcuGroupResource) Update(ctx context.Context, req resource.UpdateReques
244245
}
245246
}
246247

247-
plan.updateGroupModel(updated)
248-
249-
res.Diagnostics.Append(res.State.Set(ctx, plan)...)
248+
res.Diagnostics.Append(res.State.Set(ctx, mkPcuGroupResourceModel(
249+
*updated,
250+
plan.DeletionProtection,
251+
plan.RCUProtection,
252+
))...)
250253
}
251254

252255
func (r *pcuGroupResource) Delete(ctx context.Context, req resource.DeleteRequest, res *resource.DeleteResponse) {
@@ -270,31 +273,29 @@ func (r *pcuGroupResource) ImportState(ctx context.Context, req resource.ImportS
270273
resource.ImportStatePassthroughID(ctx, path.Root("id"), req, res)
271274
}
272275

273-
func mkPcuStatusOnlyActiveOrParkedPlanModifier() planmodifier.String {
276+
func inferPcuGroupStatusPlanModifier() planmodifier.String {
274277
return MkStringPlanModifier(
275278
"The status will always be 'ACTIVE' or 'PARKED', given no major errors occurred during provisioning/unprovisioning.",
276279
func(ctx context.Context, req planmodifier.StringRequest, res *planmodifier.StringResponse) {
277-
//var data *pcuGroupResourceModel
278-
//
279-
//diags := req.Plan.Get(ctx, &data)
280-
//if res.Diagnostics.Append(diags...); res.Diagnostics.HasError() {
281-
// return
282-
//}
283-
//
284-
//if data == nil {
285-
// return
286-
//}
287-
//
288-
//if data.Parked.ValueBool() {
289-
// res.PlanValue = types.StringValue(string(astra.PCUGroupStatusPARKED))
290-
//} else {
291-
// res.PlanValue = types.StringValue(string(astra.PCUGroupStatusACTIVE))
292-
//}
280+
var curr, plan *pcuGroupResourceModel
281+
282+
res.Diagnostics.Append(req.State.Get(ctx, &curr)...)
283+
res.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
284+
285+
if res.Diagnostics.HasError() {
286+
return
287+
}
288+
289+
if curr != nil && !shouldUpdatePcuGroup(*curr, *plan) {
290+
res.PlanValue = req.StateValue
291+
} else if plan.Parked.ValueBool() {
292+
res.PlanValue = types.StringValue(string(astra.PCUGroupStatusPARKED))
293+
}
293294
},
294295
)
295296
}
296297

297-
func mkPcuUpdateFieldsOnlyUnknownWhenChangesOccurPlanModifier() planmodifier.String {
298+
func mkPcuUpdateFieldsKnownIfNoChangesOccurPlanModifier() planmodifier.String {
298299
return MkStringPlanModifier(
299300
"The updated_[by|at] fields only change when properties of the PCU do.",
300301
func(ctx context.Context, req planmodifier.StringRequest, res *planmodifier.StringResponse) {
@@ -322,7 +323,11 @@ func shouldUpdatePcuGroup(curr, plan pcuGroupResourceModel) bool {
322323
!curr.Description.Equal(plan.Description)
323324
}
324325

325-
func (model *pcuGroupResourceModel) updateGroupModel(group *PcuGroupModel) {
326-
model.PcuGroupModel = *group
327-
model.Parked = types.BoolValue(group.Status.ValueString() == string(astra.PCUGroupStatusPARKED))
326+
func mkPcuGroupResourceModel(group PcuGroupModel, deletionProt, rcuProt types.Bool) pcuGroupResourceModel {
327+
return pcuGroupResourceModel{
328+
PcuGroupModel: group,
329+
Parked: types.BoolValue(group.Status.ValueString() == string(astra.PCUGroupStatusPARKED)),
330+
DeletionProtection: ElvisTF(&deletionProt, types.BoolValue(true)),
331+
RCUProtection: ElvisTF(&rcuProt, types.BoolValue(true)),
332+
}
328333
}

0 commit comments

Comments
 (0)