The Amazon Bedrock AgentCore Memory, Gateway, and Workload Identity are
managed declaratively by Terraform (via the AWSCC provider, in the agentcore module).
The Runtime — the container that runs the agent — is different: it is built from the
agent source and deployed with the agentcore CLI, so it is deployed as a scripted step
rather than a Terraform resource. Its ARN is then fed back into Terraform.
The runtime packages the agent source (app/agent/) into a container, creates/updates
the runtime and its execution role, and returns a runtime ARN. That build-and-deploy is
owned by the agentcore toolchain, not by declarative IaC. Terraform still owns
everything the runtime depends on and everything that depends on it — only the container
lifecycle is delegated to the CLI.
terraform apply— creates Memory, Gateway, Workload Identity, the guardrail, Cognito, buckets, and the Lambdas. On the first apply,var.agent_runtime_arnis empty, so the Lambdas point at a placeholder.make deploy-agent(runsscripts/deploy-agent.sh) — resolves the runtime config from Terraform outputs (gateway URL, memory id, buckets), runsagentcore deploy, then saves the resulting ARN so you don't have to copy it:- writes
agent_runtime_arntoinfra/environments/<env>/agent.auto.tfvars(included in$TF_VARSbyload-env.sh— see the note below), and - writes
.deploy-logs/agent-runtime-arn.env(a source-ableAGENT_RUNTIME_ARN=…). It also printsAGENT_RUNTIME_ARN=<arn>on stdout for CI/scripting.
- writes
terraform apply $TF_VARS— re-apply (after re-sourcingload-env.sh) so the saved ARN is picked up, wiringagent-invoker,websocket, andchatto the real runtime (env var + IAMbedrock-agentcore:InvokeAgentRuntime).
Terraform is run directly (see local deployment); only the agent
deploy itself is a make target.
source scripts/load-env.sh # exports $TF_VARS etc.
# 1. Base infra (if not already applied):
cd infra && terraform apply $TF_VARS && cd ..
# 2. Deploy the runtime — saves the ARN to agent.auto.tfvars + .deploy-logs/…
make deploy-agent
# 3. Re-apply — $TF_VARS (from load-env.sh) includes agent.auto.tfvars, which supplies
# agent_runtime_arn:
source scripts/load-env.sh # re-source so $TF_VARS includes agent.auto.tfvars
cd infra && terraform apply $TF_VARS && cd ..Why sourcing
load-env.shmatters here. Terraform auto-loads*.auto.tfvarsonly from its working directory (infra/), not from theenvironments/<env>/subdirectory whereagent.auto.tfvarslives.load-env.shis what appends-var-file=environments/<env>/agent.auto.tfvarsto$TF_VARS. If you run a bareterraform apply -var-file=environments/<env>/terraform.tfvarswithout that var-file,agent_runtime_arnis""and the agent Lambdas fail every invocation withInvokeAgentRuntime404 (UnknownOperationException).
If you'd rather pass it explicitly instead of via $TF_VARS:
source .deploy-logs/agent-runtime-arn.env # sets $AGENT_RUNTIME_ARN
cd infra
terraform apply -var-file=environments/dev/terraform.tfvars -var agent_runtime_arn="$AGENT_RUNTIME_ARN"
cd ..- The
agentcoreCLI:pip install bedrock-agentcore-starter-toolkit. - The infrastructure from step 1 must exist first (the deploy script reads Terraform outputs).
- On a fresh account (no
.bedrock_agentcore.yaml), the script runsagentcore configureautomatically to create it. It runs fully non-interactive (--non-interactive, with an empty request-header allowlist via-rha ""), so there are no prompts — this is safe to run locally or in CI. If you have previously seen a wizard prompt such as "Configure request header allowlist? (yes/no)" or a terminal "CPR" warning, that was the older interactive path; it no longer appears. - Re-deploys are idempotent:
agentcore deployruns with--auto-update-on-conflict, so an existing runtime is updated in place instead of erroring.
make deploy-agent already persists the ARN to
infra/environments/<env>/agent.auto.tfvars, so every subsequent terraform apply $TF_VARS keeps the wiring — as long as you run apply with $TF_VARS from a sourced
load-env.sh (which adds that var-file; Terraform will not auto-load it from the
environments/<env>/ subdirectory on its own). That file is gitignored (*.auto.tfvars),
since the ARN is environment/account-specific. If you'd prefer it to load with no extra
var-file, move the value into environments/<env>/terraform.tfvars instead.