Skip to content

Commit 042be09

Browse files
committed
add access scope flag to instance create command
1 parent 0843dce commit 042be09

3 files changed

Lines changed: 46 additions & 1 deletion

File tree

docs/stackit_postgresflex_instance_create.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ stackit postgresflex instance create [flags]
2323
### Options
2424

2525
```
26+
--access-scope string The access scope of the instance. It defines if the instance is public or airgapped. (one of: [PUBLIC, SNA])
2627
--acl strings The access control list (ACL). Must contain at least one valid subnet, for instance '0.0.0.0/0' for open access (discouraged), '1.2.3.0/24 for a public IP range of an organization, '1.2.3.4/32' for a single IP range, etc. (default [])
2728
--backup-schedule string Backup schedule. This flag will be required after 2027-01-31.
2829
--encryption-kek-key-id string The key identifier

internal/cmd/postgresflex/instance/create/create.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,23 @@ var (
5555
"Instance type,",
5656
flags.StringEnumDefaultValue(defaultType),
5757
)
58+
59+
accessScopeFlag = flags.StringEnumFlag(
60+
"access-scope",
61+
[]string{
62+
string(postgresflex.INSTANCENETWORKACCESSSCOPE_PUBLIC),
63+
string(postgresflex.INSTANCENETWORKACCESSSCOPE_SNA),
64+
},
65+
"The access scope of the instance. It defines if the instance is public or airgapped.",
66+
)
5867
)
5968

6069
type inputModel struct {
6170
*globalflags.GlobalFlagModel
6271

6372
InstanceName string
6473
ACL []string
74+
AccessScope *string
6575
BackupSchedule *string
6676
FlavorId *string
6777
StorageClass *string
@@ -203,6 +213,7 @@ func configureFlags(cmd *cobra.Command) {
203213
cmd.Flags().String(encryptionKekKeyringIdFlag, "", "The keyring identifier")
204214
cmd.Flags().String(encryptionKekKeyVersionFlag, "", "The key version")
205215
cmd.Flags().String(encryptionServiceAccountFlag, "", "The service account")
216+
accessScopeFlag.Register(cmd.Flags())
206217

207218
// remove after 2027-01-31
208219
cmd.Flags().Int64(cpuFlag, 0, "Number of CPUs.")
@@ -266,6 +277,7 @@ func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel,
266277
GlobalFlagModel: globalFlags,
267278
InstanceName: flags.FlagToStringValue(p, cmd, instanceNameFlag),
268279
ACL: flags.FlagToStringSliceValue(p, cmd, aclFlag),
280+
AccessScope: accessScopeFlag.Ptr(),
269281
BackupSchedule: flags.FlagToStringPointer(p, cmd, backupScheduleFlag),
270282
FlavorId: flavorId,
271283
StorageClass: flags.FlagToStringPointer(p, cmd, storageClassFlag),
@@ -326,6 +338,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient postgresflex
326338
}
327339
}
328340

341+
var accessScope *postgresflex.InstanceNetworkAccessScope
342+
if model.AccessScope != nil {
343+
accessScope = new(postgresflex.InstanceNetworkAccessScope(*model.AccessScope))
344+
}
345+
329346
// remove after 2027-01-31
330347
if model.BackupSchedule == nil {
331348
return postgresflex.ApiCreateInstanceRequest{}, fmt.Errorf("backup schedule is nil")
@@ -341,7 +358,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient postgresflex
341358
FlavorId: utils.PtrString(model.FlavorId),
342359
Name: model.InstanceName,
343360
Network: postgresflex.InstanceNetworkCreate{
344-
Acl: model.ACL,
361+
Acl: model.ACL,
362+
AccessScope: accessScope,
345363
},
346364
RetentionDays: *postgresflex.NewNullableInt32(model.RetentionDays),
347365
Storage: postgresflex.StorageCreate{

internal/cmd/postgresflex/instance/create/create_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,18 @@ func TestParseInput(t *testing.T) {
221221
aclValues: []string{},
222222
isValid: false,
223223
},
224+
{
225+
description: "access scope set",
226+
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
227+
flagValues["access-scope"] = string(postgresflex.INSTANCENETWORKACCESSSCOPE_SNA)
228+
}),
229+
isValid: true,
230+
expectedModel: fixtureInputModel(
231+
func(model *inputModel) {
232+
model.AccessScope = new(string(postgresflex.INSTANCENETWORKACCESSSCOPE_SNA))
233+
},
234+
),
235+
},
224236
}
225237

226238
for _, tt := range tests {
@@ -245,6 +257,20 @@ func TestBuildRequest(t *testing.T) {
245257
isValid: true,
246258
expectedRequest: fixtureRequest(),
247259
},
260+
{
261+
description: "access scope set",
262+
model: fixtureInputModel(func(model *inputModel) {
263+
model.AccessScope = new(string(postgresflex.INSTANCENETWORKACCESSSCOPE_SNA))
264+
}),
265+
isValid: true,
266+
expectedRequest: fixtureRequest(func(request *postgresflex.ApiCreateInstanceRequest) {
267+
payload := fixturePayload(func(payload *postgresflex.CreateInstancePayload) {
268+
payload.Network.AccessScope = new(postgresflex.INSTANCENETWORKACCESSSCOPE_SNA)
269+
})
270+
271+
*request = request.CreateInstancePayload(payload)
272+
}),
273+
},
248274
}
249275

250276
for _, tt := range tests {

0 commit comments

Comments
 (0)