diff options
Diffstat (limited to 'content/blog/terraform')
-rw-r--r-- | content/blog/terraform/acme.md | 6 | ||||
-rw-r--r-- | content/blog/terraform/caa.md | 2 | ||||
-rw-r--r-- | content/blog/terraform/chart-http-datasources.md | 8 | ||||
-rw-r--r-- | content/blog/terraform/email-dns-unused-zone.md | 104 | ||||
-rw-r--r-- | content/blog/terraform/tofu.md | 18 |
5 files changed, 121 insertions, 17 deletions
diff --git a/content/blog/terraform/acme.md b/content/blog/terraform/acme.md index f19302b..37045fd 100644 --- a/content/blog/terraform/acme.md +++ b/content/blog/terraform/acme.md @@ -1,16 +1,16 @@ --- -title: Certificate management with opentofu and eventline +title: Certificate management with OpenTofu and eventline description: How I manage for my personal infrastructure date: 2024-03-06 tags: - Eventline -- opentofu +- OpenTofu - terraform --- ## Introduction -In this article, I will explain how I handle the management and automatic renewal of SSL certificates on my personal infrastructure using opentofu (the fork of terraform) and [eventline](https://www.exograd.com/products/eventline/). I chose to centralise the renewal on my single host running eventline and to generate a single wildcard certificate for each domain I manage. +In this article, I will explain how I handle the management and automatic renewal of SSL certificates on my personal infrastructure using OpenTofu (the fork of terraform) and [eventline](https://www.exograd.com/products/eventline/). I chose to centralise the renewal on my single host running eventline and to generate a single wildcard certificate for each domain I manage. ## Wildcard certificates diff --git a/content/blog/terraform/caa.md b/content/blog/terraform/caa.md index defcd6a..ce6ff37 100644 --- a/content/blog/terraform/caa.md +++ b/content/blog/terraform/caa.md @@ -3,7 +3,7 @@ title: CAA DNS records with OpenTofu description: How I manage which acme CA can issue certificates for me date: 2024-05-27 tags: -- opentofu +- OpenTofu - terraform --- diff --git a/content/blog/terraform/chart-http-datasources.md b/content/blog/terraform/chart-http-datasources.md index ebf0aba..5c4108d 100644 --- a/content/blog/terraform/chart-http-datasources.md +++ b/content/blog/terraform/chart-http-datasources.md @@ -1,18 +1,18 @@ --- -title: Manage helm charts extras with opentofu +title: Manage helm charts extras with OpenTofu description: a use case for the http datasource date: 2024-04-25 tags: - aws -- opentofu +- OpenTofu - terraform --- ## Introduction -When managing helm charts with opentofu (terraform), you often have to hard code correlated settings for versioning (like app version and chart version). Sometimes it goes even further and you need to fetch a policy or a manifest with some CRDs that the chart will depend on. +When managing helm charts with OpenTofu (terraform), you often have to hard code correlated settings for versioning (like app version and chart version). Sometimes it goes even further and you need to fetch a policy or a manifest with some CRDs that the chart will depend on. -Here is an example of how to manage that with opentofu and an http datasource for the AWS load balancer controller. +Here is an example of how to manage that with OpenTofu and an http datasource for the AWS load balancer controller. ## A word about the AWS load balancer controller diff --git a/content/blog/terraform/email-dns-unused-zone.md b/content/blog/terraform/email-dns-unused-zone.md new file mode 100644 index 0000000..e1f9b81 --- /dev/null +++ b/content/blog/terraform/email-dns-unused-zone.md @@ -0,0 +1,104 @@ +--- +title: Email DNS records for zones that do not send emails +description: Automated with terraform/OpenTofu +date: 2024-09-03 +tags: +- cloudflare +- DNS +- OpenTofu +- terraform +--- + +## Introduction + +There are multiple DNS records one needs to configure in order to setup and securely use a domain to send or receive emails: MX, DKIM, DMARC and SPF. + +An often overlooked fact is that you also need to configure some of these records even if you do not intend to use a domain to send emails. If you do not, scammers will spoof your domain to send fraudulent emails and your domain's reputation will suffer. + +## DNS email records you need + +### SPF + +The most important and only required record you need is a TXT record on the apex of your domain that advertises the fact that no server can send emails from your domain: +``` +"v=spf1 -all" +``` + +### MX + +If you do not intend to ever send emails, you certainly do not intend to receive emails either. Therefore you should consider removing all MX records on your zone. Oftentimes your registrar will provision some pointing to a free email infrastructure that they provide along with your domain. + +### DKIM + +You do not need DKIM records if you are not sending emails. + +### DMARC + +While not strictly necessary, I strongly recommend to set a DMARC record that instructs the world to explicitly reject all emails not matching the SPF policy: + +``` +"v=DMARC1;p=reject;sp=reject;pct=100" +``` + +## Terraform / OpenTofu code + +### Zones + +I use a map of simple objects to specify email profiles for my DNS zones: +``` hcl +locals { + zones = { + "adyxax.eu" = { emails = "adyxax" } + "adyxax.org" = { emails = "adyxax" } + "anne-so-et-julien.fr" = { emails = "no" } + } +} + +data "cloudflare_zone" "main" { + for_each = local.zones + + name = each.key +} +``` + +### SPF + +Then I map each profile to spf records: +``` hcl +locals { + spf = { + "adyxax" = "v=spf1 mx -all" + "no" = "v=spf1 -all" + } +} + +resource "cloudflare_record" "spf" { + for_each = local.zones + + name = "@" + type = "TXT" + value = local.spf[each.value.emails] + zone_id = data.cloudflare_zone.main[each.key].id +} +``` + +### DMARC + +The same mapping system we had for spf can be used here too, but I choose to keep things simple and in the scope of this article. My real setup has some clever tricks to make dmarc notifications work centralized to a single domain that will be the subject another post: + +``` hcl +resource "cloudflare_record" "dmarc" { + for_each = { for name, info in local.zones : + name => info if info.emails == "no" + } + + name = "@" + type = "TXT" + value = "v=DMARC1;p=reject;sp=reject;pct=100" + zone_id = data.cloudflare_zone.main[each.key].id +} +``` + +## Conclusion + +Please keep your email DNS records tight and secure! diff --git a/content/blog/terraform/tofu.md b/content/blog/terraform/tofu.md index 48ec621..b52b97f 100644 --- a/content/blog/terraform/tofu.md +++ b/content/blog/terraform/tofu.md @@ -1,20 +1,20 @@ --- -title: Testing opentofu +title: Testing OpenTofu description: Little improvements and what it means for small providers like mine date: 2024-01-31 tags: - Eventline -- opentofu +- OpenTofu - terraform --- ## Introduction -This January, the opentofu project announced the general availability of their terraform fork. Not much changes for now between terraform and opentofu (and that is a good thing!), as far as I can tell the announcement was mostly about the new provider registry and of course the truly open source license. +This January, the OpenTofu project announced the general availability of their terraform fork. Not much changes for now between terraform and OpenTofu (and that is a good thing!), as far as I can tell the announcement was mostly about the new provider registry and of course the truly open source license. ## Registry change -The opentofu registry already has all the providers you are accustomed to, but your state will need to be migrated with: +The OpenTofu registry already has all the providers you are accustomed to, but your state will need to be migrated with: ```sh tofu init -upgrade` ``` @@ -24,19 +24,19 @@ For some providers you might encounter the following warning: - Installed cloudflare/cloudflare v4.23.0. Signature validation was skipped due to the registry not containing GPG keys for this provider ``` -This is harmless and will resolve itself when the providers' developers provide the public GPG key used to sign their releases to the opentofu registry. The process is very simple thanks to their GitHub workflow automation. +This is harmless and will resolve itself when the providers' developers provide the public GPG key used to sign their releases to the OpenTofu registry. The process is very simple thanks to their GitHub workflow automation. ## Little improvements - `tofu init` seems significantly faster than `terraform init`. -- You never could interrupt a terraform plan with `C-C`. I am so very glad to see that it is not a problem with opentofu! This really needs more advertising: proper Unix signal handling is like a superpower that is too often ignored by modern software. -- `tofu test` can be used to assert things about your state and your configuration. I did not play with it yet but it opens [a whole new realm of possibilities](https://opentofu.org/docs/cli/commands/test/)! +- You never could interrupt a terraform plan with `C-C`. I am so very glad to see that it is not a problem with OpenTofu! This really needs more advertising: proper Unix signal handling is like a superpower that is too often ignored by modern software. +- `tofu test` can be used to assert things about your state and your configuration. I did not play with it yet but it opens [a whole new realm of possibilities](https://OpenTofu.org/docs/cli/commands/test/)! - `tofu import` can use expressions referencing other values or resources attributes, this is a big deal when handling massive imports! ## Eventline terraform provider -I did the required pull requests on the [opentofu registry](https://github.com/opentofu/registry) to have my [Eventline provider](https://github.com/adyxax/terraform-provider-eventline) all fixed up and ready to rock! +I did the required pull requests on the [OpenTofu registry](https://github.com/OpenTofu/registry) to have my [Eventline provider](https://github.com/adyxax/terraform-provider-eventline) all fixed up and ready to rock! ## Conclusion -I hope opentofu really takes off, the little improvements they made already feel like a breath of fresh air. Terraform could be so much more! +I hope OpenTofu really takes off, the little improvements they made already feel like a breath of fresh air. Terraform could be so much more! |