mirror of
https://github.com/Infisical/infisical.git
synced 2025-03-29 22:02:57 +00:00
Terraform Cloud integration
This commit is contained in:
@ -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"
|
||||
// },
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// });
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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 /"
|
||||
/>
|
||||
</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">
|
||||
<Select
|
||||
value={targetApp}
|
||||
|
Reference in New Issue
Block a user