mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Terraform Cloud Secret Sync Integration
This commit is contained in:
@@ -1791,9 +1791,10 @@ export const SecretSyncs = {
|
||||
},
|
||||
TERRAFORM_CLOUD: {
|
||||
org: "The ID of the Terraform Cloud org to sync secrets to.",
|
||||
project: "The ID of the Terraform Cloud project to sync secrets to.",
|
||||
workspace: "The ID of the Terraform Cloud workspace to sync secrets to.",
|
||||
scope: "The Terraform Cloud scope that secrets should be synced to."
|
||||
destinationName: "The name of the Terraform Cloud variable set / workspace to sync secrets to.",
|
||||
destinationId: "The ID of the Terraform Cloud variable set / workspace to sync secrets to.",
|
||||
scope: "The Terraform Cloud scope that secrets should be synced to.",
|
||||
category: "The Terraform Cloud category that secrets should be synced to."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import { AppConnection } from "@app/services/app-connection/app-connection-enums
|
||||
import {
|
||||
CreateTerraformCloudConnectionSchema,
|
||||
SanitizedTerraformCloudConnectionSchema,
|
||||
TerraformCloudOrgWithApps,
|
||||
TTerraformCloudOrganization,
|
||||
UpdateTerraformCloudConnectionSchema
|
||||
} from "@app/services/app-connection/terraform-cloud";
|
||||
import { AuthMode } from "@app/services/auth/auth-type";
|
||||
@@ -38,10 +38,12 @@ export const registerTerraformCloudConnectionRouter = async (server: FastifyZodP
|
||||
.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
projects: z
|
||||
variableSets: z
|
||||
.object({
|
||||
id: z.string(),
|
||||
name: z.string()
|
||||
name: z.string(),
|
||||
description: z.string().optional(),
|
||||
global: z.boolean().optional()
|
||||
})
|
||||
.array(),
|
||||
workspaces: z
|
||||
@@ -58,7 +60,7 @@ export const registerTerraformCloudConnectionRouter = async (server: FastifyZodP
|
||||
handler: async (req) => {
|
||||
const { connectionId } = req.params;
|
||||
|
||||
const organizations: TerraformCloudOrgWithApps[] =
|
||||
const organizations: TTerraformCloudOrganization[] =
|
||||
await server.services.appConnection.terraformCloud.listOrganizations(connectionId, req.permission);
|
||||
|
||||
return organizations;
|
||||
|
||||
@@ -38,6 +38,12 @@ import {
|
||||
THumanitecConnectionInput,
|
||||
TValidateHumanitecConnectionCredentials
|
||||
} from "./humanitec";
|
||||
import {
|
||||
TTerraformCloudConnection,
|
||||
TTerraformCloudConnectionConfig,
|
||||
TTerraformCloudConnectionInput,
|
||||
TValidateTerraformCloudConnectionCredentials
|
||||
} from "./terraform-cloud";
|
||||
|
||||
export type TAppConnection = { id: string } & (
|
||||
| TAwsConnection
|
||||
@@ -47,6 +53,7 @@ export type TAppConnection = { id: string } & (
|
||||
| TAzureAppConfigurationConnection
|
||||
| TDatabricksConnection
|
||||
| THumanitecConnection
|
||||
| TTerraformCloudConnection
|
||||
);
|
||||
|
||||
export type TAppConnectionInput = { id: string } & (
|
||||
@@ -57,6 +64,7 @@ export type TAppConnectionInput = { id: string } & (
|
||||
| TAzureAppConfigurationConnectionInput
|
||||
| TDatabricksConnectionInput
|
||||
| THumanitecConnectionInput
|
||||
| TTerraformCloudConnectionInput
|
||||
);
|
||||
|
||||
export type TCreateAppConnectionDTO = Pick<
|
||||
@@ -75,7 +83,8 @@ export type TAppConnectionConfig =
|
||||
| TAzureKeyVaultConnectionConfig
|
||||
| TAzureAppConfigurationConnectionConfig
|
||||
| TDatabricksConnectionConfig
|
||||
| THumanitecConnectionConfig;
|
||||
| THumanitecConnectionConfig
|
||||
| TTerraformCloudConnectionConfig;
|
||||
|
||||
export type TValidateAppConnectionCredentials =
|
||||
| TValidateAwsConnectionCredentials
|
||||
@@ -84,7 +93,8 @@ export type TValidateAppConnectionCredentials =
|
||||
| TValidateAzureKeyVaultConnectionCredentials
|
||||
| TValidateAzureAppConfigurationConnectionCredentials
|
||||
| TValidateDatabricksConnectionCredentials
|
||||
| TValidateHumanitecConnectionCredentials;
|
||||
| TValidateHumanitecConnectionCredentials
|
||||
| TValidateTerraformCloudConnectionCredentials;
|
||||
|
||||
export type TListAwsConnectionKmsKeys = {
|
||||
connectionId: string;
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
TTerraformCloudConnection,
|
||||
TTerraformCloudConnectionConfig,
|
||||
TTerraformCloudOrganization,
|
||||
TTerraformCloudProject,
|
||||
TTerraformCloudVariableSet,
|
||||
TTerraformCloudWorkspace
|
||||
} from "./terraform-cloud-connection-types";
|
||||
|
||||
@@ -81,12 +81,12 @@ export const listOrganizations = async (
|
||||
}
|
||||
|
||||
const orgEntities = orgsResponse.data.data;
|
||||
const orgsWithProjectsAndWorkspaces: TTerraformCloudOrganization[] = [];
|
||||
const orgsWithVariableSetsAndWorkspaces: TTerraformCloudOrganization[] = [];
|
||||
|
||||
const projectPromises = orgEntities.map((org) =>
|
||||
const variableSetPromises = orgEntities.map((org) =>
|
||||
request
|
||||
.get<{ data: { id: string; attributes: { name: string } }[] }>(
|
||||
`${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${org.id}/projects`,
|
||||
.get<{ data: { id: string; attributes: { name: string; description?: string; global?: boolean } }[] }>(
|
||||
`${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${org.id}/varsets`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiToken}`,
|
||||
@@ -111,19 +111,21 @@ export const listOrganizations = async (
|
||||
.catch(() => ({ data: { data: [] } }))
|
||||
);
|
||||
|
||||
const [projectResponses, workspaceResponses] = await Promise.all([
|
||||
Promise.all(projectPromises),
|
||||
const [variableSetResponses, workspaceResponses] = await Promise.all([
|
||||
Promise.all(variableSetPromises),
|
||||
Promise.all(workspacePromises)
|
||||
]);
|
||||
|
||||
for (let i = 0; i < orgEntities.length; i += 1) {
|
||||
const org = orgEntities[i];
|
||||
const projectsData = projectResponses[i].data?.data || [];
|
||||
const variableSetsData = variableSetResponses[i].data?.data || [];
|
||||
const workspacesData = workspaceResponses[i].data?.data || [];
|
||||
|
||||
const projects: TTerraformCloudProject[] = projectsData.map((project) => ({
|
||||
id: project.id,
|
||||
name: project.attributes.name
|
||||
const variableSets: TTerraformCloudVariableSet[] = variableSetsData.map((varSet) => ({
|
||||
id: varSet.id,
|
||||
name: varSet.attributes.name,
|
||||
description: varSet.attributes.description,
|
||||
global: varSet.attributes.global
|
||||
}));
|
||||
|
||||
const workspaces: TTerraformCloudWorkspace[] = workspacesData.map((workspace) => ({
|
||||
@@ -131,13 +133,13 @@ export const listOrganizations = async (
|
||||
name: workspace.attributes.name
|
||||
}));
|
||||
|
||||
orgsWithProjectsAndWorkspaces.push({
|
||||
orgsWithVariableSetsAndWorkspaces.push({
|
||||
id: org.id,
|
||||
name: org.attributes.name,
|
||||
projects,
|
||||
variableSets,
|
||||
workspaces
|
||||
});
|
||||
}
|
||||
|
||||
return orgsWithProjectsAndWorkspaces;
|
||||
return orgsWithVariableSetsAndWorkspaces;
|
||||
};
|
||||
|
||||
@@ -39,9 +39,11 @@ export type TerraformCloudOrgWithApps = TerraformCloudOrg & {
|
||||
apps: TerraformCloudApp[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudProject = {
|
||||
export type TTerraformCloudVariableSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
global?: boolean;
|
||||
};
|
||||
|
||||
export type TTerraformCloudWorkspace = {
|
||||
@@ -52,15 +54,15 @@ export type TTerraformCloudWorkspace = {
|
||||
export type TTerraformCloudOrganization = {
|
||||
id: string;
|
||||
name: string;
|
||||
projects: TTerraformCloudProject[];
|
||||
variableSets: TTerraformCloudVariableSet[];
|
||||
workspaces: TTerraformCloudWorkspace[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionOrganization = TTerraformCloudOrganization;
|
||||
export type TTerraformCloudConnectionProject = TTerraformCloudProject;
|
||||
export type TTerraformCloudConnectionVariableSet = TTerraformCloudVariableSet;
|
||||
export type TTerraformCloudConnectionWorkspace = TTerraformCloudWorkspace;
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
Project = "project",
|
||||
VariableSet = "variableSet",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
export enum TerraformCloudSyncScope {
|
||||
Project = "project",
|
||||
VariableSet = "variable-set",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
export enum TerraformCloudSyncCategory {
|
||||
Environment = "env",
|
||||
Terraform = "terraform"
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ import { request } from "@app/lib/config/request";
|
||||
import { logger } from "@app/lib/logger";
|
||||
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
|
||||
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
|
||||
import { SECRET_SYNC_NAME_MAP } from "@app/services/secret-sync/secret-sync-maps";
|
||||
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
|
||||
import { TerraformCloudSyncScope } from "./terraform-cloud-sync-enums";
|
||||
import {
|
||||
TerraformCloudApiResponse,
|
||||
@@ -25,10 +25,14 @@ const getTerraformCloudVariables = async (
|
||||
} = secretSync;
|
||||
|
||||
let url;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.Project) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/projects/${destinationConfig.project}/vars`;
|
||||
let source: TerraformCloudVariable["source"];
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars`;
|
||||
source = "varset";
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/workspaces/${destinationConfig.workspace}/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars`;
|
||||
source = "workspace";
|
||||
}
|
||||
|
||||
const response = await request.get<TerraformCloudApiResponse<TerraformCloudApiVariable[]>>(url, {
|
||||
@@ -49,7 +53,7 @@ const getTerraformCloudVariables = async (
|
||||
sensitive: variable.attributes.sensitive,
|
||||
description: variable.attributes.description || "",
|
||||
category: variable.attributes.category,
|
||||
source: destinationConfig.scope === TerraformCloudSyncScope.Project ? "project" : "workspace"
|
||||
source
|
||||
}));
|
||||
|
||||
return variables;
|
||||
@@ -68,10 +72,11 @@ const deleteVariable = async (
|
||||
|
||||
try {
|
||||
let url;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.Project) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/projects/${destinationConfig.project}/vars/${variable.id}`;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars/${variable.id}`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/workspaces/${destinationConfig.workspace}/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars/${variable.id}`;
|
||||
}
|
||||
|
||||
await request.delete(url, {
|
||||
@@ -104,10 +109,11 @@ const createVariable = async (
|
||||
} = secretSync;
|
||||
|
||||
let url;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.Project) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/projects/${destinationConfig.project}/vars`;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/workspaces/${destinationConfig.workspace}/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars`;
|
||||
}
|
||||
|
||||
await request.post(
|
||||
@@ -119,9 +125,8 @@ const createVariable = async (
|
||||
key,
|
||||
value: secretMap[key].value,
|
||||
description: secretMap[key].comment || "",
|
||||
category: "env",
|
||||
sensitive: true,
|
||||
hcl: false
|
||||
category: secretSync.destinationConfig.category,
|
||||
sensitive: true
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -156,10 +161,11 @@ const updateVariable = async (
|
||||
} = secretSync;
|
||||
|
||||
let url;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.Project) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/projects/${destinationConfig.project}/vars/${variable.id}`;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars/${variable.id}`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/organizations/${destinationConfig.org}/workspaces/${destinationConfig.workspace}/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars/${variable.id}`;
|
||||
}
|
||||
|
||||
await request.patch(
|
||||
@@ -170,7 +176,8 @@ const updateVariable = async (
|
||||
id: variable.id,
|
||||
attributes: {
|
||||
value: secretMap[variable.key].value,
|
||||
description: secretMap[variable.key].comment || ""
|
||||
description: secretMap[variable.key].comment || "",
|
||||
category: secretSync.destinationConfig.category
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -9,24 +9,39 @@ import {
|
||||
GenericUpdateSecretSyncFieldsSchema
|
||||
} from "@app/services/secret-sync/secret-sync-schemas";
|
||||
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
|
||||
import { TerraformCloudSyncScope } from "@app/services/secret-sync/terraform-cloud/terraform-cloud-sync-enums";
|
||||
import {
|
||||
TerraformCloudSyncCategory,
|
||||
TerraformCloudSyncScope
|
||||
} from "@app/services/secret-sync/terraform-cloud/terraform-cloud-sync-enums";
|
||||
|
||||
const TerraformCloudSyncDestinationConfigSchema = z.discriminatedUnion("scope", [
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.Project).describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.scope),
|
||||
scope: z
|
||||
.literal(TerraformCloudSyncScope.VariableSet)
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.scope),
|
||||
org: z.string().min(1, "Org ID is required").describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.org),
|
||||
project: z
|
||||
destinationName: z
|
||||
.string()
|
||||
.min(1, "Project ID is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.project)
|
||||
.min(1, "Variable set name is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationName),
|
||||
destinationId: z
|
||||
.string()
|
||||
.min(1, "Variable set ID is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationId),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory).describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.category)
|
||||
}),
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.Workspace).describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.scope),
|
||||
org: z.string().min(1, "Org ID is required").describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.org),
|
||||
workspace: z
|
||||
destinationName: z
|
||||
.string()
|
||||
.min(1, "Workspace name is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationName),
|
||||
destinationId: z
|
||||
.string()
|
||||
.min(1, "Workspace ID is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.workspace)
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationId),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory).describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.category)
|
||||
})
|
||||
]);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export type TerraformCloudVariable = {
|
||||
sensitive: boolean;
|
||||
description: string;
|
||||
category: "terraform" | "env";
|
||||
source: "project" | "workspace";
|
||||
source: "varset" | "workspace";
|
||||
};
|
||||
|
||||
export type TerraformCloudApiResponse<T> = {
|
||||
@@ -83,8 +83,3 @@ export type TerraformCloudApiResponse<T> = {
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
Project = "project",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
@@ -7,9 +7,10 @@ import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/Se
|
||||
import { FilterableSelect, FormControl, Select, SelectItem, Tooltip } from "@app/components/v2";
|
||||
import {
|
||||
TERRAFORM_CLOUD_SYNC_SCOPES,
|
||||
TerraformCloudSyncCategory,
|
||||
TerraformCloudSyncScope,
|
||||
TTerraformCloudConnectionOrganization,
|
||||
TTerraformCloudConnectionProject,
|
||||
TTerraformCloudConnectionVariableSet,
|
||||
TTerraformCloudConnectionWorkspace,
|
||||
useTerraformCloudConnectionListOrganizations
|
||||
} from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
@@ -32,7 +33,7 @@ export const TerraformCloudSyncFields = () => {
|
||||
});
|
||||
|
||||
const selectedOrg = organizations?.find((org) => org.id === currentOrg);
|
||||
const projects = selectedOrg?.projects || [];
|
||||
const variableSets = selectedOrg?.variableSets || [];
|
||||
const workspaces = selectedOrg?.workspaces || [];
|
||||
|
||||
return (
|
||||
@@ -40,8 +41,8 @@ export const TerraformCloudSyncFields = () => {
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.org", "");
|
||||
setValue("destinationConfig.project", "");
|
||||
setValue("destinationConfig.workspace", "");
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
@@ -61,8 +62,8 @@ export const TerraformCloudSyncFields = () => {
|
||||
onChange(
|
||||
(option as SingleValue<TTerraformCloudConnectionOrganization>)?.id ?? null
|
||||
);
|
||||
setValue("destinationConfig.project", "");
|
||||
setValue("destinationConfig.workspace", "");
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
}}
|
||||
options={organizations}
|
||||
placeholder="Select an organization..."
|
||||
@@ -72,10 +73,38 @@ export const TerraformCloudSyncFields = () => {
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.category"
|
||||
control={control}
|
||||
defaultValue={TerraformCloudSyncCategory.Environment}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Category"
|
||||
>
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
className="w-full border border-mineshaft-500 capitalize"
|
||||
position="popper"
|
||||
defaultValue={TerraformCloudSyncCategory.Environment}
|
||||
placeholder="Select category..."
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(TerraformCloudSyncCategory).map((category) => (
|
||||
<SelectItem className="capitalize" value={category} key={category}>
|
||||
{category.replace("-", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.scope"
|
||||
control={control}
|
||||
defaultValue={TerraformCloudSyncScope.Project}
|
||||
defaultValue={TerraformCloudSyncScope.VariableSet}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
@@ -106,12 +135,8 @@ export const TerraformCloudSyncFields = () => {
|
||||
value={value}
|
||||
onValueChange={(val) => {
|
||||
onChange(val);
|
||||
// Reset either project or workspace based on which scope was selected
|
||||
if (val === TerraformCloudSyncScope.Project) {
|
||||
setValue("destinationConfig.workspace", "");
|
||||
} else {
|
||||
setValue("destinationConfig.project", "");
|
||||
}
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
}}
|
||||
className="w-full border border-mineshaft-500 capitalize"
|
||||
position="popper"
|
||||
@@ -127,22 +152,22 @@ export const TerraformCloudSyncFields = () => {
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
{currentScope === TerraformCloudSyncScope.Project && (
|
||||
{currentScope === TerraformCloudSyncScope.VariableSet && (
|
||||
<Controller
|
||||
name="destinationConfig.project"
|
||||
name="destinationConfig.destinationId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="Project"
|
||||
label="Variable Set"
|
||||
helperText={
|
||||
<Tooltip
|
||||
className="max-w-md"
|
||||
content="Ensure that the project exists in the selected organization and the service account used on this connection has write permissions for the specified project."
|
||||
content="Ensure that the variable set exists in the selected organization and the service account used on this connection has write permissions for the specified variable set."
|
||||
>
|
||||
<div>
|
||||
<span>Don't see the project you're looking for?</span>{" "}
|
||||
<span>Don't see the variable set you're looking for?</span>{" "}
|
||||
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
@@ -152,12 +177,20 @@ export const TerraformCloudSyncFields = () => {
|
||||
menuPlacement="top"
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId) && Boolean(currentOrg)}
|
||||
isDisabled={!connectionId || !currentOrg}
|
||||
value={projects.find((project) => project.id === value) ?? null}
|
||||
value={variableSets.find((variableSet) => variableSet.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
onChange((option as SingleValue<TTerraformCloudConnectionProject>)?.id ?? null);
|
||||
const selectedOption =
|
||||
option as SingleValue<TTerraformCloudConnectionVariableSet>;
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.destinationName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
}
|
||||
}}
|
||||
options={projects}
|
||||
placeholder="Select a project..."
|
||||
options={variableSets}
|
||||
placeholder="Select a variable set..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
@@ -167,7 +200,7 @@ export const TerraformCloudSyncFields = () => {
|
||||
)}
|
||||
{currentScope === TerraformCloudSyncScope.Workspace && (
|
||||
<Controller
|
||||
name="destinationConfig.workspace"
|
||||
name="destinationConfig.destinationId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
@@ -192,7 +225,14 @@ export const TerraformCloudSyncFields = () => {
|
||||
isDisabled={!connectionId || !currentOrg}
|
||||
value={workspaces.find((workspace) => workspace.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
onChange((option as SingleValue<TTerraformCloudConnectionWorkspace>)?.id ?? null);
|
||||
const selectedOption = option as SingleValue<TTerraformCloudConnectionWorkspace>;
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.destinationName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
}
|
||||
}}
|
||||
options={workspaces}
|
||||
placeholder="Select a workspace..."
|
||||
|
||||
@@ -8,19 +8,20 @@ import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
export const TerraformCloudSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.TerraformCloud }>();
|
||||
const orgId = watch("destinationConfig.org");
|
||||
const projectId = watch("destinationConfig.project");
|
||||
const workspaceId = watch("destinationConfig.workspace");
|
||||
const destinationName = watch("destinationConfig.destinationName");
|
||||
const scope = watch("destinationConfig.scope");
|
||||
const category = watch("destinationConfig.category");
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncLabel label="Organization">{orgId}</SecretSyncLabel>
|
||||
{scope === TerraformCloudSyncScope.Project && (
|
||||
<SecretSyncLabel label="Project">{projectId}</SecretSyncLabel>
|
||||
{scope === TerraformCloudSyncScope.VariableSet && (
|
||||
<SecretSyncLabel label="Variable Set">{destinationName}</SecretSyncLabel>
|
||||
)}
|
||||
{scope === TerraformCloudSyncScope.Workspace && (
|
||||
<SecretSyncLabel label="Workspace">{workspaceId}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Workspace">{destinationName}</SecretSyncLabel>
|
||||
)}
|
||||
<SecretSyncLabel label="Category">{category}</SecretSyncLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import { TerraformCloudSyncScope } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import {
|
||||
TerraformCloudSyncCategory,
|
||||
TerraformCloudSyncScope
|
||||
} from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const TerraformCloudSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
@@ -9,14 +12,18 @@ export const TerraformCloudSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
destination: z.literal(SecretSync.TerraformCloud),
|
||||
destinationConfig: z.discriminatedUnion("scope", [
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.Project),
|
||||
scope: z.literal(TerraformCloudSyncScope.VariableSet),
|
||||
org: z.string().trim().min(1, "Organization required"),
|
||||
project: z.string().trim().min(1, "Project required")
|
||||
destinationId: z.string().trim().min(1, "Variable set id required"),
|
||||
destinationName: z.string().trim().min(1, "Variable set name required"),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory)
|
||||
}),
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.Workspace),
|
||||
org: z.string().trim().min(1, "Organization required"),
|
||||
workspace: z.string().trim().min(1, "Workspace required")
|
||||
destinationId: z.string().trim().min(1, "Workspace id required"),
|
||||
destinationName: z.string().trim().min(1, "Workspace name required"),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory)
|
||||
})
|
||||
])
|
||||
})
|
||||
|
||||
@@ -8,7 +8,8 @@ import {
|
||||
AzureKeyVaultConnectionMethod,
|
||||
GcpConnectionMethod,
|
||||
GitHubConnectionMethod,
|
||||
TAppConnection
|
||||
TAppConnection,
|
||||
TerraformCloudConnectionMethod
|
||||
} from "@app/hooks/api/appConnections/types";
|
||||
import { DatabricksConnectionMethod } from "@app/hooks/api/appConnections/types/databricks-connection";
|
||||
import { HumanitecConnectionMethod } from "@app/hooks/api/appConnections/types/humanitec-connection";
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
export type TTerraformCloudOrganization = {
|
||||
name: string;
|
||||
id: string;
|
||||
projects: TTerraformCloudProject[];
|
||||
variableSets: TTerraformCloudVariableSet[];
|
||||
workspaces: TTerraformCloudWorkspace[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudProject = {
|
||||
export type TTerraformCloudVariableSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
@@ -18,13 +18,15 @@ export type TTerraformCloudWorkspace = {
|
||||
export type TTerraformCloudConnectionOrganization = {
|
||||
id: string;
|
||||
name: string;
|
||||
projects: TTerraformCloudConnectionProject[];
|
||||
variableSets: TTerraformCloudConnectionVariableSet[];
|
||||
workspaces: TTerraformCloudConnectionWorkspace[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionProject = {
|
||||
export type TTerraformCloudConnectionVariableSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
global: boolean;
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionWorkspace = {
|
||||
@@ -33,14 +35,19 @@ export type TTerraformCloudConnectionWorkspace = {
|
||||
};
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
Project = "project",
|
||||
VariableSet = "variable-set",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
export enum TerraformCloudSyncCategory {
|
||||
Environment = "env",
|
||||
Terraform = "terraform"
|
||||
}
|
||||
|
||||
export const TERRAFORM_CLOUD_SYNC_SCOPES = {
|
||||
[TerraformCloudSyncScope.Project]: {
|
||||
name: "Project",
|
||||
description: "Sync secrets to a specific project in Terraform Cloud."
|
||||
[TerraformCloudSyncScope.VariableSet]: {
|
||||
name: "Variable Set",
|
||||
description: "Sync secrets to a specific variable set in Terraform Cloud."
|
||||
},
|
||||
[TerraformCloudSyncScope.Workspace]: {
|
||||
name: "Workspace",
|
||||
|
||||
@@ -2,18 +2,24 @@ import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { TRootSecretSync } from "@app/hooks/api/secretSyncs/types/root-sync";
|
||||
|
||||
import { TerraformCloudSyncCategory } from "../../appConnections/terraform-cloud";
|
||||
|
||||
export type TTerraformCloudSync = TRootSecretSync & {
|
||||
destination: SecretSync.TerraformCloud;
|
||||
destinationConfig:
|
||||
| {
|
||||
scope: TerraformCloudSyncScope.Project;
|
||||
scope: TerraformCloudSyncScope.VariableSet;
|
||||
org: string;
|
||||
project: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
destinationId: string;
|
||||
destinationName: string;
|
||||
}
|
||||
| {
|
||||
scope: TerraformCloudSyncScope.Workspace;
|
||||
org: string;
|
||||
workspace: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
destinationId: string;
|
||||
destinationName: string;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.TerraformCloud;
|
||||
@@ -23,6 +29,6 @@ export type TTerraformCloudSync = TRootSecretSync & {
|
||||
};
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
Project = "project",
|
||||
VariableSet = "variable-set",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { TerraformCloudSyncScope } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync, TSecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import {
|
||||
GitHubSyncScope,
|
||||
@@ -76,10 +75,7 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
break;
|
||||
case SecretSync.TerraformCloud:
|
||||
primaryText = destinationConfig.org;
|
||||
secondaryText =
|
||||
destinationConfig.scope === TerraformCloudSyncScope.Project
|
||||
? destinationConfig.project
|
||||
: destinationConfig.workspace;
|
||||
secondaryText = destinationConfig.destinationName;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Col Values ${destination}`);
|
||||
|
||||
@@ -15,11 +15,13 @@ export const TerraformCloudSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
|
||||
let Components: ReactNode;
|
||||
switch (destinationConfig.scope) {
|
||||
case TerraformCloudSyncScope.Project:
|
||||
case TerraformCloudSyncScope.VariableSet:
|
||||
Components = (
|
||||
<>
|
||||
<SecretSyncLabel label="Organization">{destinationConfig.org}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Project">{destinationConfig.project}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Variable Set">
|
||||
{destinationConfig.destinationName}
|
||||
</SecretSyncLabel>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
@@ -27,7 +29,7 @@ export const TerraformCloudSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
Components = (
|
||||
<>
|
||||
<SecretSyncLabel label="Organization">{destinationConfig.org}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Workspace">{destinationConfig.workspace}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Workspace">{destinationConfig.destinationName}</SecretSyncLabel>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user