@@ -38,6 +38,7 @@ type ProjectResourceModel struct {
38
38
Name types.String `tfsdk:"name"`
39
39
DatabasePassword types.String `tfsdk:"database_password"`
40
40
Region types.String `tfsdk:"region"`
41
+ InstanceSize types.String `tfsdk:"instance_size"`
41
42
Id types.String `tfsdk:"id"`
42
43
}
43
44
@@ -67,6 +68,10 @@ func (r *ProjectResource) Schema(ctx context.Context, req resource.SchemaRequest
67
68
MarkdownDescription : "Region where the project is located" ,
68
69
Required : true ,
69
70
},
71
+ "instance_size" : schema.StringAttribute {
72
+ MarkdownDescription : "Desired instance size of the project" ,
73
+ Optional : true ,
74
+ },
70
75
"id" : schema.StringAttribute {
71
76
MarkdownDescription : "Project identifier" ,
72
77
Computed : true ,
@@ -85,13 +90,11 @@ func (r *ProjectResource) Configure(ctx context.Context, req resource.ConfigureR
85
90
}
86
91
87
92
client , ok := req .ProviderData .(* api.ClientWithResponses )
88
-
89
93
if ! ok {
90
94
resp .Diagnostics .AddError (
91
95
"Unexpected Resource Configure Type" ,
92
96
fmt .Sprintf ("Expected *http.Client, got: %T. Please report this issue to the provider developers." , req .ProviderData ),
93
97
)
94
-
95
98
return
96
99
}
97
100
@@ -103,13 +106,11 @@ func (r *ProjectResource) Create(ctx context.Context, req resource.CreateRequest
103
106
104
107
// Read Terraform plan data into the model
105
108
resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
106
-
107
109
if resp .Diagnostics .HasError () {
108
110
return
109
111
}
110
112
111
113
resp .Diagnostics .Append (createProject (ctx , & data , r .client )... )
112
-
113
114
if resp .Diagnostics .HasError () {
114
115
return
115
116
}
@@ -125,15 +126,13 @@ func (r *ProjectResource) Read(ctx context.Context, req resource.ReadRequest, re
125
126
126
127
// Read Terraform prior state data into the model
127
128
resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
128
-
129
129
if resp .Diagnostics .HasError () {
130
130
return
131
131
}
132
132
133
133
tflog .Trace (ctx , "read project" )
134
134
135
135
resp .Diagnostics .Append (readProject (ctx , & data , r .client )... )
136
-
137
136
if resp .Diagnostics .HasError () {
138
137
return
139
138
}
@@ -147,7 +146,6 @@ func (r *ProjectResource) Update(ctx context.Context, req resource.UpdateRequest
147
146
148
147
// Read Terraform plan data into the model
149
148
resp .Diagnostics .Append (req .Plan .Get (ctx , & data )... )
150
-
151
149
if resp .Diagnostics .HasError () {
152
150
return
153
151
}
@@ -162,13 +160,11 @@ func (r *ProjectResource) Delete(ctx context.Context, req resource.DeleteRequest
162
160
163
161
// Read Terraform prior state data into the model
164
162
resp .Diagnostics .Append (req .State .Get (ctx , & data )... )
165
-
166
163
if resp .Diagnostics .HasError () {
167
164
return
168
165
}
169
166
170
167
resp .Diagnostics .Append (deleteProject (ctx , & data , r .client )... )
171
-
172
168
if resp .Diagnostics .HasError () {
173
169
return
174
170
}
@@ -184,13 +180,17 @@ func (r *ProjectResource) ImportState(ctx context.Context, req resource.ImportSt
184
180
}
185
181
186
182
func createProject (ctx context.Context , data * ProjectResourceModel , client * api.ClientWithResponses ) diag.Diagnostics {
187
- httpResp , err := client . CreateProjectWithResponse ( ctx , api.CreateProjectJSONRequestBody {
183
+ body := api.CreateProjectJSONRequestBody {
188
184
OrganizationId : data .OrganizationId .ValueString (),
189
185
Name : data .Name .ValueString (),
190
186
DbPass : data .DatabasePassword .ValueString (),
191
- Region : api .CreateProjectBodyRegion (data .Region .ValueString ()),
192
- })
187
+ Region : api .V1CreateProjectBodyRegion (data .Region .ValueString ()),
188
+ }
189
+ if ! data .InstanceSize .IsNull () {
190
+ body .DesiredInstanceSize = Ptr (api .DesiredInstanceSize (data .InstanceSize .ValueString ()))
191
+ }
193
192
193
+ httpResp , err := client .CreateProjectWithResponse (ctx , body )
194
194
if err != nil {
195
195
msg := fmt .Sprintf ("Unable to create project, got error: %s" , err )
196
196
return diag.Diagnostics {diag .NewErrorDiagnostic ("Client Error" , msg )}
@@ -207,7 +207,6 @@ func createProject(ctx context.Context, data *ProjectResourceModel, client *api.
207
207
208
208
func readProject (ctx context.Context , data * ProjectResourceModel , client * api.ClientWithResponses ) diag.Diagnostics {
209
209
httpResp , err := client .GetProjectsWithResponse (ctx )
210
-
211
210
if err != nil {
212
211
msg := fmt .Sprintf ("Unable to read project, got error: %s" , err )
213
212
return diag.Diagnostics {diag .NewErrorDiagnostic ("Client Error" , msg )}
@@ -234,7 +233,6 @@ func readProject(ctx context.Context, data *ProjectResourceModel, client *api.Cl
234
233
235
234
func deleteProject (ctx context.Context , data * ProjectResourceModel , client * api.ClientWithResponses ) diag.Diagnostics {
236
235
httpResp , err := client .DeleteProjectWithResponse (ctx , data .Id .ValueString ())
237
-
238
236
if err != nil {
239
237
msg := fmt .Sprintf ("Unable to delete project, got error: %s" , err )
240
238
return diag.Diagnostics {diag .NewErrorDiagnostic ("Client Error" , msg )}
0 commit comments