Skip to content

Commit ff10928

Browse files
committed
Add OpenTofu docs, switch to OpenTofu in workflow
1 parent bfc786f commit ff10928

File tree

8 files changed

+47
-55
lines changed

8 files changed

+47
-55
lines changed

.github/workflows/release-build-and-deploy.yml

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,8 @@ jobs:
129129
- name: Checkout code
130130
uses: actions/checkout@v4
131131

132-
- name: Set up Terraform
133-
uses: hashicorp/setup-terraform@v3
134-
135-
# TODO: Replace above step with this
136-
# - name: Set up OpenTofu
137-
# uses: hashicorp/setup-opentofu@v1
132+
- name: Set up OpenTofu
133+
uses: hashicorp/setup-opentofu@v1
138134

139135
- name: Configure AWS credentials
140136
uses: aws-actions/configure-aws-credentials@v4
@@ -143,36 +139,26 @@ jobs:
143139
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
144140
aws-region: ${{ needs.set-deployment-variables.outputs.aws_region }}
145141

146-
- name: Initialize Terraform
142+
- name: Initialize Tofu
147143
run: |
148-
cd terraform
149-
terraform init
144+
tofu -chdir=infra init
150145
151-
- name: Terraform Plan
146+
- name: Tofu Plan
152147
run: |
153-
cd terraform
154-
terraform plan \
148+
tofu -chdir=infra plan \
155149
-var="aws_region=${{ needs.set-deployment-variables.outputs.aws_region }}" \
156150
-var="environment=dev" \
157151
-var="cloudflare_api_token=${{ secrets.CLOUDFLARE_API_TOKEN }}" \
158152
-var="cloudflare_zone_id=${{ secrets.CLOUDFLARE_ZONE_ID }}" \
159153
-var="domain_name=${{ needs.set-deployment-variables.outputs.domain_name }}" \
160154
-var="subdomain=${{ needs.set-deployment-variables.outputs.subdomain }}"
161155
162-
- name: Terraform Apply
156+
- name: Tofu Apply
163157
run: |
164-
cd terraform
165-
terraform apply -auto-approve \
158+
tofu -chdir=infra apply -auto-approve \
166159
-var="aws_region=${{ needs.set-deployment-variables.outputs.aws_region }}" \
167160
-var="environment=dev" \
168161
-var="cloudflare_api_token=${{ secrets.CLOUDFLARE_API_TOKEN }}" \
169162
-var="cloudflare_zone_id=${{ secrets.CLOUDFLARE_ZONE_ID }}" \
170163
-var="domain_name=${{ needs.set-deployment-variables.outputs.domain_name }}" \
171164
-var="subdomain=${{ needs.set-deployment-variables.outputs.subdomain }}"
172-
173-
# TODO: Replace above three steps with these
174-
# - name: Initialize Tofu
175-
176-
# - name: Tofu Plan
177-
178-
# - name: Tofu Apply
File renamed without changes.
Lines changed: 14 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# AI Usage Log - Terraform Configuration
1+
# AI Usage Log - OpenTofu/Terraform Configuration
22

3-
This directory contains Terraform configurations for deploying the AI Usage Log application on AWS Fargate.
3+
This directory contains OpenTofu/Terraform configurations for deploying the AI Usage Log application on AWS Fargate.
44

55
## Architecture
66

@@ -74,27 +74,29 @@ This setup uses a hybrid DNS approach combining Amazon Route 53 and Cloudflare:
7474
### Understanding the DNS Flow
7575

7676
1. **Cloudflare** manages your root domain (e.g., `suhailskhan.com`)
77-
2. **Terraform** creates a Route 53 hosted zone for your subdomain (e.g., `ai-usage-log.suhailskhan.com`)
78-
3. **Terraform** automatically creates NS records in Cloudflare pointing the subdomain to AWS nameservers
77+
2. **OpenTofu/Terraform** creates a Route 53 hosted zone for your subdomain (e.g., `ai-usage-log.suhailskhan.com`)
78+
3. **OpenTofu/Terraform** automatically creates NS records in Cloudflare pointing the subdomain to AWS nameservers
7979
4. **Route 53** takes full control of DNS for the subdomain and integrates with the ALB
8080
5. **ACM** validates the SSL certificate using DNS validation in Route 53
8181
6. **Traffic flows directly** from users → Route 53 → ALB
8282

8383
## Deployment Steps
8484

85-
1. Initialize Terraform:
85+
The following steps use OpenTofu, but you may substitute the commands with Terraform commands.
86+
87+
1. Initialize OpenTofu:
8688
```
87-
terraform init
89+
tofu init
8890
```
8991

9092
2. Review the plan:
9193
```
92-
terraform plan
94+
tofu plan
9395
```
9496

9597
3. Apply the configuration:
9698
```
97-
terraform apply
99+
tofu apply
98100
```
99101

100102
4. Store environment variables in AWS Secrets Manager:
@@ -144,5 +146,5 @@ curl -I https://ai-usage-log.suhailskhan.com
144146

145147
To destroy all created resources:
146148
```
147-
terraform destroy
149+
tofu destroy
148150
```

terraform/main.tf renamed to infra/main.tf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,29 +717,25 @@ resource "cloudflare_record" "ai_usage_log_ns_1" {
717717
name = var.subdomain
718718
content = aws_route53_zone.ai_usage_log.name_servers[0]
719719
type = "NS"
720-
ttl = 300
721720
}
722721

723722
resource "cloudflare_record" "ai_usage_log_ns_2" {
724723
zone_id = var.cloudflare_zone_id
725724
name = var.subdomain
726725
content = aws_route53_zone.ai_usage_log.name_servers[1]
727726
type = "NS"
728-
ttl = 300
729727
}
730728

731729
resource "cloudflare_record" "ai_usage_log_ns_3" {
732730
zone_id = var.cloudflare_zone_id
733731
name = var.subdomain
734732
content = aws_route53_zone.ai_usage_log.name_servers[2]
735733
type = "NS"
736-
ttl = 300
737734
}
738735

739736
resource "cloudflare_record" "ai_usage_log_ns_4" {
740737
zone_id = var.cloudflare_zone_id
741738
name = var.subdomain
742739
content = aws_route53_zone.ai_usage_log.name_servers[3]
743740
type = "NS"
744-
ttl = 300
745741
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ subdomain = "ai-usage-log"
55

66
# Cloudflare Configuration
77
# Get your API token from: https://dash.cloudflare.com/profile/api-tokens
8-
# The token needs Zone:Edit permissions for suhailskhan.com
8+
# The token needs Zone:Edit permissions for your domain
99
cloudflare_api_token = "your-cloudflare-api-token-here"
1010

1111
# Get your zone ID from the Cloudflare Dashboard

infra/tofu.tfvars.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
aws_region = "us-east-1"
2+
environment = "dev"
3+
domain_name = "suhailskhan.com"
4+
subdomain = "ai-usage-log"
5+
6+
# Cloudflare Configuration
7+
# Get your API token from: https://dash.cloudflare.com/profile/api-tokens
8+
# The token needs Zone:Edit permissions for your domain
9+
cloudflare_api_token = "your-cloudflare-api-token-here"
10+
11+
# Get your zone ID from the Cloudflare Dashboard
12+
# Found in the domain overview page, right sidebar
13+
cloudflare_zone_id = "your-cloudflare-zone-id-here"

0 commit comments

Comments
 (0)