Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor gandi configuration in a TF module #1084

Merged
merged 3 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 12 additions & 64 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,10 @@ variable "project" {
variable "domain" {
default = "androidmakers.fr"
}
//
variable "gandi_access_token" {
type = string
}

# Also create "androidmakers-tfstate" as it can sadly not be a variable
# Typically use the same resource as for tfstate-bucket above (but doest have to)
variable "region" {
default = "europe-west9"
}

terraform {
backend "gcs" {
bucket = "androidmakers-tfstate"
prefix = "terraform/state"
}
}

terraform {
required_providers {
gandi = {
Expand All @@ -49,63 +35,25 @@ provider "gandi" {
personal_access_token = var.gandi_access_token
}

import {
id = "androidmakers.fr"
to = gandi_domain.androidmakers_fr
}

resource "gandi_domain" "androidmakers_fr" {
name = "androidmakers.fr"

# The owner block is required even though sadly it's not supported by the current provider
owner {
email = "placeholder"
type = "company"
street_addr = "placeholder"
zip = "placeholder"
phone = "placeholder"
given_name = "placeholder"
family_name = "placeholder"
country = "FR"
city = "placeholder"
state = "placeholder"
mail_obfuscated = true
organisation = "placeholder"
data_obfuscated = true
}
lifecycle {
ignore_changes = [
# "Error: domain owner contact update is currently not supported"
owner,
]
}
}

import {
id = "androidmakers.fr"
to = gandi_livedns_domain.androidmakers_fr
}
module "gandi" {
source = "./modules/gandi"

resource "gandi_livedns_domain" "androidmakers_fr" {
name = "androidmakers.fr"
loadbalancer_ip = google_compute_global_address.default.address
}

import {
id = "androidmakers.fr/@/A"
to = gandi_livedns_record.androidmakers_fr
# Also create "androidmakers-tfstate" as it can sadly not be a variable
# Typically use the same resource as for tfstate-bucket above (but doest have to)
variable "region" {
default = "europe-west9"
}

resource "gandi_livedns_record" "androidmakers_fr" {
zone = gandi_livedns_domain.androidmakers_fr.id
name = "@"
type = "A"
ttl = 3600
values = [
google_compute_global_address.default.address
]
terraform {
backend "gcs" {
bucket = "androidmakers-tfstate"
prefix = "terraform/state"
}
}


provider google-beta {
project = var.project
region = var.region
Expand Down
49 changes: 49 additions & 0 deletions terraform/modules/gandi/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
terraform {
required_providers {
gandi = {
version = "2.3.0"
source = "go-gandi/gandi"
}
}
}

resource "gandi_domain" "androidmakers_fr" {
name = "androidmakers.fr"

# The owner block is required even though sadly it's not supported by the current provider
owner {
email = "placeholder"
type = "company"
street_addr = "placeholder"
zip = "placeholder"
phone = "placeholder"
given_name = "placeholder"
family_name = "placeholder"
country = "FR"
city = "placeholder"
state = "placeholder"
mail_obfuscated = true
organisation = "placeholder"
data_obfuscated = true
}
lifecycle {
ignore_changes = [
# "Error: domain owner contact update is currently not supported"
owner,
]
}
}

resource "gandi_livedns_domain" "androidmakers_fr" {
name = "androidmakers.fr"
}

resource "gandi_livedns_record" "androidmakers_fr" {
zone = gandi_livedns_domain.androidmakers_fr.id
name = "@"
type = "A"
ttl = 3600
values = [
var.loadbalancer_ip
]
}
Empty file.
4 changes: 4 additions & 0 deletions terraform/modules/gandi/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

variable "loadbalancer_ip" {
type = string
}
Loading