mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Improve terraform-cloud secret sync destination variables
This commit is contained in:
@@ -1815,8 +1815,10 @@ export const SecretSyncs = {
|
||||
},
|
||||
TERRAFORM_CLOUD: {
|
||||
org: "The ID of the Terraform Cloud org to sync secrets 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.",
|
||||
variableSetName: "The name of the Terraform Cloud Variable Set to sync secrets to.",
|
||||
variableSetId: "The ID of the Terraform Cloud Variable Set to sync secrets to.",
|
||||
workspaceName: "The name of the Terraform Cloud workspace to sync secrets to.",
|
||||
workspaceId: "The ID of the Terraform Cloud 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."
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ const getTerraformCloudVariables = async (
|
||||
let source: TerraformCloudVariable["source"];
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.variableSetId}/relationships/vars`;
|
||||
source = "varset";
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.workspaceId}/vars`;
|
||||
source = "workspace";
|
||||
}
|
||||
|
||||
@@ -92,9 +92,9 @@ const deleteVariable = async (
|
||||
let url;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.variableSetId}/relationships/vars/${variable.id}`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.workspaceId}/vars/${variable.id}`;
|
||||
}
|
||||
|
||||
await request.delete(url, {
|
||||
@@ -127,9 +127,9 @@ const createVariable = async (
|
||||
let url;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.variableSetId}/relationships/vars`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.workspaceId}/vars`;
|
||||
}
|
||||
|
||||
await request.post(
|
||||
@@ -177,9 +177,9 @@ const updateVariable = async (
|
||||
let url;
|
||||
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.destinationId}/relationships/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/varsets/${destinationConfig.variableSetId}/relationships/vars/${variable.id}`;
|
||||
} else {
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.destinationId}/vars/${variable.id}`;
|
||||
url = `${IntegrationUrls.TERRAFORM_CLOUD_API_URL}/api/v2/workspaces/${destinationConfig.workspaceId}/vars/${variable.id}`;
|
||||
}
|
||||
|
||||
await request.patch(
|
||||
|
||||
@@ -20,27 +20,27 @@ const TerraformCloudSyncDestinationConfigSchema = z.discriminatedUnion("scope",
|
||||
.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),
|
||||
destinationName: z
|
||||
variableSetName: z
|
||||
.string()
|
||||
.min(1, "Variable set name is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationName),
|
||||
destinationId: z
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.variableSetName),
|
||||
variableSetId: z
|
||||
.string()
|
||||
.min(1, "Variable set ID is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationId),
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.variableSetId),
|
||||
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),
|
||||
destinationName: z
|
||||
workspaceName: z
|
||||
.string()
|
||||
.min(1, "Workspace name is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationName),
|
||||
destinationId: z
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.workspaceName),
|
||||
workspaceId: z
|
||||
.string()
|
||||
.min(1, "Workspace ID is required")
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.destinationId),
|
||||
.describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.workspaceId),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory).describe(SecretSyncs.DESTINATION_CONFIG.TERRAFORM_CLOUD.category)
|
||||
})
|
||||
]);
|
||||
|
||||
@@ -94,8 +94,8 @@ description: "Learn how to configure a Terraform Cloud Sync for Infisical."
|
||||
},
|
||||
"destinationConfig": {
|
||||
"scope": "variable-set",
|
||||
"destinationId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
|
||||
"destinationName": "my-variable-set",
|
||||
"variableSetId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
|
||||
"variableSetName": "my-variable-set",
|
||||
"org": "my-organization-id",
|
||||
"category": "env"
|
||||
}
|
||||
@@ -149,8 +149,8 @@ description: "Learn how to configure a Terraform Cloud Sync for Infisical."
|
||||
"destination": "terraform-cloud",
|
||||
"destinationConfig": {
|
||||
"scope": "workspace",
|
||||
"destinationId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
|
||||
"destinationName": "my-workspace",
|
||||
"workspaceId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
|
||||
"workspaceName": "my-workspace",
|
||||
"org": "my-organization-id",
|
||||
"category": "terraform"
|
||||
}
|
||||
|
||||
@@ -39,8 +39,10 @@ export const TerraformCloudSyncFields = () => {
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.org", "");
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
@@ -60,8 +62,10 @@ export const TerraformCloudSyncFields = () => {
|
||||
onChange(
|
||||
(option as SingleValue<TTerraformCloudConnectionOrganization>)?.id ?? null
|
||||
);
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
options={organizations}
|
||||
placeholder="Select an organization..."
|
||||
@@ -155,8 +159,10 @@ export const TerraformCloudSyncFields = () => {
|
||||
value={value}
|
||||
onValueChange={(val) => {
|
||||
onChange(val);
|
||||
setValue("destinationConfig.destinationId", "");
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
setValue("destinationConfig.variableSetId", "");
|
||||
setValue("destinationConfig.workspaceId", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}}
|
||||
className="w-full border border-mineshaft-500 capitalize"
|
||||
position="popper"
|
||||
@@ -174,7 +180,7 @@ export const TerraformCloudSyncFields = () => {
|
||||
/>
|
||||
{currentScope === TerraformCloudSyncScope.VariableSet && (
|
||||
<Controller
|
||||
name="destinationConfig.destinationId"
|
||||
name="destinationConfig.variableSetId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Variable Set">
|
||||
@@ -189,9 +195,9 @@ export const TerraformCloudSyncFields = () => {
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.destinationName", selectedOption.name);
|
||||
setValue("destinationConfig.variableSetName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
setValue("destinationConfig.variableSetName", "");
|
||||
}
|
||||
}}
|
||||
options={variableSets}
|
||||
@@ -205,7 +211,7 @@ export const TerraformCloudSyncFields = () => {
|
||||
)}
|
||||
{currentScope === TerraformCloudSyncScope.Workspace && (
|
||||
<Controller
|
||||
name="destinationConfig.destinationId"
|
||||
name="destinationConfig.workspaceId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Workspace">
|
||||
@@ -219,9 +225,9 @@ export const TerraformCloudSyncFields = () => {
|
||||
onChange(selectedOption?.id ?? null);
|
||||
|
||||
if (selectedOption) {
|
||||
setValue("destinationConfig.destinationName", selectedOption.name);
|
||||
setValue("destinationConfig.workspaceName", selectedOption.name);
|
||||
} else {
|
||||
setValue("destinationConfig.destinationName", "");
|
||||
setValue("destinationConfig.workspaceName", "");
|
||||
}
|
||||
}}
|
||||
options={workspaces}
|
||||
|
||||
@@ -8,7 +8,8 @@ import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
export const TerraformCloudSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.TerraformCloud }>();
|
||||
const orgId = watch("destinationConfig.org");
|
||||
const destinationName = watch("destinationConfig.destinationName");
|
||||
const variableSetName = watch("destinationConfig.variableSetName");
|
||||
const workspaceName = watch("destinationConfig.workspaceName");
|
||||
const scope = watch("destinationConfig.scope");
|
||||
const category = watch("destinationConfig.category");
|
||||
|
||||
@@ -16,10 +17,10 @@ export const TerraformCloudSyncReviewFields = () => {
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{orgId}</GenericFieldLabel>
|
||||
{scope === TerraformCloudSyncScope.VariableSet && (
|
||||
<GenericFieldLabel label="Variable Set">{destinationName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Variable Set">{variableSetName}</GenericFieldLabel>
|
||||
)}
|
||||
{scope === TerraformCloudSyncScope.Workspace && (
|
||||
<GenericFieldLabel label="Workspace">{destinationName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Workspace">{workspaceName}</GenericFieldLabel>
|
||||
)}
|
||||
<GenericFieldLabel label="Category">{category}</GenericFieldLabel>
|
||||
</>
|
||||
|
||||
@@ -14,15 +14,15 @@ export const TerraformCloudSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
scope: z.literal(TerraformCloudSyncScope.VariableSet),
|
||||
org: z.string().trim().min(1, "Organization required"),
|
||||
destinationId: z.string().trim().min(1, "Variable Set required"),
|
||||
destinationName: z.string().trim().min(1, "Variable set name 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"),
|
||||
destinationId: z.string().trim().min(1, "Workspace required"),
|
||||
destinationName: z.string().trim().min(1, "Workspace name required"),
|
||||
workspaceId: z.string().trim().min(1, "Workspace required"),
|
||||
workspaceName: z.string().trim().min(1, "Workspace name required"),
|
||||
category: z.nativeEnum(TerraformCloudSyncCategory)
|
||||
})
|
||||
])
|
||||
|
||||
@@ -11,15 +11,15 @@ export type TTerraformCloudSync = TRootSecretSync & {
|
||||
scope: TerraformCloudSyncScope.VariableSet;
|
||||
org: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
destinationId: string;
|
||||
destinationName: string;
|
||||
variableSetId: string;
|
||||
variableSetName: string;
|
||||
}
|
||||
| {
|
||||
scope: TerraformCloudSyncScope.Workspace;
|
||||
org: string;
|
||||
category: TerraformCloudSyncCategory;
|
||||
destinationId: string;
|
||||
destinationName: string;
|
||||
workspaceId: string;
|
||||
workspaceName: string;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.TerraformCloud;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { TerraformCloudSyncScope } from "@app/hooks/api/appConnections/terraform-cloud";
|
||||
import { SecretSync, TSecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import {
|
||||
GitHubSyncScope,
|
||||
@@ -75,7 +76,11 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
break;
|
||||
case SecretSync.TerraformCloud:
|
||||
primaryText = destinationConfig.org;
|
||||
secondaryText = destinationConfig.destinationName;
|
||||
if (destinationConfig.scope === TerraformCloudSyncScope.VariableSet) {
|
||||
secondaryText = destinationConfig.variableSetName;
|
||||
} else {
|
||||
secondaryText = destinationConfig.workspaceName;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Col Values ${destination}`);
|
||||
|
||||
@@ -20,7 +20,7 @@ export const TerraformCloudSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{destinationConfig.org}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Variable Set">
|
||||
{destinationConfig.destinationName}
|
||||
{destinationConfig.variableSetName}
|
||||
</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
@@ -29,9 +29,7 @@ export const TerraformCloudSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
Components = (
|
||||
<>
|
||||
<GenericFieldLabel label="Organization">{destinationConfig.org}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Workspace">
|
||||
{destinationConfig.destinationName}
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Workspace">{destinationConfig.workspaceName}</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user