Skip to content

Commit 439b8dd

Browse files
Merge pull request #3170 from jerichokeyne/ocm-21587
OCM-21587 | fix: Removing fedramp checks that prevent setting HCP billing accounts
2 parents b5b452a + 79cd65d commit 439b8dd

4 files changed

Lines changed: 71 additions & 92 deletions

File tree

cmd/create/cluster/cmd.go

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,106 +1222,89 @@ func run(cmd *cobra.Command, _ []string) {
12221222

12231223
// Billing Account
12241224
billingAccount := args.billingAccount
1225-
if !fedramp.Enabled() {
1226-
isClassicBillingCapabilityEnabled, err := r.OCMClient.IsCapabilityEnabled(
1227-
"capability.cluster.rosa_classic_billing_account")
1228-
if err != nil {
1229-
_ = r.Reporter.Errorf("Failed to determine if billing account capability is enabled for user "+
1230-
"organization: %s", err)
1225+
isClassicBillingCapabilityEnabled, err := r.OCMClient.IsCapabilityEnabled(
1226+
"capability.cluster.rosa_classic_billing_account")
1227+
if err != nil {
1228+
_ = r.Reporter.Errorf("failed to determine if billing account capability is enabled for user "+
1229+
"organization: %s", err)
1230+
os.Exit(1)
1231+
}
1232+
1233+
isHcpBillingTechPreview, err := r.OCMClient.IsTechnologyPreview(ocm.HcpBillingAccount, time.Now())
1234+
if err != nil {
1235+
r.Reporter.Errorf("%s", err)
1236+
os.Exit(1)
1237+
}
1238+
1239+
if (isHostedCP && !isHcpBillingTechPreview) || (!isHostedCP && isClassicBillingCapabilityEnabled) {
1240+
1241+
if billingAccount != "" && !ocm.IsValidAWSAccount(billingAccount) {
1242+
r.Reporter.Errorf("provided billing account number %s is not valid. "+
1243+
"Rerun the command with a valid billing account number. %s",
1244+
billingAccount, listBillingAccountMessage)
12311245
os.Exit(1)
12321246
}
12331247

1234-
isHcpBillingTechPreview, err := r.OCMClient.IsTechnologyPreview(ocm.HcpBillingAccount, time.Now())
1248+
cloudAccounts, err := r.OCMClient.GetBillingAccounts()
12351249
if err != nil {
12361250
r.Reporter.Errorf("%s", err)
12371251
os.Exit(1)
12381252
}
12391253

1240-
if (isHostedCP && !isHcpBillingTechPreview) || (!isHostedCP && isClassicBillingCapabilityEnabled) {
1241-
1242-
if billingAccount != "" && !ocm.IsValidAWSAccount(billingAccount) {
1243-
r.Reporter.Errorf("Provided billing account number %s is not valid. "+
1244-
"Rerun the command with a valid billing account number. %s",
1245-
billingAccount, listBillingAccountMessage)
1246-
os.Exit(1)
1247-
}
1248-
1249-
cloudAccounts, err := r.OCMClient.GetBillingAccounts()
1250-
if err != nil {
1251-
r.Reporter.Errorf("%s", err)
1252-
os.Exit(1)
1253-
}
1254+
billingAccounts := ocm.GenerateBillingAccountsList(cloudAccounts)
12541255

1255-
billingAccounts := ocm.GenerateBillingAccountsList(cloudAccounts)
1256+
if interactive.Enabled() {
1257+
if len(billingAccounts) > 0 {
1258+
billingAccount, err = interactive.GetOption(interactive.Input{
1259+
Question: "Billing Account",
1260+
Help: cmd.Flags().Lookup("billing-account").Usage,
1261+
Default: billingAccount,
1262+
Required: true,
1263+
Options: billingAccounts,
1264+
})
12561265

1257-
if billingAccount == "" && !interactive.Enabled() {
1258-
// if a billing account is not provided we will try to use the infrastructure account as default
1259-
billingAccount, err = provideBillingAccount(billingAccounts, awsCreator.AccountID, r)
12601266
if err != nil {
1261-
r.Reporter.Errorf("%s", err)
1267+
r.Reporter.Errorf("expected a valid billing account: '%s'", err)
12621268
os.Exit(1)
12631269
}
1264-
}
1265-
1266-
if interactive.Enabled() {
1267-
if len(billingAccounts) > 0 {
1268-
billingAccount, err = interactive.GetOption(interactive.Input{
1269-
Question: "Billing Account",
1270-
Help: cmd.Flags().Lookup("billing-account").Usage,
1271-
Default: billingAccount,
1272-
Required: true,
1273-
Options: billingAccounts,
1274-
})
12751270

1276-
if err != nil {
1277-
r.Reporter.Errorf("Expected a valid billing account: '%s'", err)
1278-
os.Exit(1)
1279-
}
1280-
1281-
billingAccount = aws.ParseOption(billingAccount)
1282-
}
1283-
1284-
err := ocm.ValidateBillingAccount(billingAccount)
1285-
if err != nil {
1286-
r.Reporter.Errorf("%v", err)
1287-
os.Exit(1)
1288-
}
1271+
billingAccount = aws.ParseOption(billingAccount)
1272+
}
12891273

1290-
// Get contract info
1291-
contracts, isContractEnabled := ocm.GetBillingAccountContracts(cloudAccounts, billingAccount)
1274+
// Get contract info
1275+
contracts, isContractEnabled := ocm.GetBillingAccountContracts(cloudAccounts, billingAccount)
12921276

1293-
if billingAccount != awsCreator.AccountID {
1294-
r.Reporter.Infof(
1295-
"The AWS billing account you selected is different from your AWS infrastructure account. " +
1296-
"The AWS billing account will be charged for subscription usage. " +
1297-
"The AWS infrastructure account contains the ROSA infrastructure.",
1298-
)
1299-
} else {
1300-
r.Reporter.Infof("Using '%s' as billing account.",
1301-
billingAccount)
1302-
}
1277+
if billingAccount != awsCreator.AccountID {
1278+
r.Reporter.Infof(
1279+
"The AWS billing account you selected is different from your AWS infrastructure account. " +
1280+
"The AWS billing account will be charged for subscription usage. " +
1281+
"The AWS infrastructure account contains the ROSA infrastructure.",
1282+
)
1283+
} else {
1284+
r.Reporter.Infof("Using '%s' as billing account.",
1285+
billingAccount)
1286+
}
13031287

1304-
if isContractEnabled && len(contracts) > 0 {
1305-
//currently, an AWS account will have only one ROSA HCP active contract at a time
1306-
contractDisplay := GenerateContractDisplay(contracts[0])
1307-
r.Reporter.Infof(contractDisplay)
1308-
}
1288+
if isContractEnabled && len(contracts) > 0 {
1289+
//currently, an AWS account will have only one ROSA HCP active contract at a time
1290+
contractDisplay := GenerateContractDisplay(contracts[0])
1291+
r.Reporter.Infof(contractDisplay)
13091292
}
13101293
}
1311-
}
13121294

1313-
if fedramp.Enabled() && billingAccount != "" {
1314-
_ = r.Reporter.Errorf(billingAccountsGovErrorMsg)
1315-
os.Exit(1)
1316-
}
1295+
if billingAccount == "" && !interactive.Enabled() {
1296+
// if a billing account is not provided we will try to use the infrastructure account as default
1297+
billingAccount, err = provideBillingAccount(billingAccounts, awsCreator.AccountID, r)
1298+
if err != nil {
1299+
r.Reporter.Errorf("%s", err)
1300+
os.Exit(1)
1301+
}
1302+
}
13171303

1318-
if isHostedCP && fedramp.Enabled() && billingAccount != "" {
1319-
if cmd.Flags().Changed(billingAccountFlag) {
1320-
_ = r.Reporter.Errorf(billingAccountsGovErrorMsg)
1321-
} else {
1322-
r.Reporter.Warnf("Billing accounts when using Govcloud are associated with non-govcloud accounts, " +
1323-
"using empty ID for billing account to create cluster")
1324-
billingAccount = ""
1304+
err = ocm.ValidateBillingAccount(billingAccount)
1305+
if err != nil {
1306+
r.Reporter.Errorf("%v", err)
1307+
os.Exit(1)
13251308
}
13261309
}
13271310

cmd/create/cluster/cmd_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,15 @@ var _ = Describe("validateBillingAccount()", func() {
481481
wrongBillingAccount := "123"
482482
err := ocm.ValidateBillingAccount(wrongBillingAccount)
483483
Expect(err).To(HaveOccurred())
484-
Expect(err.Error()).To(Equal("Provided billing account number 123 is not valid. " +
484+
Expect(err.Error()).To(Equal("provided billing account number 123 is not valid. " +
485485
"Rerun the command with a valid billing account number"))
486486
})
487487

488488
It("KO: fails to validate an empty billing account", func() {
489489
wrongBillingAccount := ""
490490
err := ocm.ValidateBillingAccount(wrongBillingAccount)
491491
Expect(err).To(HaveOccurred())
492-
Expect(err.Error()).To(Equal("A billing account number is required"))
492+
Expect(err.Error()).To(Equal("a billing account number is required"))
493493
})
494494

495495
})

cmd/edit/cluster/cmd.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -887,21 +887,17 @@ func run(cmd *cobra.Command, _ []string) {
887887
if cmd.Flags().Changed("billing-account") {
888888
billingAccount = args.billingAccount
889889

890-
if billingAccount != "" && fedramp.Enabled() {
891-
_ = r.Reporter.Errorf("Billing accounts are not supported for govcloud clusters")
892-
os.Exit(1)
893-
}
894890
if billingAccount != "" && !ocm.IsValidAWSAccount(billingAccount) {
895-
_ = r.Reporter.Errorf("Provided billing account number %s is not valid. "+
891+
_ = r.Reporter.Errorf("provided billing account number %s is not valid. "+
896892
"Rerun the command with a valid billing account number", billingAccount)
897893
os.Exit(1)
898894
}
899895
} else {
900896
billingAccount = cluster.AWS().BillingAccountID()
901897
}
902898

903-
if interactive.Enabled() && !fedramp.Enabled() &&
904-
(aws.IsHostedCP(cluster) && isClassicBillingCapabilityEnabled) {
899+
if interactive.Enabled() &&
900+
(aws.IsHostedCP(cluster) || isClassicBillingCapabilityEnabled) {
905901
cloudAccounts, err := r.OCMClient.GetBillingAccounts()
906902
if err != nil {
907903
_ = r.Reporter.Errorf("%s", err)

pkg/ocm/billing.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func (c *Client) GetBillingAccounts() ([]*v1.CloudAccount, error) {
4343
}
4444

4545
if len(billingAccounts) == 0 {
46-
return billingAccounts, errors.New("No valid billing account associated." +
46+
return billingAccounts, errors.New("no valid billing account associated." +
4747
" Go to https://console.aws.amazon.com/rosa/home#/get-started" +
4848
" to enable ROSA with HCP for your intended billing account." +
49-
" You must have a valid billing account associated to continue.")
49+
" You must have a valid billing account associated to continue")
5050
}
5151

5252
return billingAccounts, nil
@@ -101,10 +101,10 @@ func IsValidAWSAccount(account string) bool {
101101

102102
func ValidateBillingAccount(billingAccount string) error {
103103
if billingAccount == "" {
104-
return fmt.Errorf("A billing account number is required")
104+
return fmt.Errorf("a billing account number is required")
105105
}
106106
if !IsValidAWSAccount(billingAccount) {
107-
return fmt.Errorf("Provided billing account number %s is not valid. "+
107+
return fmt.Errorf("provided billing account number %s is not valid. "+
108108
"Rerun the command with a valid billing account number", billingAccount)
109109
}
110110
return nil

0 commit comments

Comments
 (0)