mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 05:27:48 +00:00
Merge pull request #3360 from Infisical/feat/terraformCloudIntegration
Terraform cloud integration
This commit is contained in:
+3
@@ -12,6 +12,7 @@ import { DatabricksSyncFields } from "./DatabricksSyncFields";
|
||||
import { GcpSyncFields } from "./GcpSyncFields";
|
||||
import { GitHubSyncFields } from "./GitHubSyncFields";
|
||||
import { HumanitecSyncFields } from "./HumanitecSyncFields";
|
||||
import { TerraformCloudSyncFields } from "./TerraformCloudSyncFields";
|
||||
import { VercelSyncFields } from "./VercelSyncFields";
|
||||
|
||||
export const SecretSyncDestinationFields = () => {
|
||||
@@ -36,6 +37,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <DatabricksSyncFields />;
|
||||
case SecretSync.Humanitec:
|
||||
return <HumanitecSyncFields />;
|
||||
case SecretSync.TerraformCloud:
|
||||
return <TerraformCloudSyncFields />;
|
||||
case SecretSync.Camunda:
|
||||
return <CamundaSyncFields />;
|
||||
case SecretSync.Vercel:
|
||||
|
||||
+244
@@ -0,0 +1,244 @@
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
|
||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||
import { FilterableSelect, FormControl, Select, SelectItem } from "@app/components/v2";
|
||||
import {
|
||||
TERRAFORM_CLOUD_SYNC_SCOPES,
|
||||
TerraformCloudSyncCategory,
|
||||
TerraformCloudSyncScope,
|
||||
TTerraformCloudConnectionOrganization,
|
||||
TTerraformCloudConnectionVariableSet,
|
||||
TTerraformCloudConnectionWorkspace,
|
||||
useTerraformCloudConnectionListOrganizations
|
||||
} from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
export const TerraformCloudSyncFields = () => {
|
||||
const { control, watch, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.TerraformCloud }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const currentOrg = watch("destinationConfig.org");
|
||||
const currentScope = watch("destinationConfig.scope");
|
||||
|
||||
const { data: organizations = [], isPending: isOrganizationsPending } =
|
||||
useTerraformCloudConnectionListOrganizations(connectionId, {
|
||||
enabled: Boolean(connectionId)
|
||||
});
|
||||
|
||||
const selectedOrg = organizations?.find((org) => org.id === currentOrg);
|
||||
const variableSets = selectedOrg?.variableSets || [];
|
||||
const workspaces = selectedOrg?.workspaces || [];
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.org", "");
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.org"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Organization"
|
||||
>
|
||||
<FilterableSelect
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={organizations ? (organizations.find((org) => org.id === value) ?? null) : null}
|
||||
onChange={(option) => {
|
||||
onChange(
|
||||
(option as SingleValue<TTerraformCloudConnectionOrganization>)?.id ?? null
|
||||
);
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
options={organizations}
|
||||
placeholder="Select an organization..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</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"
|
||||
tooltipClassName="max-w-lg py-3"
|
||||
tooltipText={
|
||||
<div className="flex flex-col gap-3">
|
||||
<ul className="flex list-disc flex-col gap-3 pl-4">
|
||||
<li>
|
||||
<p className="text-mineshaft-300">
|
||||
<span className="font-medium text-bunker-200">
|
||||
Environment variables configure Terraform's behavior (e.g.,
|
||||
credentials).
|
||||
</span>
|
||||
</p>
|
||||
</li>
|
||||
<li>
|
||||
<p className="text-mineshaft-300">
|
||||
<span className="font-medium text-bunker-200">
|
||||
Terraform variables are used as input values in your configuration.
|
||||
</span>
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<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.entries(TerraformCloudSyncCategory).map(([envKey, envValue]) => (
|
||||
<SelectItem className="capitalize" value={envValue} key={envValue}>
|
||||
{envKey.replace("-", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.scope"
|
||||
control={control}
|
||||
defaultValue={TerraformCloudSyncScope.VariableSet}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Scope"
|
||||
tooltipClassName="max-w-lg py-3"
|
||||
tooltipText={
|
||||
<div className="flex flex-col gap-3">
|
||||
<p>
|
||||
Specify how Infisical should manage secrets from Terraform Cloud. The following
|
||||
options are available:
|
||||
</p>
|
||||
<ul className="flex list-disc flex-col gap-3 pl-4">
|
||||
{Object.values(TERRAFORM_CLOUD_SYNC_SCOPES).map(({ name, description }) => {
|
||||
return (
|
||||
<li key={name}>
|
||||
<p className="text-mineshaft-300">
|
||||
<span className="font-medium text-bunker-200">{name}</span>: {description}
|
||||
</p>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={(val) => {
|
||||
onChange(val);
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
className="w-full border border-mineshaft-500 capitalize"
|
||||
position="popper"
|
||||
placeholder="Select a scope..."
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(TerraformCloudSyncScope).map((scope) => (
|
||||
<SelectItem className="capitalize" value={scope} key={scope}>
|
||||
{scope.replace("-", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
{currentScope === TerraformCloudSyncScope.VariableSet && (
|
||||
<Controller
|
||||
name="destinationConfig.variableSetId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Variable Set">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId) && Boolean(currentOrg)}
|
||||
isDisabled={!connectionId || !currentOrg}
|
||||
value={variableSets.find((variableSet) => variableSet.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedOption =
|
||||
option as SingleValue<TTerraformCloudConnectionVariableSet>;
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.variableSetName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
}
|
||||
}}
|
||||
options={variableSets}
|
||||
placeholder="Select a variable set..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
{currentScope === TerraformCloudSyncScope.Workspace && (
|
||||
<Controller
|
||||
name="destinationConfig.workspaceId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Workspace">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId) && Boolean(currentOrg)}
|
||||
isDisabled={!connectionId || !currentOrg}
|
||||
value={workspaces.find((workspace) => workspace.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedOption = option as SingleValue<TTerraformCloudConnectionWorkspace>;
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.workspaceName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}
|
||||
}}
|
||||
options={workspaces}
|
||||
placeholder="Select a workspace..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
};
|
||||
+1
@@ -39,6 +39,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.AzureAppConfiguration:
|
||||
case SecretSync.Databricks:
|
||||
case SecretSync.Humanitec:
|
||||
case SecretSync.TerraformCloud:
|
||||
case SecretSync.Camunda:
|
||||
case SecretSync.Vercel:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
|
||||
+4
@@ -22,6 +22,7 @@ import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
|
||||
import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
|
||||
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
|
||||
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
|
||||
import { TerraformCloudSyncReviewFields } from "./TerraformCloudSyncReviewFields";
|
||||
import { VercelSyncReviewFields } from "./VercelSyncReviewFields";
|
||||
|
||||
export const SecretSyncReviewFields = () => {
|
||||
@@ -74,6 +75,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.Humanitec:
|
||||
DestinationFieldsComponent = <HumanitecSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.TerraformCloud:
|
||||
DestinationFieldsComponent = <TerraformCloudSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Camunda:
|
||||
DestinationFieldsComponent = <CamundaSyncReviewFields />;
|
||||
break;
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { useFormContext } from "react-hook-form";
|
||||
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
|
||||
import { TerraformCloudSyncScope } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const TerraformCloudSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.TerraformCloud }>();
|
||||
const orgId = watch("destinationConfig.org");
|
||||
const variableSetName = watch("destinationConfig.variableSetName");
|
||||
const workspaceName = watch("destinationConfig.workspaceName");
|
||||
const scope = watch("destinationConfig.scope");
|
||||
const category = watch("destinationConfig.category");
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{orgId}</GenericFieldLabel>
|
||||
{scope === TerraformCloudSyncScope.VariableSet && (
|
||||
<GenericFieldLabel label="Variable Set">{variableSetName}</GenericFieldLabel>
|
||||
)}
|
||||
{scope === TerraformCloudSyncScope.Workspace && (
|
||||
<GenericFieldLabel label="Workspace">{workspaceName}</GenericFieldLabel>
|
||||
)}
|
||||
<GenericFieldLabel label="Category">{category}</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import { AzureKeyVaultSyncDestinationSchema } from "./azure-key-vault-sync-desti
|
||||
import { CamundaSyncDestinationSchema } from "./camunda-sync-destination-schema";
|
||||
import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
|
||||
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
|
||||
import { TerraformCloudSyncDestinationSchema } from "./terraform-cloud-destination-schema";
|
||||
import { VercelSyncDestinationSchema } from "./vercel-sync-destination-schema";
|
||||
|
||||
const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
@@ -21,6 +22,7 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
AzureAppConfigurationSyncDestinationSchema,
|
||||
DatabricksSyncDestinationSchema,
|
||||
HumanitecSyncDestinationSchema,
|
||||
TerraformCloudSyncDestinationSchema,
|
||||
CamundaSyncDestinationSchema,
|
||||
VercelSyncDestinationSchema
|
||||
]);
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import {
|
||||
TerraformCloudSyncCategory,
|
||||
TerraformCloudSyncScope
|
||||
} from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const TerraformCloudSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.TerraformCloud),
|
||||
destinationConfig: z.discriminatedUnion("scope", [
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.VariableSet),
|
||||
org: z.string().trim().min(1, "Organization required"),
|
||||
variableSetId: z.string().trim().min(1, "Variable Set required"),
|
||||
variableSetName: 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"),
|
||||
workspaceId: z.string().trim().min(1, "Workspace required"),
|
||||
workspaceName: z.string().trim().min(1, "Workspace name required"),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory)
|
||||
})
|
||||
])
|
||||
})
|
||||
);
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
MsSqlConnectionMethod,
|
||||
PostgresConnectionMethod,
|
||||
TAppConnection,
|
||||
TerraformCloudConnectionMethod,
|
||||
VercelConnectionMethod
|
||||
} from "@app/hooks/api/appConnections/types";
|
||||
|
||||
@@ -31,6 +32,7 @@ export const APP_CONNECTION_MAP: Record<AppConnection, { name: string; image: st
|
||||
},
|
||||
[AppConnection.Databricks]: { name: "Databricks", image: "Databricks.png" },
|
||||
[AppConnection.Humanitec]: { name: "Humanitec", image: "Humanitec.png" },
|
||||
[AppConnection.TerraformCloud]: { name: "Terraform Cloud", image: "Terraform Cloud.png" },
|
||||
[AppConnection.Vercel]: { name: "Vercel", image: "Vercel.png" },
|
||||
[AppConnection.Postgres]: { name: "PostgreSQL", image: "Postgres.png" },
|
||||
[AppConnection.MsSql]: { name: "Microsoft SQL Server", image: "MsSql.png" },
|
||||
@@ -56,6 +58,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
|
||||
case CamundaConnectionMethod.ClientCredentials:
|
||||
return { name: "Client Credentials", icon: faKey };
|
||||
case HumanitecConnectionMethod.ApiToken:
|
||||
case TerraformCloudConnectionMethod.ApiToken:
|
||||
case VercelConnectionMethod.ApiToken:
|
||||
return { name: "API Token", icon: faKey };
|
||||
case PostgresConnectionMethod.UsernameAndPassword:
|
||||
|
||||
@@ -24,6 +24,10 @@ export const SECRET_SYNC_MAP: Record<SecretSync, { name: string; image: string }
|
||||
name: "Humanitec",
|
||||
image: "Humanitec.png"
|
||||
},
|
||||
[SecretSync.TerraformCloud]: {
|
||||
name: "Terraform Cloud",
|
||||
image: "Terraform Cloud.png"
|
||||
},
|
||||
[SecretSync.Camunda]: {
|
||||
name: "Camunda",
|
||||
image: "Camunda.png"
|
||||
@@ -43,6 +47,7 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.AzureAppConfiguration]: AppConnection.AzureAppConfiguration,
|
||||
[SecretSync.Databricks]: AppConnection.Databricks,
|
||||
[SecretSync.Humanitec]: AppConnection.Humanitec,
|
||||
[SecretSync.TerraformCloud]: AppConnection.TerraformCloud,
|
||||
[SecretSync.Camunda]: AppConnection.Camunda,
|
||||
[SecretSync.Vercel]: AppConnection.Vercel
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ export enum AppConnection {
|
||||
AzureAppConfiguration = "azure-app-configuration",
|
||||
Databricks = "databricks",
|
||||
Humanitec = "humanitec",
|
||||
TerraformCloud = "terraform-cloud",
|
||||
Vercel = "vercel",
|
||||
Postgres = "postgres",
|
||||
MsSql = "mssql",
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./queries";
|
||||
export * from "./types";
|
||||
@@ -0,0 +1,37 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { appConnectionKeys } from "../queries";
|
||||
import { TTerraformCloudOrganization } from "./types";
|
||||
|
||||
const terraformCloudConnectionKeys = {
|
||||
all: [...appConnectionKeys.all, "terraform-cloud"] as const,
|
||||
listOrganizations: (connectionId: string) =>
|
||||
[...terraformCloudConnectionKeys.all, "organizations", connectionId] as const
|
||||
};
|
||||
|
||||
export const useTerraformCloudConnectionListOrganizations = (
|
||||
connectionId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TTerraformCloudOrganization[],
|
||||
unknown,
|
||||
TTerraformCloudOrganization[],
|
||||
ReturnType<typeof terraformCloudConnectionKeys.listOrganizations>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: terraformCloudConnectionKeys.listOrganizations(connectionId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TTerraformCloudOrganization[]>(
|
||||
`/api/v1/app-connections/terraform-cloud/${connectionId}/organizations`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,56 @@
|
||||
export type TTerraformCloudOrganization = {
|
||||
name: string;
|
||||
id: string;
|
||||
variableSets: TTerraformCloudVariableSet[];
|
||||
workspaces: TTerraformCloudWorkspace[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudVariableSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TTerraformCloudWorkspace = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionOrganization = {
|
||||
id: string;
|
||||
name: string;
|
||||
variableSets: TTerraformCloudConnectionVariableSet[];
|
||||
workspaces: TTerraformCloudConnectionWorkspace[];
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionVariableSet = {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
global: boolean;
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionWorkspace = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
VariableSet = "variable-set",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
|
||||
export enum TerraformCloudSyncCategory {
|
||||
Environment = "env",
|
||||
Terraform = "terraform"
|
||||
}
|
||||
|
||||
export const TERRAFORM_CLOUD_SYNC_SCOPES = {
|
||||
[TerraformCloudSyncScope.VariableSet]: {
|
||||
name: "Variable Set",
|
||||
description: "Sync secrets to a specific variable set in Terraform Cloud."
|
||||
},
|
||||
[TerraformCloudSyncScope.Workspace]: {
|
||||
name: "Workspace",
|
||||
description: "Sync secrets to a specific workspace in Terraform Cloud."
|
||||
}
|
||||
};
|
||||
@@ -39,6 +39,10 @@ export type THumanitecConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Humanitec;
|
||||
};
|
||||
|
||||
export type TTerraformCloudConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.TerraformCloud;
|
||||
};
|
||||
|
||||
export type TVercelConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Vercel;
|
||||
};
|
||||
@@ -63,6 +67,7 @@ export type TAppConnectionOption =
|
||||
| TAzureKeyVaultConnectionOption
|
||||
| TDatabricksConnectionOption
|
||||
| THumanitecConnectionOption
|
||||
| TTerraformCloudConnectionOption
|
||||
| TVercelConnectionOption
|
||||
| TPostgresConnectionOption
|
||||
| TMsSqlConnectionOption
|
||||
@@ -76,6 +81,7 @@ export type TAppConnectionOptionMap = {
|
||||
[AppConnection.AzureAppConfiguration]: TAzureAppConfigurationConnectionOption;
|
||||
[AppConnection.Databricks]: TDatabricksConnectionOption;
|
||||
[AppConnection.Humanitec]: THumanitecConnectionOption;
|
||||
[AppConnection.TerraformCloud]: TTerraformCloudConnectionOption;
|
||||
[AppConnection.Vercel]: TVercelConnectionOption;
|
||||
[AppConnection.Postgres]: TPostgresConnectionOption;
|
||||
[AppConnection.MsSql]: TMsSqlConnectionOption;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { TGitHubConnection } from "./github-connection";
|
||||
import { THumanitecConnection } from "./humanitec-connection";
|
||||
import { TMsSqlConnection } from "./mssql-connection";
|
||||
import { TPostgresConnection } from "./postgres-connection";
|
||||
import { TTerraformCloudConnection } from "./terraform-cloud-connection";
|
||||
import { TVercelConnection } from "./vercel-connection";
|
||||
|
||||
export * from "./aws-connection";
|
||||
@@ -22,6 +23,7 @@ export * from "./github-connection";
|
||||
export * from "./humanitec-connection";
|
||||
export * from "./mssql-connection";
|
||||
export * from "./postgres-connection";
|
||||
export * from "./terraform-cloud-connection";
|
||||
export * from "./vercel-connection";
|
||||
|
||||
export type TAppConnection =
|
||||
@@ -32,6 +34,7 @@ export type TAppConnection =
|
||||
| TAzureAppConfigurationConnection
|
||||
| TDatabricksConnection
|
||||
| THumanitecConnection
|
||||
| TTerraformCloudConnection
|
||||
| TVercelConnection
|
||||
| TPostgresConnection
|
||||
| TMsSqlConnection
|
||||
@@ -70,6 +73,7 @@ export type TAppConnectionMap = {
|
||||
[AppConnection.AzureAppConfiguration]: TAzureAppConfigurationConnection;
|
||||
[AppConnection.Databricks]: TDatabricksConnection;
|
||||
[AppConnection.Humanitec]: THumanitecConnection;
|
||||
[AppConnection.TerraformCloud]: TTerraformCloudConnection;
|
||||
[AppConnection.Vercel]: TVercelConnection;
|
||||
[AppConnection.Postgres]: TPostgresConnection;
|
||||
[AppConnection.MsSql]: TMsSqlConnection;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
|
||||
|
||||
export enum TerraformCloudConnectionMethod {
|
||||
ApiToken = "api-token"
|
||||
}
|
||||
|
||||
export type TTerraformCloudConnection = TRootAppConnection & {
|
||||
app: AppConnection.TerraformCloud;
|
||||
} & {
|
||||
method: TerraformCloudConnectionMethod.ApiToken;
|
||||
credentials: {
|
||||
apiToken: string;
|
||||
};
|
||||
};
|
||||
@@ -7,6 +7,7 @@ export enum SecretSync {
|
||||
AzureAppConfiguration = "azure-app-configuration",
|
||||
Databricks = "databricks",
|
||||
Humanitec = "humanitec",
|
||||
TerraformCloud = "terraform-cloud",
|
||||
Camunda = "camunda",
|
||||
Vercel = "vercel"
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import { TAzureKeyVaultSync } from "./azure-key-vault-sync";
|
||||
import { TCamundaSync } from "./camunda-sync";
|
||||
import { TGcpSync } from "./gcp-sync";
|
||||
import { THumanitecSync } from "./humanitec-sync";
|
||||
import { TTerraformCloudSync } from "./terraform-cloud-sync";
|
||||
import { TVercelSync } from "./vercel-sync";
|
||||
|
||||
export type TSecretSyncOption = {
|
||||
@@ -27,6 +28,7 @@ export type TSecretSync =
|
||||
| TAzureAppConfigurationSync
|
||||
| TDatabricksSync
|
||||
| THumanitecSync
|
||||
| TTerraformCloudSync
|
||||
| TCamundaSync
|
||||
| TVercelSync;
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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.VariableSet;
|
||||
org: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
variableSetId: string;
|
||||
variableSetName: string;
|
||||
}
|
||||
| {
|
||||
scope: TerraformCloudSyncScope.Workspace;
|
||||
org: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
workspaceId: string;
|
||||
workspaceName: string;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.TerraformCloud;
|
||||
name: string;
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
|
||||
export enum TerraformCloudSyncScope {
|
||||
VariableSet = "variable-set",
|
||||
Workspace = "workspace"
|
||||
}
|
||||
+5
@@ -19,6 +19,7 @@ import { GitHubConnectionForm } from "./GitHubConnectionForm";
|
||||
import { HumanitecConnectionForm } from "./HumanitecConnectionForm";
|
||||
import { MsSqlConnectionForm } from "./MsSqlConnectionForm";
|
||||
import { PostgresConnectionForm } from "./PostgresConnectionForm";
|
||||
import { TerraformCloudConnectionForm } from "./TerraformCloudConnectionForm";
|
||||
import { VercelConnectionForm } from "./VercelConnectionForm";
|
||||
|
||||
type FormProps = {
|
||||
@@ -72,6 +73,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
|
||||
return <DatabricksConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Humanitec:
|
||||
return <HumanitecConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.TerraformCloud:
|
||||
return <TerraformCloudConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Vercel:
|
||||
return <VercelConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Postgres:
|
||||
@@ -130,6 +133,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
|
||||
return <DatabricksConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Humanitec:
|
||||
return <HumanitecConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.TerraformCloud:
|
||||
return <TerraformCloudConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Vercel:
|
||||
return <VercelConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Postgres:
|
||||
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
Button,
|
||||
FormControl,
|
||||
ModalClose,
|
||||
SecretInput,
|
||||
Select,
|
||||
SelectItem
|
||||
} from "@app/components/v2";
|
||||
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
||||
import {
|
||||
TerraformCloudConnectionMethod,
|
||||
TTerraformCloudConnection
|
||||
} from "@app/hooks/api/appConnections";
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
|
||||
import {
|
||||
genericAppConnectionFieldsSchema,
|
||||
GenericAppConnectionsFields
|
||||
} from "./GenericAppConnectionFields";
|
||||
|
||||
type Props = {
|
||||
appConnection?: TTerraformCloudConnection;
|
||||
onSubmit: (formData: FormData) => void;
|
||||
};
|
||||
|
||||
const rootSchema = genericAppConnectionFieldsSchema.extend({
|
||||
app: z.literal(AppConnection.TerraformCloud)
|
||||
});
|
||||
|
||||
const formSchema = z.discriminatedUnion("method", [
|
||||
rootSchema.extend({
|
||||
method: z.literal(TerraformCloudConnectionMethod.ApiToken),
|
||||
credentials: z.object({
|
||||
apiToken: z.string().trim().min(1, "API Token required")
|
||||
})
|
||||
})
|
||||
]);
|
||||
|
||||
type FormData = z.infer<typeof formSchema>;
|
||||
|
||||
export const TerraformCloudConnectionForm = ({ appConnection, onSubmit }: Props) => {
|
||||
const isUpdate = Boolean(appConnection);
|
||||
|
||||
const form = useForm<FormData>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: appConnection ?? {
|
||||
app: AppConnection.TerraformCloud,
|
||||
method: TerraformCloudConnectionMethod.ApiToken
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
formState: { isSubmitting, isDirty }
|
||||
} = form;
|
||||
|
||||
return (
|
||||
<FormProvider {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
{!isUpdate && <GenericAppConnectionsFields />}
|
||||
<Controller
|
||||
name="method"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
tooltipText={`The method you would like to use to connect with ${
|
||||
APP_CONNECTION_MAP[AppConnection.TerraformCloud].name
|
||||
}. This field cannot be changed after creation.`}
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Method"
|
||||
>
|
||||
<Select
|
||||
isDisabled={isUpdate}
|
||||
value={value}
|
||||
onValueChange={(val) => onChange(val)}
|
||||
className="w-full border border-mineshaft-500"
|
||||
position="popper"
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(TerraformCloudConnectionMethod).map((method) => {
|
||||
return (
|
||||
<SelectItem value={method} key={method}>
|
||||
{getAppConnectionMethodDetails(method).name}{" "}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="credentials.apiToken"
|
||||
control={control}
|
||||
shouldUnregister
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="API Token"
|
||||
>
|
||||
<SecretInput
|
||||
containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<div className="mt-8 flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
colorSchema="secondary"
|
||||
isLoading={isSubmitting}
|
||||
isDisabled={isSubmitting || !isDirty}
|
||||
>
|
||||
{isUpdate ? "Update Credentials" : "Connect to Terraform Cloud"}
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
);
|
||||
};
|
||||
+3
@@ -9,6 +9,7 @@ import { DatabricksSyncDestinationCol } from "./DatabricksSyncDestinationCol";
|
||||
import { GcpSyncDestinationCol } from "./GcpSyncDestinationCol";
|
||||
import { GitHubSyncDestinationCol } from "./GitHubSyncDestinationCol";
|
||||
import { HumanitecSyncDestinationCol } from "./HumanitecSyncDestinationCol";
|
||||
import { TerraformCloudSyncDestinationCol } from "./TerraformCloudSyncDestinationCol";
|
||||
import { VercelSyncDestinationCol } from "./VercelSyncDestinationCol";
|
||||
|
||||
type Props = {
|
||||
@@ -33,6 +34,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
return <DatabricksSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Humanitec:
|
||||
return <HumanitecSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.TerraformCloud:
|
||||
return <TerraformCloudSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Camunda:
|
||||
return <CamundaSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Vercel:
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { TTerraformCloudSync } from "@app/hooks/api/secretSyncs/types/terraform-cloud-sync";
|
||||
|
||||
import { getSecretSyncDestinationColValues } from "../helpers";
|
||||
import { SecretSyncTableCell } from "../SecretSyncTableCell";
|
||||
|
||||
type Props = {
|
||||
secretSync: TTerraformCloudSync;
|
||||
};
|
||||
|
||||
export const TerraformCloudSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
const { primaryText, secondaryText } = getSecretSyncDestinationColValues(secretSync);
|
||||
|
||||
return <SecretSyncTableCell primaryText={primaryText} secondaryText={secondaryText} />;
|
||||
};
|
||||
+9
@@ -1,3 +1,4 @@
|
||||
import { TerraformCloudSyncScope } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync, TSecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import {
|
||||
GitHubSyncScope,
|
||||
@@ -73,6 +74,14 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
}
|
||||
secondaryText = `Organization - ${destinationConfig.org}`;
|
||||
break;
|
||||
case SecretSync.TerraformCloud:
|
||||
primaryText = destinationConfig.org;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
secondaryText = destinationConfig.variableSetName;
|
||||
} else {
|
||||
secondaryText = destinationConfig.workspaceName;
|
||||
}
|
||||
break;
|
||||
case SecretSync.Camunda:
|
||||
primaryText = destinationConfig.clusterName ?? destinationConfig.clusterUUID;
|
||||
secondaryText = "Cluster";
|
||||
|
||||
+4
@@ -19,6 +19,7 @@ import { AzureKeyVaultSyncDestinationSection } from "./AzureKeyVaultSyncDestinat
|
||||
import { CamundaSyncDestinationSection } from "./CamundaSyncDestinationSection";
|
||||
import { GcpSyncDestinationSection } from "./GcpSyncDestinationSection";
|
||||
import { HumanitecSyncDestinationSection } from "./HumanitecSyncDestinationSection";
|
||||
import { TerraformCloudSyncDestinationSection } from "./TerraformCloudSyncDestinationSection";
|
||||
import { VercelSyncDestinationSection } from "./VercelSyncDestinationSection";
|
||||
|
||||
type Props = {
|
||||
@@ -59,6 +60,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
|
||||
case SecretSync.Humanitec:
|
||||
DestinationComponents = <HumanitecSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.TerraformCloud:
|
||||
DestinationComponents = <TerraformCloudSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.Camunda:
|
||||
DestinationComponents = <CamundaSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
import { ReactNode } from "react";
|
||||
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { TerraformCloudSyncCategory } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import {
|
||||
TerraformCloudSyncScope,
|
||||
TTerraformCloudSync
|
||||
} from "@app/hooks/api/secretSyncs/types/terraform-cloud-sync";
|
||||
|
||||
type Props = {
|
||||
secretSync: TTerraformCloudSync;
|
||||
};
|
||||
|
||||
export const TerraformCloudSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
const { destinationConfig } = secretSync;
|
||||
|
||||
let Components: ReactNode;
|
||||
switch (destinationConfig.scope) {
|
||||
case TerraformCloudSyncScope.VariableSet:
|
||||
Components = (
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{destinationConfig.org}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Variable Set">
|
||||
{destinationConfig.variableSetName}
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Category">
|
||||
{Object.keys(TerraformCloudSyncCategory).find(
|
||||
(key) =>
|
||||
TerraformCloudSyncCategory[key as keyof typeof TerraformCloudSyncCategory] ===
|
||||
destinationConfig.category
|
||||
)}
|
||||
</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
case TerraformCloudSyncScope.Workspace:
|
||||
Components = (
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{destinationConfig.org}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Workspace">{destinationConfig.workspaceName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Category">
|
||||
{Object.keys(TerraformCloudSyncCategory).find(
|
||||
(key) =>
|
||||
TerraformCloudSyncCategory[key as keyof typeof TerraformCloudSyncCategory] ===
|
||||
destinationConfig.category
|
||||
)}
|
||||
</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled Terraform Cloud Sync Destination Section Scope ${secretSync.destinationConfig.scope}`
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel className="capitalize" label="Scope">
|
||||
{destinationConfig.scope.replace("-", " ")}
|
||||
</GenericFieldLabel>
|
||||
{Components}
|
||||
</>
|
||||
);
|
||||
};
|
||||
+1
@@ -48,6 +48,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
|
||||
case SecretSync.AzureAppConfiguration:
|
||||
case SecretSync.Databricks:
|
||||
case SecretSync.Humanitec:
|
||||
case SecretSync.TerraformCloud:
|
||||
case SecretSync.Camunda:
|
||||
case SecretSync.Vercel:
|
||||
AdditionalSyncOptionsComponent = null;
|
||||
|
||||
Reference in New Issue
Block a user