@@ -36,24 +36,28 @@ func Execute() {
3636 }
3737}
3838
39- func ProcessOrgEndToEnd (consoleUI runner.ConsoleUI , cmd int , targets []string ) {
39+ func setOpsError () error {
40+ return fmt .Errorf ("error running operations" )
41+ }
42+
43+ func ProcessOrgEndToEnd (consoleUI runner.ConsoleUI , cmd int , targets []string ) error {
4044 ctx := context .Background ()
4145 orgClient := awsorgs .New ()
4246 rootAWSOU , err := ymlparser .NewParser (orgClient ).ParseOrganization (ctx , orgFile )
4347 if err != nil {
4448 consoleUI .Print (fmt .Sprintf ("error: %s" , err ), resource.Account {AccountID : "error" , AccountName : "error" })
45- return
49+ return oops . Wrapf ( err , "ParseOrg" )
4650 }
4751
4852 if rootAWSOU == nil {
4953 consoleUI .Print ("Could not parse AWS Organization" , resource.Account {AccountID : "error" , AccountName : "error" })
50- return
54+ return oops . Errorf ( "No root AWS OU" )
5155 }
5256
5357 mgmtAcct , err := resolveMgmtAcct (ctx , orgClient , rootAWSOU )
5458 if err != nil {
5559 consoleUI .Print (fmt .Sprintf ("Could not fetch AWS Management Account: %s" , err ), resource.Account {AccountID : "error" , AccountName : "error" })
56- return
60+ return oops . Wrapf ( err , "resolveMgmtAcct" )
5761 }
5862
5963 var deployStacks bool
@@ -72,6 +76,11 @@ func ProcessOrgEndToEnd(consoleUI runner.ConsoleUI, cmd int, targets []string) {
7276 }
7377 }
7478
79+ // opsError is the error we return eventually. We want to allow partially
80+ // applied operations across organizations, IaC, and SCPs so we only return
81+ // this error in the end.
82+ var opsError error
83+
7584 if len (targets ) == 0 || deployOrganization {
7685 orgOps := resourceoperation .CollectOrganizationUnitOps (
7786 ctx , consoleUI , orgClient , mgmtAcct , rootAWSOU , cmd ,
@@ -88,6 +97,7 @@ func ProcessOrgEndToEnd(consoleUI runner.ConsoleUI, cmd int, targets []string) {
8897 err := op .Call (ctx )
8998 if err != nil {
9099 consoleUI .Print (fmt .Sprintf ("Error on AWS Organization Operation: %v" , err ), * mgmtAcct )
100+ opsError = setOpsError ()
91101 }
92102 }
93103 }
@@ -105,7 +115,11 @@ func ProcessOrgEndToEnd(consoleUI runner.ConsoleUI, cmd int, targets []string) {
105115 consoleUI .Print ("No accounts to deploy." , * mgmtAcct )
106116 }
107117
108- runIAC (ctx , consoleUI , cmd , accountsToApply )
118+ err := runIAC (ctx , consoleUI , cmd , accountsToApply )
119+ if err != nil {
120+ consoleUI .Print ("No accounts to deploy." , * mgmtAcct )
121+ opsError = setOpsError ()
122+ }
109123 }
110124
111125 if len (targets ) == 0 || deploySCP {
@@ -124,14 +138,17 @@ func ProcessOrgEndToEnd(consoleUI runner.ConsoleUI, cmd int, targets []string) {
124138 err := op .Call (ctx )
125139 if err != nil {
126140 consoleUI .Print (fmt .Sprintf ("Error on SCP Operation: %v" , err ), * scpAdmin )
141+ opsError = setOpsError ()
127142 }
128143 }
129144
130145 if len (scpOps ) == 0 {
131146 consoleUI .Print ("No Service Control Policies to deploy." , * scpAdmin )
132147 }
133148 }
149+
134150 consoleUI .Print ("Done.\n " , * mgmtAcct )
151+ return opsError
135152}
136153
137154func validateTargets () error {
0 commit comments