Explorar o código

read infra status and handle errors

Alexander Belanger %!s(int64=4) %!d(string=hai) anos
pai
achega
efca5c6a74

+ 3 - 1
dashboard/src/components/ProvisionerStatus.tsx

@@ -12,7 +12,9 @@ type Props = {
 export interface TFModule {
   id: number
   kind: string
-  resources: TFResource[]
+  status: string
+  // optional resources, if not created
+  resources?: TFResource[]
 }
 
 export interface TFResourceError {

+ 38 - 34
dashboard/src/main/home/onboarding/steps/ProvisionResources/forms/SharedStatus.tsx

@@ -56,42 +56,46 @@ export const SharedStatus: React.FC<{
         })
   
         var modules : TFModule[] = []
-  
+        
         // query for desired and current state, and convert to tf module
         matchedInfras.forEach((infra : any) => {
-          api.getInfraDesired("<token>", {}, { project_id: project_id, infra_id: infra?.id }).then((resDesired) => {
-            api.getInfraCurrent("<token>", {}, { project_id: project_id, infra_id: infra?.id }).then((resCurrent) => {
-              var desired = resDesired.data
-              var current = resCurrent.data
-  
-              // convert current state to a lookup table
-              var currentMap : Map<string, string> = new Map()
-  
-              current?.resources?.forEach((val : any) => {
-                currentMap.set(val?.type + "." + val?.name, "")
-              })
-  
-              // map desired state to list of resources
-              var resources : TFResource[] = desired?.map((val : any) => {
-                return {
-                  addr: val?.addr,
-                  provisioned: currentMap.has(val?.addr),
-                  errored: {
-                    errored_out: val?.errored?.errored_out,
-                    error_context: val?.errored?.error_context,
-                  },
-                }
-              })
-  
-              var module : TFModule = {
-                id: infra.id,
-                kind: infra.kind,
-                resources: resources,
-              }
-  
-              modules.push(module)
-            })
-          })
+          var module : TFModule = {
+            id: infra.id,
+            kind: infra.kind,
+            status: infra.status,
+          }
+
+          if (infra?.status != "created" && infra?.status != "destroyed") {
+            api.getInfraDesired("<token>", {}, { project_id: project_id, infra_id: infra?.id }).then((resDesired) => {
+              api.getInfraCurrent("<token>", {}, { project_id: project_id, infra_id: infra?.id }).then((resCurrent) => {
+                var desired = resDesired.data
+                var current = resCurrent.data
+    
+                // convert current state to a lookup table
+                var currentMap : Map<string, string> = new Map()
+    
+                current?.resources?.forEach((val : any) => {
+                  currentMap.set(val?.type + "." + val?.name, "")
+                })
+    
+                // map desired state to list of resources
+                var resources : TFResource[] = desired?.map((val : any) => {
+                  return {
+                    addr: val?.addr,
+                    provisioned: currentMap.has(val?.addr),
+                    errored: {
+                      errored_out: val?.errored?.errored_out,
+                      error_context: val?.errored?.error_context,
+                    },
+                  }
+                })
+
+                module.resources = resources
+              }).catch((err) => console.log(err))
+            }).catch((err) => console.log(err))
+          }
+
+          modules.push(module)
         });
   
         setTFModules(modules)