mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 09:26:14 +00:00
Terraform Cloud integration
This commit is contained in:
@@ -1832,33 +1832,59 @@ const syncSecretsTerraformCloud = async ({
|
|||||||
accessToken: string;
|
accessToken: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
// const entries = Object.entries(secrets);
|
const payload = Object.entries(secrets).map(([key, value]) => {
|
||||||
|
const payloadObj = {
|
||||||
|
data: {
|
||||||
|
type: 'vars',
|
||||||
|
attributes: {
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
category: `${integration.targetService}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
// const data = entries.map((a: any) => {
|
return standardRequest.post(`${INTEGRATION_TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${integration.appId}/vars`, payloadObj, {
|
||||||
// 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`,
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
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"
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
);
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ export default function TerraformCloudCreateIntegrationPage() {
|
|||||||
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
||||||
const [targetApp, setTargetApp] = useState("");
|
const [targetApp, setTargetApp] = useState("");
|
||||||
const [secretPath, setSecretPath] = useState("/");
|
const [secretPath, setSecretPath] = useState("/");
|
||||||
|
const [variableType, setVariableType] = useState("");
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -66,7 +67,7 @@ export default function TerraformCloudCreateIntegrationPage() {
|
|||||||
sourceEnvironment: selectedSourceEnvironment,
|
sourceEnvironment: selectedSourceEnvironment,
|
||||||
targetEnvironment: null,
|
targetEnvironment: null,
|
||||||
targetEnvironmentId: null,
|
targetEnvironmentId: null,
|
||||||
targetService: null,
|
targetService: variableType,
|
||||||
targetServiceId: null,
|
targetServiceId: null,
|
||||||
owner: null,
|
owner: null,
|
||||||
path: null,
|
path: null,
|
||||||
@@ -82,6 +83,11 @@ export default function TerraformCloudCreateIntegrationPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const variableTypes = [
|
||||||
|
{ name: "env" },
|
||||||
|
{ name: "terraform" }
|
||||||
|
]
|
||||||
|
|
||||||
return integrationAuth &&
|
return integrationAuth &&
|
||||||
workspace &&
|
workspace &&
|
||||||
selectedSourceEnvironment &&
|
selectedSourceEnvironment &&
|
||||||
@@ -113,6 +119,24 @@ export default function TerraformCloudCreateIntegrationPage() {
|
|||||||
placeholder="Provide a path, default is /"
|
placeholder="Provide a path, default is /"
|
||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
<FormControl label="Variable Type" className="mt-4">
|
||||||
|
<Select
|
||||||
|
value={variableType}
|
||||||
|
onValueChange={(val) => setVariableType(val)}
|
||||||
|
className="w-full border border-mineshaft-500"
|
||||||
|
>
|
||||||
|
{
|
||||||
|
variableTypes.map((variable) => (
|
||||||
|
<SelectItem
|
||||||
|
value={variable.name}
|
||||||
|
key={`target-app-${variable.name}`}
|
||||||
|
>
|
||||||
|
{variable.name}
|
||||||
|
</SelectItem>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
<FormControl label="Terraform Cloud Project" className="mt-4">
|
<FormControl label="Terraform Cloud Project" className="mt-4">
|
||||||
<Select
|
<Select
|
||||||
value={targetApp}
|
value={targetApp}
|
||||||
|
|||||||
Reference in New Issue
Block a user