import { useState } from "react"; import { saveAwsAdminBundle } from "../../../lib/tauri-commands"; import { awsErrorMessage, toAwsError } from "../../../lib/aws-error"; import type { AwsError, ModuleKind, NetworkChoice } from "../../../lib/types"; import Button from "../../ui/Button"; import Field, { inputClass } from "../../ui/Field"; import Modal from "../../ui/Modal"; import NetworkFields from "./NetworkFields"; import { DEFAULT_NETWORK, environmentNameError, networkFromDraft, type NetworkDraft } from "./environmentFormat"; const COMMANDS = "tofu init -backend-config=backend.hcl\ntofu apply"; const TITLE: Record = { environment: "Environment bundle", user_onboard: "Onboarding bundle", permissions_boundary: "Permissions boundary bundle", }; /** * An admin request (D5): Triple-C writes the module, `backend.hcl`, * `terraform.tfvars.json` and a README into a folder picked in Rust, and the * admin runs the two commands from there. */ export default function AdminBundleModal({ connectionId, region, kind, environment, ownerId, network, reason, onSaved, onClose, }: { connectionId: string; region: string; kind: ModuleKind; /** Fixed environment; when absent for an environment bundle, the user picks it here. */ environment?: string; ownerId?: string; network?: NetworkChoice; /** Why the bundle is needed (e.g. the refusal that led here). */ reason?: string; /** Called with the folder once a bundle was actually written. */ onSaved?: (folder: string) => void; onClose: () => void; }) { const askEnvironment = kind === "environment" && !environment; const [name, setName] = useState("main"); const [draft, setDraft] = useState(DEFAULT_NETWORK); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(null); const [error, setError] = useState(null); const [copyNote, setCopyNote] = useState(null); const nameError = askEnvironment ? environmentNameError(name) : null; const picked = askEnvironment ? networkFromDraft(draft) : null; const ready = !nameError && (!picked || "network" in picked); const save = async () => { setSaving(true); setError(null); try { const folder = await saveAwsAdminBundle(connectionId, region, kind, { environment: askEnvironment ? name : environment, ownerId, network: picked && "network" in picked ? picked.network : network, }); if (folder) { setSaved(folder); onSaved?.(folder); } } catch (e) { setError(toAwsError(e)); } finally { setSaving(false); } }; const copy = async () => { try { await navigator.clipboard.writeText(COMMANDS); setCopyNote("Commands copied."); } catch (e) { setCopyNote(`Could not copy: ${awsErrorMessage(toAwsError(e))}`); } }; return ( Close } >
{reason && (

Doing this from here was refused: {reason}

)} {kind === "environment" && (

Deploying an environment needs an environment admin. Triple-C writes the OpenTofu module with its backend settings and variables into a folder; send it to an admin, who deploys it from there.

)} {kind === "user_onboard" && (

Joining {environment} needs your own task role and file system, which an environment admin creates by applying this bundle. Send them the folder; once it's applied, Detect again shows you as joined.

)} {kind === "permissions_boundary" && (

Every role Triple-C creates is capped by the account's permissions boundary, and creating it needs an account administrator. Send them this folder.

)}

The bundle works with OpenTofu or Terraform 1.10 and later. Its README lists every step.

{askEnvironment && (
{(id) => setName(e.target.value)} />}
)} {error && (

{awsErrorMessage(error)}

)} {saved && (

Saved to {saved}

From that folder, run:

              {COMMANDS}
            
{copyNote &&

{copyNote}

}
)}
); }