Skip to content

Commit 6b363be

Browse files
committed
iks upgrade added
Signed-off-by: Nadgowda, Shripad <[email protected]>
1 parent 7377bbd commit 6b363be

File tree

5 files changed

+328
-68
lines changed

5 files changed

+328
-68
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"version": 4,
3+
"terraform_version": "1.9.3",
4+
"serial": 4,
5+
"lineage": "7219df5a-b4c8-874f-e7b0-c6e1e6fdb637",
6+
"outputs": {
7+
"iks_order": {
8+
"value": {
9+
"availability_zone": "us-region-2a",
10+
"cloudaccount": "514957828905",
11+
"cluster_status": "Active",
12+
"id": "cl-bzm3m2ouba",
13+
"kubernetes_version": "1.27",
14+
"name": "talented-ostrich-iks",
15+
"network": {
16+
"cluster_cidr": "100.68.0.0/16",
17+
"cluster_dns": "100.66.0.10",
18+
"enable_lb": false,
19+
"service_cidr": "100.66.0.0/16"
20+
},
21+
"storage": null,
22+
"upgrade_available": true
23+
},
24+
"type": [
25+
"object",
26+
{
27+
"availability_zone": "string",
28+
"cloudaccount": "string",
29+
"cluster_status": "string",
30+
"id": "string",
31+
"kubernetes_version": "string",
32+
"name": "string",
33+
"network": [
34+
"object",
35+
{
36+
"cluster_cidr": "string",
37+
"cluster_dns": "string",
38+
"enable_lb": "bool",
39+
"service_cidr": "string"
40+
}
41+
],
42+
"storage": [
43+
"object",
44+
{
45+
"size_in_tb": "number",
46+
"state": "string",
47+
"storage_provider": "string"
48+
}
49+
],
50+
"upgrade_available": "bool"
51+
}
52+
]
53+
}
54+
},
55+
"resources": [
56+
{
57+
"mode": "managed",
58+
"type": "intelcloud_iks_cluster",
59+
"name": "cluster1",
60+
"provider": "provider[\"registry.terraform.io/intel/intelcloud\"]",
61+
"instances": [
62+
{
63+
"schema_version": 0,
64+
"attributes": {
65+
"availability_zone": "us-region-2a",
66+
"cloudaccount": "514957828905",
67+
"cluster_status": "Active",
68+
"id": "cl-bzm3m2ouba",
69+
"kubernetes_version": "1.27",
70+
"name": "talented-ostrich-iks",
71+
"network": {
72+
"cluster_cidr": "100.68.0.0/16",
73+
"cluster_dns": "100.66.0.10",
74+
"enable_lb": false,
75+
"service_cidr": "100.66.0.0/16"
76+
},
77+
"storage": null,
78+
"upgrade_available": true
79+
},
80+
"sensitive_attributes": [],
81+
"dependencies": [
82+
"random_pet.prefix"
83+
]
84+
}
85+
]
86+
},
87+
{
88+
"mode": "managed",
89+
"type": "intelcloud_iks_node_group",
90+
"name": "ng1",
91+
"provider": "provider[\"registry.terraform.io/intel/intelcloud\"]",
92+
"instances": [
93+
{
94+
"schema_version": 0,
95+
"attributes": {
96+
"cluster_uuid": "cl-bzm3m2ouba",
97+
"id": "ng-canq2j5ua4",
98+
"imiid": "iks-vm-u22-cd-wk-1-27-11-v20240227",
99+
"interfaces": [
100+
{
101+
"name": "us-region-2a",
102+
"vnet": "us-region-2a-default"
103+
}
104+
],
105+
"name": "talented-ostrich-ng",
106+
"node_count": 1,
107+
"node_type": "vm-spr-sml",
108+
"ssh_public_key_names": [
109+
"shrimac"
110+
],
111+
"state": "Active",
112+
"userdata_url": ""
113+
},
114+
"sensitive_attributes": [],
115+
"dependencies": [
116+
"intelcloud_iks_cluster.cluster1",
117+
"random_pet.prefix"
118+
]
119+
}
120+
]
121+
},
122+
{
123+
"mode": "managed",
124+
"type": "random_pet",
125+
"name": "prefix",
126+
"provider": "provider[\"registry.terraform.io/hashicorp/random\"]",
127+
"instances": [
128+
{
129+
"schema_version": 0,
130+
"attributes": {
131+
"id": "talented-ostrich",
132+
"keepers": null,
133+
"length": 2,
134+
"prefix": null,
135+
"separator": "-"
136+
},
137+
"sensitive_attributes": []
138+
}
139+
]
140+
}
141+
],
142+
"check_results": null
143+
}

examples/resources/iks/terraform.tfstate

Lines changed: 0 additions & 9 deletions
This file was deleted.

