Skip to content

Commit

Permalink
Add used_in_production arg in subaccount creation and update
Browse files Browse the repository at this point in the history
  • Loading branch information
PHAN Trung Thanh committed Jul 12, 2023
1 parent c719f8b commit 62b6b00
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
16 changes: 8 additions & 8 deletions internal/btpcli/facade_accounts_subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ type SubaccountCreateInput struct { // TODO support all options
}

type SubaccountUpdateInput struct {
BetaEnabled bool `btpcli:"betaEnabled"`
Description string `btpcli:"description"`
Directory string `btpcli:"directoryID"`
DisplayName string `btpcli:"displayName"`
Labels map[string][]string `btpcli:"labels"`
SubaccountId string `btpcli:"subaccount"`
Globalaccount string `btpcli:"globalAccount"`
// UsedForProduction bool `btpcli:"usedForProduction"`
BetaEnabled bool `btpcli:"betaEnabled"`
Description string `btpcli:"description"`
Directory string `btpcli:"directoryID"`
DisplayName string `btpcli:"displayName"`
Labels map[string][]string `btpcli:"labels"`
SubaccountId string `btpcli:"subaccount"`
Globalaccount string `btpcli:"globalAccount"`
UsedForProduction bool `btpcli:"usedForProduction"`
}

func (f *accountsSubaccountFacade) Create(ctx context.Context, args *SubaccountCreateInput) (cis.SubaccountResponseObject, CommandResponse, error) {
Expand Down
24 changes: 24 additions & 0 deletions internal/provider/resource_subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ __Further documentation:__
getFormattedValueAsTableRow("`NOT_USED_FOR_PRODUCTION`", "The subaccount is not used for production purposes.") +
getFormattedValueAsTableRow("`USED_FOR_PRODUCTION`", "The subaccount is used for production purposes."),
Computed: true,
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf([]string{
"USED_FOR_PRODUCTION",
"NOT_USED_FOR_PRODUCTION",
"UNSET",
}...),
},
},
},
}
Expand Down Expand Up @@ -236,6 +244,11 @@ func (rs *subaccountResource) Create(ctx context.Context, req resource.CreateReq
args.Labels = labels
}

if !plan.Usage.IsUnknown() && !plan.Usage.IsNull() {
usedForProduction := plan.Usage.ValueString()
args.UsedForProduction = usedForProduction
}

cliRes, _, err := rs.cli.Accounts.Subaccount.Create(ctx, &args)

if err != nil {
Expand Down Expand Up @@ -299,6 +312,17 @@ func (rs *subaccountResource) Update(ctx context.Context, req resource.UpdateReq
plan.Labels.ElementsAs(ctx, &labels, false)
args.Labels = labels

// Specifically in BTP CLI's update subcommand, usage is specified as a boolean
// As shown in the cli's documentation
// --used-for-production [BOOL]
// So we modify the input arg here
if !plan.Usage.IsUnknown() && !plan.Usage.IsNull() {
if !plan.Usage.Equal(types.StringValue("UNSET")) {
usedForProduction := plan.Usage.ValueString()
args.UsedForProduction = (usedForProduction == "USED_FOR_PRODUCTION")
}
}

cliRes, _, err := rs.cli.Accounts.Subaccount.Update(ctx, &args)
if err != nil {
resp.Diagnostics.AddError("API Error Updating Resource Subaccount", fmt.Sprintf("%s", err))
Expand Down

0 comments on commit 62b6b00

Please sign in to comment.