@@ -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
0 commit comments