Add namecheap terraform provider

This commit is contained in:
Erik Stambaugh 2024-01-20 12:58:49 -08:00
parent b23546f7f1
commit 0d02812bd1
4 changed files with 57 additions and 1 deletions

1
.gitignore vendored
View file

@ -14,3 +14,4 @@ pubkey
.s3_id .s3_id
.s3_secret .s3_secret
ansible/credentials ansible/credentials
terraform/dns_*.tf

View file

@ -39,3 +39,16 @@ MASTODON_SIDEKIQ_COUNT = 2
# How many threads in each sidekiq container? # How many threads in each sidekiq container?
MASTODON_SIDEKIQ_THREADS = 100 MASTODON_SIDEKIQ_THREADS = 100
# Are we autoconfiguring Namecheap DNS via Terraform? Leave at zero for "no"
DNS_NAMECHEAP = 0
# https://registry.terraform.io/providers/namecheap/namecheap/latest/docs
# https://www.namecheap.com/support/knowledgebase/article.aspx/10502/2208/namecheap-terraform-provider/
# This is the username you use to log into Namecheap
DNS_NAMECHEAP_API_USERNAME =
# This is an API key you create according to https://www.namecheap.com/support/knowledgebase/article.aspx/10502/2208/namecheap-terraform-provider/
DNS_NAMECHEAP_API_KEY =

View file

@ -4,7 +4,7 @@ include ../config.mk
default: terraform default: terraform
# I hate sed too and I am so sorry for what I'm about to do # I hate sed too and I am so sorry for what I'm about to do
terraform: terraform-check *.tf terraform: terraform-check *.tf terraform-options
terraform init || terraform init -upgrade terraform init || terraform init -upgrade
terraform apply terraform apply
terraform output | sed \ terraform output | sed \
@ -69,6 +69,22 @@ pubkey:
ssh-keygen -t rsa -N "" -f privkey && mv privkey.pub pubkey; \ ssh-keygen -t rsa -N "" -f privkey && mv privkey.pub pubkey; \
fi fi
# optional components for terraform
terraform-options: config.tf tf-namecheap
tf-namecheap:
if test "$(DNS_NAMECHEAP)" -eq 1; then \
for FILE in namecheap/*; do \
sed $(SEDLINE) $${FILE} > $$(basename "$${FILE}"); \
done; \
else \
for FILE in namecheap/*; do \
echo rm -fv $$(basename "$${FILE}"); \
done; \
fi
# clean doesn't touch tfstate because we're not insane # clean doesn't touch tfstate because we're not insane
clean: clean:
rm -f privkey pubkey rm -f privkey pubkey

View file

@ -0,0 +1,26 @@
# configure a namecheap managed domain to use AWS Route53 nameservers
terraform {
required_providers {
namecheap = {
source = "namecheap/namecheap"
version = ">= 2.0.0"
}
}
}
provider "namecheap" {
user_name = "{{DNS_NAMECHEAP_API_USERNAME}}"
api_user = "{{DNS_NAMECHEAP_API_USERNAME}}"
api_key = "{{DNS_NAMECHEAP_API_KEY}}"
use_sandbox = false
}
resource "namecheap_domain_records" "mastodon" {
domain = "{{DOMAIN_NAME}}"
mode = "OVERWRITE"
nameservers = module.zone.route53_zone_name_servers["{{DOMAIN_NAME}}"]
}