diff --git a/backend/src/integrations/sync.ts b/backend/src/integrations/sync.ts index 66c584385..95478fc5b 100644 --- a/backend/src/integrations/sync.ts +++ b/backend/src/integrations/sync.ts @@ -1832,33 +1832,59 @@ const syncSecretsTerraformCloud = async ({ accessToken: string; }) => { - // const entries = Object.entries(secrets); - - // const data = entries.map((a: any) => { - // const obj = { - // "data": { - // "attributes": { - // "key": a.key, - // "value": a.value, - // "category": "env" - // } - // } - // } - // return Object.fromEntries(obj) - // }) - - console.log("Testing Out:", secrets) - - await standardRequest.post( - `${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`, - {}, - { + const payload = Object.entries(secrets).map(([key, value]) => { + const payloadObj = { + 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" + "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?.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" + // }, + // } + // ); + // } + // }); + }; /** diff --git a/frontend/src/pages/integrations/terraform-cloud/create.tsx b/frontend/src/pages/integrations/terraform-cloud/create.tsx index 826f0eb16..9e46f4c97 100644 --- a/frontend/src/pages/integrations/terraform-cloud/create.tsx +++ b/frontend/src/pages/integrations/terraform-cloud/create.tsx @@ -32,6 +32,7 @@ export default function TerraformCloudCreateIntegrationPage() { const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState(""); const [targetApp, setTargetApp] = useState(""); const [secretPath, setSecretPath] = useState("/"); + const [variableType, setVariableType] = useState(""); const [isLoading, setIsLoading] = useState(false); useEffect(() => { @@ -66,7 +67,7 @@ export default function TerraformCloudCreateIntegrationPage() { sourceEnvironment: selectedSourceEnvironment, targetEnvironment: null, targetEnvironmentId: null, - targetService: null, + targetService: variableType, targetServiceId: null, owner: null, path: null, @@ -82,6 +83,11 @@ export default function TerraformCloudCreateIntegrationPage() { } }; + const variableTypes = [ + { name: "env" }, + { name: "terraform" } + ] + return integrationAuth && workspace && selectedSourceEnvironment && @@ -113,6 +119,24 @@ export default function TerraformCloudCreateIntegrationPage() { placeholder="Provide a path, default is /" /> + + +