|
1 | 1 | # Terraform Configurations |
2 | 2 |
|
3 | | -Infrastructure as Code for cloud resource provisioning. |
| 3 | +Infrastructure as Code for VertexChain cloud resource provisioning. |
4 | 4 |
|
5 | 5 | ## Overview |
6 | 6 |
|
7 | | -Terraform modules for provisioning cloud infrastructure for VertexChain. |
| 7 | +Terraform modules for provisioning AWS infrastructure for VertexChain, |
| 8 | +a location-aware micro-messaging platform built on Stellar. |
8 | 9 |
|
9 | | -## Contents |
| 10 | +## Module Structure |
10 | 11 |
|
11 | | -- AWS/GCP/Azure resource definitions |
12 | | -- Network configurations |
13 | | -- Database provisioning |
14 | | -- Storage buckets |
15 | | -- Load balancers |
| 12 | +``` |
| 13 | +infrastructure/terraform/ |
| 14 | +├── main.tf # Root module entry point |
| 15 | +├── variables.tf # Root module input variables |
| 16 | +├── outputs.tf # Root module outputs (ARNs for every resource) |
| 17 | +├── providers.tf # Terraform and provider configuration |
| 18 | +├── modules/ |
| 19 | +│ ├── network/ # VPC, subnets, gateways, NACLs, security groups |
| 20 | +│ ├── compute/ # EKS, ASG, ALB, launch templates, target groups |
| 21 | +│ └── data/ # RDS, ElastiCache, S3, backup vaults & plans |
| 22 | +├── envs/ # Per-environment tfvars files |
| 23 | +│ ├── terraform.tfvars.dev |
| 24 | +│ ├── terraform.tfvars.staging |
| 25 | +│ ├── terraform.tfvars.prod |
| 26 | +│ └── terraform.tfvars.example |
| 27 | +├── tests/ # Terratest integration tests |
| 28 | +│ └── test_helper.go |
| 29 | +└── archive/ # Previous flat .tf files (kept for reference) |
| 30 | +``` |
16 | 31 |
|
17 | 32 | ## Usage |
18 | 33 |
|
19 | | -Run `terraform plan` and `terraform apply` to provision resources. |
| 34 | +```bash |
| 35 | +# Initialize Terraform |
| 36 | +terraform init |
| 37 | + |
| 38 | +# Select workspace |
| 39 | +terraform workspace select dev || terraform workspace new dev |
| 40 | + |
| 41 | +# Plan with environment-specific variables |
| 42 | +terraform plan -var-file=envs/terraform.tfvars.dev |
| 43 | + |
| 44 | +# Apply changes |
| 45 | +terraform apply -var-file=envs/terraform.tfvars.dev |
| 46 | +``` |
| 47 | +
|
| 48 | +## Workspace Strategy |
| 49 | +
|
| 50 | +Per-environment state isolation is handled by workspaces. Each environment |
| 51 | +uses its own `tfvars` file while sharing the same root module: |
| 52 | +
|
| 53 | +| Environment | Workspace | Variable file | |
| 54 | +|-------------|-----------|--------------------------| |
| 55 | +| dev | `dev` | `envs/terraform.tfvars.dev` | |
| 56 | +| staging | `staging` | `envs/terraform.tfvars.staging` | |
| 57 | +| prod | `prod` | `envs/terraform.tfvars.prod` | |
| 58 | +
|
| 59 | +## Outputs |
| 60 | +
|
| 61 | +All resource ARNs are surfaced through the root module's `outputs.tf`. |
| 62 | +Run `terraform output` to see the full list after an apply. |
| 63 | +
|
| 64 | +```bash |
| 65 | +terraform output |
| 66 | +# vpc_id = "vpc-xxx" |
| 67 | +# alb_arn = "arn:aws:elasticloadbalancing:..." |
| 68 | +# rds_instance_arn = "arn:aws:rds:..." |
| 69 | +# redis_replication_group_arn = "arn:aws:elasticache:..." |
| 70 | +# s3_uploads_bucket_arn = "arn:aws:s3:::..." |
| 71 | +# eks_cluster_arn = "arn:aws:eks:..." |
| 72 | +# waf_web_acl_arn = "arn:aws:wafv2:..." |
| 73 | +# cloudfront_distribution_arn = "arn:aws:cloudfront:..." |
| 74 | +# ...and many more |
| 75 | +``` |
| 76 | +
|
| 77 | +## Migrating from the flat structure |
| 78 | +
|
| 79 | +The previous flat `.tf` files (vpc.tf, rds.tf, etc.) have been refactored into |
| 80 | +the submodule structure above. The original files are preserved in the |
| 81 | +`archive/` directory for reference and should be removed once the new modular |
| 82 | +structure is validated. |
| 83 | +
|
| 84 | +Before applying the new module structure to an existing deployment: |
| 85 | +
|
| 86 | +1. Import existing resources into the new module state: |
| 87 | + ```bash |
| 88 | + terraform import module.network.aws_vpc.this vpc-xxx |
| 89 | + terraform import module.data.aws_db_instance.postgres db-xxx |
| 90 | + # ... etc. |
| 91 | + ``` |
| 92 | +
|
| 93 | +2. Run `terraform plan` to verify no unexpected changes. |
| 94 | +
|
| 95 | +3. Apply once all differences are reconciled. |
0 commit comments