AWS infrastructure provisioning (Terraform) plus an AWS account inventory tool (Go).
This repository assumes you are authenticated via the AWS CLI. No AWS credentials are stored in this repo.
bootstrap/creates the Terraform remote state backend (S3) using local state.infra/provisions the infrastructure.scripts/aws-inventory/is the Go inventory tool.out/is generated output (gitignored).
- AWS CLI installed and authenticated:
aws sts get-caller-identity
- Terraform >= 1.6
- Go >= 1.23
- Domain managed in Cloudflare (for example
example.com) - Cloudflare scoped API token for your zone (create at https://dash.cloudflare.com/profile/api-tokens):
- Template: Edit zone DNS
- Permissions: Zone:DNS:Edit, Zone:DNS:Read
- Zone Resources: Include -> Specific zone ->
<your-domain>
Enable pre-commit hooks:
pre-commit clean
pre-commit install
pre-commit run --all-filesDisable pre-commit hooks:
rm .git/hooks/pre-commitIf you authenticated with aws login using browser-based authentication for a non-SSO account, see Appendix: AWS CLI authentication at the end of this document.
Bootstrap creates:
- S3 bucket for Terraform state
terraform -chdir=bootstrap init
terraform -chdir=bootstrap apply -auto-approveTerraform backends cannot consume normal Terraform variables, so backend parameters are provided via a local, gitignored backend.hcl file.
Run this once after bootstrap:
STATE_BUCKET=$(terraform -chdir=bootstrap output -raw state_bucket_name)
cat > infra/backend.hcl <<EOF
bucket = "$STATE_BUCKET"
use_lockfile = true
EOFCreate a local, gitignored secrets file:
cp infra/secrets.auto.tfvars.example infra/secrets.auto.tfvarsFill in at minimum:
domain_namecloudflare_api_token
Optional:
owner(if omitted, owner tag defaults to the AWS caller identity ARN)ami_id_override(optional AMI ID to use instead of the default lookup)
terraform -chdir=infra init -backend-config=backend.hcl
terraform -chdir=infra apply -auto-approveThe application is served at:
https://app.<domain_name>
It returns a simple page that includes the instance hostname.
curl -s https://app.<domain_name>Run it multiple times to observe hostname changes behind the load balancer.
go run -C scripts/aws-inventory .Optional concurrency override:
go run . --concurrency 8
# or
AWS_INVENTORY_CONCURRENCY=8 go run .Output:
- human-readable summary to stdout
- JSON report written to
out/report.json
All architecture, decisions, invariants, and tradeoffs are documented in:
docs/ARCHITECTURE.md
Destroy in reverse order so the backend bucket is removed last:
terraform -chdir=infra destroy -auto-approve
terraform -chdir=bootstrap destroy -auto-approve -var=force_destroy_state_bucket=trueTerraform relies on the AWS SDK credential chain. Some AWS CLI authentication methods, especially aws login (browser-based authentication), work for the AWS CLI but are not visible to Terraform by default.
When this happens, Terraform fails with:
No valid credential sources found
aws login --profile loginThis command:
- authenticates you via the browser
- automatically creates or updates a
[profile login]section in~/.aws/config - stores credentials in the AWS CLI internal cache (not in config files)
You do not need to manually edit the login profile.
Terraform reads credentials from the default AWS profile unless told otherwise. To allow Terraform to reuse the credentials obtained by aws login, add the following to the default profile in ~/.aws/config:
[default]
credential_process = aws configure export-credentials --format process --profile loginThat's the only required change.
If region already exists under [default], keep it. If not, it is recommended (but not required) to add the same region used during aws login.
Example (optional but recommended):
[default]
region = il-central-1
credential_process = aws configure export-credentials --format process --profile loginaws loginauthenticates you and caches temporary credentials- Terraform cannot read that cache directly
credential_processinstructs Terraform to:- execute the AWS CLI and retrieve credentials on demand
aws configure export-credentials --format processoutputs credentials in a standard JSON format understood by Terraform
- No static credentials are written to disk
- AWS CLI and Terraform now share the same authenticated session
This setup is not needed if you use:
- IAM access keys in
~/.aws/credentials - EC2 / ECS IAM roles
- Standard AWS SSO (
aws configure sso+aws sso login)
It is only required for AWS CLI authentication flows that Terraform cannot consume directly.