diff --git a/docs/resources/subaccount.md b/docs/resources/subaccount.md index 5d84d5f0..7c760f62 100644 --- a/docs/resources/subaccount.md +++ b/docs/resources/subaccount.md @@ -59,6 +59,13 @@ resource "btp_subaccount" "my_project_on_azure" { - `description` (String) A description of the subaccount for customer-facing UIs. - `labels` (Map of Set of String) The set of words or phrases assigned to the subaccount. - `parent_id` (String) The ID of the subaccount’s parent entity. If the subaccount is located directly in the global account (not in a directory), then this is the ID of the global account. +- `usage` (String) Shows whether the subaccount is used for production purposes. This flag can help your cloud operator to take appropriate action when handling incidents that are related to mission-critical accounts in production systems. Do not apply for subaccounts that are used for nonproduction purposes, such as development, testing, and demos. Applying this setting this does not modify the subaccount. Possible values are: + + | value | description | + | --- | --- | + | `UNSET` | Global account or subaccount admin has not set the production-relevancy flag (default value). | + | `NOT_USED_FOR_PRODUCTION` | The subaccount is not used for production purposes. | + | `USED_FOR_PRODUCTION` | The subaccount is used for production purposes. | ### Read-Only @@ -94,13 +101,6 @@ resource "btp_subaccount" "my_project_on_azure" { | `MIGRATION_FAILED` | The migration of the subaccount failed and the subaccount was not migrated. | | `ROLLBACK_MIGRATION_PROCESSING` | The migration of the subaccount was rolled back and the subaccount is not migrated. | | `SUSPENSION_FAILED` | The suspension operations failed. | -- `usage` (String) Shows whether the subaccount is used for production purposes. This flag can help your cloud operator to take appropriate action when handling incidents that are related to mission-critical accounts in production systems. Do not apply for subaccounts that are used for nonproduction purposes, such as development, testing, and demos. Applying this setting this does not modify the subaccount. Possible values are: - - | value | description | - | --- | --- | - | `UNSET` | Global account or subaccount admin has not set the production-relevancy flag (default value). | - | `NOT_USED_FOR_PRODUCTION` | The subaccount is not used for production purposes. | - | `USED_FOR_PRODUCTION` | The subaccount is used for production purposes. | ## Import 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/btpcli/facade_accounts_subaccount_test.go b/internal/btpcli/facade_accounts_subaccount_test.go index d70b1ce6..55fa2667 100644 --- a/internal/btpcli/facade_accounts_subaccount_test.go +++ b/internal/btpcli/facade_accounts_subaccount_test.go @@ -129,11 +129,12 @@ func TestAccountsSubaccountFacade_Update(t *testing.T) { srvCalled = true assertCall(t, r, command, ActionUpdate, map[string]string{ - "subaccount": subaccountId, - "displayName": displayName, - "description": description, - "betaEnabled": "false", - "globalAccount": globalAccount, + "subaccount": subaccountId, + "displayName": displayName, + "description": description, + "betaEnabled": "false", + "globalAccount": globalAccount, + "usedForProduction": "false", }) })) 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))