import { useState } from "react"; import { deployAwsPermissionsBoundary } from "../../../lib/tauri-commands"; import { awsErrorMessage } from "../../../lib/aws-error"; import type { AwsError, EnvironmentScan, NetworkChoice } from "../../../lib/types"; import Button from "../../ui/Button"; import Field, { inputClass } from "../../ui/Field"; import Modal from "../../ui/Modal"; import AdminBundleModal from "./AdminBundleModal"; import DeployProgress, { runKey, useDeployRuns } from "./DeployProgress"; import NetworkFields from "./NetworkFields"; import { BOUNDARY_STATE_KEY, DEFAULT_NETWORK, environmentNameError, networkFromDraft, type NetworkDraft, } from "./environmentFormat"; /** * Deploy a new environment (name + D4 network), or — with `repair` — pick the * network for an environment that has no record to take it from. A missing * permissions boundary is a first step before the form. */ export default function DeployEnvironmentModal({ connectionId, region, scan, repair, onClose, onDeploy, onDetect, }: { connectionId: string; region: string; scan: EnvironmentScan; /** The environment to repair; absent for a new deploy. */ repair?: string; onClose: () => void; /** Starts the run; resolves to the command's error, or null once started. */ onDeploy: (name: string, network: NetworkChoice) => Promise; onDetect: () => void; }) { const [name, setName] = useState("main"); const [draft, setDraft] = useState(DEFAULT_NETWORK); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const [boundaryDone, setBoundaryDone] = useState(false); const [boundaryError, setBoundaryError] = useState(null); const [bundle, setBundle] = useState<{ reason?: string } | null>(null); const boundary = useDeployRuns(({ result }) => { if (result?.ok) setBoundaryDone(true); onDetect(); }); const boundaryRun = boundary.runs[runKey(region, BOUNDARY_STATE_KEY)]; const boundaryFailed = boundaryRun?.done && boundaryRun.result && !boundaryRun.result.ok ? boundaryRun.result : null; if (bundle) { return ( setBundle(null)} /> ); } const needsBoundary = !repair && scan.boundary === "no" && !boundaryDone; const target = repair ?? name; const nameError = repair ? null : environmentNameError(name) ?? (scan.environments.some((e) => e.name === name) ? `An environment named ${name} already exists here.` : null); const picked = networkFromDraft(draft); const ready = !nameError && "network" in picked && !submitting; const createBoundary = async () => { setBoundaryError(null); const err = await boundary.start(BOUNDARY_STATE_KEY, region, "Permissions boundary", () => deployAwsPermissionsBoundary(connectionId, region), ); if (err?.kind === "access_denied") setBundle({ reason: awsErrorMessage(err) }); else if (err) setBoundaryError(err); }; const submit = async () => { if (!("network" in picked)) return; setSubmitting(true); setError(null); const err = await onDeploy(target, picked.network); setSubmitting(false); if (err) setError(err); else onClose(); }; const verb = repair ? "Repair" : "Deploy"; return ( {!needsBoundary && ( )} } > {needsBoundary ? (

This account has no Triple-C permissions boundary yet. Every role an environment creates is capped by it, so it comes first.

{boundaryError && (

{awsErrorMessage(boundaryError)}

)} {boundaryRun && } {boundaryFailed && (

Creating the boundary failed. If it was refused, an account administrator can create it from a bundle.

)}
) : (
{repair ? (

{repair} has no record, so Triple-C can't tell which network it was deployed with. Choose the same one: a different network than the one it was deployed with replaces the network resources (VPC, subnets, NAT gateway).

) : ( {(id) => setName(e.target.value)} />} )}

First deploy downloads OpenTofu (~30 MB) and the AWS provider (~150 MB).

{error && (

{awsErrorMessage(error)}

)}
)}
); }