From edef22d28e1f9b350d55b7d044de529d28126ef9 Mon Sep 17 00:00:00 2001 From: Andrew Atimapre Date: Tue, 18 Jul 2023 23:14:41 +0100 Subject: [PATCH] Terraform Cloud integration --- backend/src/integrations/sync.ts | 72 +++++++++----------------------- 1 file changed, 20 insertions(+), 52 deletions(-) diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts index 296549246..c5bd1de85 100644 --- a/backend/src/integrations/sync.ts +++ b/backend/src/integrations/sync.ts @@ -1832,60 +1832,28 @@ const syncSecretsTerraformCloud = async ({ accessToken: string; }) => { - const payload = Object.entries(secrets).map(([key, value]) => { - const payloadObj = { - data: { - type: 'vars', - attributes: { - key, - value, - category: `${integration.targetService}`, + Object.entries(secrets).map( async ([key, value]) => + await standardRequest.post( + `${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`, + { + data: { + type: 'vars', + attributes: { + key, + value, + category: `${integration.targetService}`, + }, }, }, - }; - - return standardRequest.post(`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`, payloadObj, { - headers: { - Authorization: `Bearer ${accessToken}`, - "Content-Type": "application/vnd.api+json", - "Accept": "application/vnd.api+json" - }, - }); - }); - - Promise.all(payload); - - - // get secrets from Terraform Cloud - // const getSecretsRes = ( - // await standardRequest.get( - // `${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.app}/vars`, - // { - // headers: { - // Authorization: `Bearer ${accessToken}`, - // "Content-Type": "application/vnd.api+json", - // "Accept": "application/vnd.api+json" - // }, - // } - // ) - // ).data; - - // delete secrets from Terraform Cloud - // getSecretsRes.forEach(async (data: any) => { - // if (!(data.attributes.name in secrets)) { - // await standardRequest.delete( - // `${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.app}/vars/${data.id}`, - // { - // headers: { - // Authorization: `Bearer ${accessToken}`, - // "Content-Type": "application/vnd.api+json", - // "Accept": "application/vnd.api+json" - // }, - // } - // ); - // } - // }); - + { + headers: { + Authorization: `Bearer ${accessToken}`, + "Content-Type": "application/vnd.api+json", + Accept: "application/vnd.api+json", + }, + } + ) + ) }; /**