internal/provider/filesystem_resource.go

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -286,63 +286,63 @@ func (r *filesystemResource) Update(ctx context.Context, req resource.UpdateRequ
286286
// Detect changes in the "spec" field
287287
if !plan.Spec.Size.Equal(state.Spec.Size) {
288288
tflog.Info(ctx, "Detected change in filesystem spec, updating resource")
289-
}
290289

291-
inArg := itacservices.FilesystemUpdateRequest{
292-
Metadata: struct {
293-
Name string "json:\"name\""
294-
}{
295-
Name: plan.Name.ValueString(),
296-
},
297-
Spec: struct {
298-
Request struct {
299-
Size string "json:\"storage\""
300-
} "json:\"request\""
301-
}{
302-
Request: struct {
303-
Size string "json:\"storage\""
290+
inArg := itacservices.FilesystemUpdateRequest{
291+
Metadata: struct {
292+
Name string "json:\"name\""
304293
}{
305-
Size: fmt.Sprintf("%dTB", plan.Spec.Size.ValueInt64()),
294+
Name: plan.Name.ValueString(),
306295
},
307-
},
308-
}
309-
310-
tflog.Info(ctx, "making a call to IDC Service for update filesystem")
311-
err := r.client.UpdateFilesystem(ctx, &inArg)
312-
if err != nil {
313-
resp.Diagnostics.AddError(
314-
"Error creating order",
315-
"Could not create order, unexpected error: "+err.Error(),
316-
)
317-
return
318-
}
319-
320-
// Get refreshed order value from IDC Service
321-
filesystem, err := r.client.GetFilesystemByResourceId(ctx, state.ID.ValueString())
322-
if err != nil {
323-
resp.Diagnostics.AddError(
324-
"Error Reading IDC Filesystem resource",
325-
"Could not read IDC Filesystem resource ID "+state.ID.ValueString()+": "+err.Error(),
326-
)
327-
return
328-
}
329-
330-
currState, err := refreshFilesystemResourceModel(ctx, filesystem)
331-
if err != nil {
332-
resp.Diagnostics.AddError(
333-
"Error Reading IDC Filesystem resource",
334-
"Could not read IDC Filesystem resource ID "+plan.ID.ValueString()+": "+err.Error(),
335-
)
336-
return
337-
}
338-
currState.Spec.Size = plan.Spec.Size
339-
// Set refreshed state
340-
diags = resp.State.Set(ctx, currState)
341-
resp.Diagnostics.Append(diags...)
342-
if resp.Diagnostics.HasError() {
343-
return
296+
Spec: struct {
297+
Request struct {
298+
Size string "json:\"storage\""
299+
} "json:\"request\""
300+
}{
301+
Request: struct {
302+
Size string "json:\"storage\""
303+
}{
304+
Size: fmt.Sprintf("%dTB", plan.Spec.Size.ValueInt64()),
305+
},
306+
},
307+
}
308+
309+
tflog.Info(ctx, "making a call to IDC Service for update filesystem")
310+
err := r.client.UpdateFilesystem(ctx, &inArg)
311+
if err != nil {
312+
resp.Diagnostics.AddError(
313+
"Error creating order",
314+
"Could not create order, unexpected error: "+err.Error(),
315+
)
316+
return
317+
}
318+
319+
// Get refreshed order value from IDC Service
320+
filesystem, err := r.client.GetFilesystemByResourceId(ctx, state.ID.ValueString())
321+
if err != nil {
322+
resp.Diagnostics.AddError(
323+
"Error Reading IDC Filesystem resource",
324+
"Could not read IDC Filesystem resource ID "+state.ID.ValueString()+": "+err.Error(),
325+
)
326+
return
327+
}
328+
329+
currState, err := refreshFilesystemResourceModel(ctx, filesystem)
330+
if err != nil {
331+
resp.Diagnostics.AddError(
332+
"Error Reading IDC Filesystem resource",
333+
"Could not read IDC Filesystem resource ID "+plan.ID.ValueString()+": "+err.Error(),
334+
)
335+
return
336+
}
337+
currState.Spec.Size = plan.Spec.Size
338+
// Set refreshed state
339+
diags = resp.State.Set(ctx, currState)
340+
resp.Diagnostics.Append(diags...)
341+
if resp.Diagnostics.HasError() {
342+
return
343+
}
344344
}
345-
345+
tflog.Info(ctx, "no change detected change in filesystem spec, skipping update")
346346
}
347347

348348
func (r *filesystemResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) {
@@ -391,6 +391,8 @@ func mapFilesystemStatus(fsStatus string) string {
391391
func refreshFilesystemResourceModel(ctx context.Context, filesystem *itacservices.Filesystem) (*filesystemResourceModel, error) {
392392

393393
state := &filesystemResourceModel{}
394+
diags := diag.Diagnostics{}
395+
394396
sizeStr := strings.Split(filesystem.Spec.Request.Size, "TB")[0]
395397
size, _ := strconv.ParseInt(sizeStr, 10, 64)
396398

@@ -421,7 +423,6 @@ func refreshFilesystemResourceModel(ctx context.Context, filesystem *itacservice
421423
Password: types.StringValue(filesystem.Status.Mount.Password),
422424
}
423425

424-
diags := diag.Diagnostics{}
425426
state.ClusterInfo, diags = types.ObjectValueFrom(ctx, clusterInfoMap.AttributeTypes(), clusterInfoMap)
426427
if diags.HasError() {
427428
return state, fmt.Errorf("error parsing values")

0 commit comments

Comments
 (0)