mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 08:27:22 +00:00
Terraform Cloud integration
This commit is contained in:
@@ -1832,28 +1832,81 @@ const syncSecretsTerraformCloud = async ({
|
|||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
Object.entries(secrets).map( async ([key, value]) =>
|
// get secrets from Terraform Cloud
|
||||||
await standardRequest.post(
|
const getSecretsRes = (
|
||||||
`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`,
|
await standardRequest.get(`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`,
|
||||||
{
|
{
|
||||||
data: {
|
headers: {
|
||||||
type: 'vars',
|
Authorization: `Bearer ${accessToken}`,
|
||||||
attributes: {
|
Accept: "application/json",
|
||||||
key,
|
},
|
||||||
value,
|
}
|
||||||
category: `${integration.targetService}`,
|
)).data.data;
|
||||||
|
|
||||||
|
// create or update secrets on Terraform Cloud
|
||||||
|
for await (const key of Object.keys(secrets)) {
|
||||||
|
const existingSecret = getSecretsRes.find((sec: any) => sec.attributes.key == key);
|
||||||
|
|
||||||
|
if (!existingSecret) {
|
||||||
|
await standardRequest.post(
|
||||||
|
`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`,
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
type: "vars",
|
||||||
|
attributes: {
|
||||||
|
key,
|
||||||
|
value: secrets[key],
|
||||||
|
category: integration.targetService,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
{
|
||||||
{
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
"Content-Type": "application/vnd.api+json",
|
||||||
|
Accept: "application/vnd.api+json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (secrets[key] !== existingSecret.attributes.value) {
|
||||||
|
|
||||||
|
await standardRequest.patch(
|
||||||
|
`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars/${existingSecret.id}`,
|
||||||
|
{
|
||||||
|
data: {
|
||||||
|
type: "vars",
|
||||||
|
id: existingSecret.id,
|
||||||
|
attributes: {
|
||||||
|
...existingSecret,
|
||||||
|
value: secrets[existingSecret.attributes.key],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${accessToken}`,
|
||||||
|
"Content-Type": "application/vnd.api+json",
|
||||||
|
Accept: "application/vnd.api+json",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete secrets from Terraform Cloud
|
||||||
|
for await (const sec of getSecretsRes) {
|
||||||
|
if (!(sec.attributes.key in secrets)) {
|
||||||
|
await standardRequest.delete(`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars/${sec.id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${accessToken}`,
|
Authorization: `Bearer ${accessToken}`,
|
||||||
"Content-Type": "application/vnd.api+json",
|
"Content-Type": "application/vnd.api+json",
|
||||||
Accept: "application/vnd.api+json",
|
Accept: "application/vnd.api+json",
|
||||||
},
|
},
|
||||||
}
|
})
|
||||||
)
|
}
|
||||||
)
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user