From 62b6b0044e50e62877314e8ceac5275914282432 Mon Sep 17 00:00:00 2001 From: PHAN Trung Thanh Date: Wed, 12 Jul 2023 14:52:20 +0200 Subject: [PATCH] Add used_in_production arg in subaccount creation and update --- internal/btpcli/facade_accounts_subaccount.go | 16 ++++++------- internal/provider/resource_subaccount.go | 24 +++++++++++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/internal/btpcli/facade_accounts_subaccount.go b/internal/btpcli/facade_accounts_subaccount.go index 3fcce459..501bf337 100644 --- a/internal/btpcli/facade_accounts_subaccount.go +++ b/internal/btpcli/facade_accounts_subaccount.go @@ -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) { diff --git a/internal/provider/resource_subaccount.go b/internal/provider/resource_subaccount.go index bc9ebeea..a3998bf1 100644 --- a/internal/provider/resource_subaccount.go +++ b/internal/provider/resource_subaccount.go @@ -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", + }...), + }, }, }, } @@ -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 { @@ -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))