From 3284c5c8548be113a69d60a7edd1a4e83361bb5c Mon Sep 17 00:00:00 2001 From: sksat Date: Mon, 20 Dec 2021 02:03:03 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Revert=20"Revert=20"Cloudflare=20provider?= =?UTF-8?q?=E3=81=A7DNS=E3=83=AC=E3=82=B3=E3=83=BC=E3=83=89=E3=82=82?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=81=99=E3=82=8B""?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit c9dffd4e9e8b571303e945b02e5d5c426f72bbf5. --- terraform/.terraform.lock.hcl | 32 +++++++++++++++++++++++++++++++ terraform/dns.tf | 27 ++++++++++++++++++++++++++ terraform/{oci.tf => provider.tf} | 13 +++++++++++++ terraform/variable.tf | 1 + 4 files changed, 73 insertions(+) create mode 100644 terraform/dns.tf rename terraform/{oci.tf => provider.tf} (59%) diff --git a/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl index d9501a7..8d9eb80 100644 --- a/terraform/.terraform.lock.hcl +++ b/terraform/.terraform.lock.hcl @@ -1,6 +1,28 @@ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. +provider "registry.terraform.io/cloudflare/cloudflare" { + version = "3.5.0" + constraints = "3.5.0" + hashes = [ + "h1:iqvoG0iDGOL7+CQN2jpGVpUMPq9gREltz/wERdfKd5Y=", + "zh:0523b5f8082c43ae2fef5822c6f1426ab97fde7e6cd82ad7b912b921a41cd789", + "zh:0fe591cd01ad595820556e50fbde0fc85fe316a59b3cb2c16e4b15c6c16f7437", + "zh:102fd4eb66275bd4a48758ab4c8772bf3546b7006891360820fbbaaf9f14d001", + "zh:139366f9eb5dafafd812930f08067beeb9a7689c2f867db30472e60834758cbd", + "zh:1569e47f14210839463ef2269392a72a6b2346a0fb82ef57cae773834281dabb", + "zh:4b06a68c3e542f8a22916035185e0830ef8e4d411f71f77bf9179ab050d45b94", + "zh:590c3b740abce0315884c0f09af0922e00d9103189fc94c345491109afc07ab0", + "zh:5ae2882c898bda32186c4ffe4c81ae61074c10d8bd6dd5d6918f3e930da0ed66", + "zh:784f5e2a65232b1e10d09ff13e62a1485c34abbdb55c2aa6c7d828d959e8606d", + "zh:8c2fdcf17eb2e55646fdbd88560dff7f1644eb5478a9eea4336066db31b8ac7c", + "zh:b12b64bece15f025a9664e564ef9bf6b01c913a5899630840a8e5bac23cf923c", + "zh:d8e63ff45173ce5a80bc88bbfd1fa9473fd28374fd50fabba02a97d8f87f2e57", + "zh:d9d4ff5105b598800ccf40fc574420e6470b80bc12e20a47a6405f1376add270", + "zh:e768407999692cdf3f7359542937a37adee627a15452b0acde0a720eceef79bc", + ] +} + provider "registry.terraform.io/hashicorp/oci" { version = "4.57.0" constraints = "4.57.0" @@ -15,5 +37,15 @@ provider "registry.terraform.io/hashicorp/oci" { "h1:uPE7YvZj1CB4cGY1xWYkB51AtSOaoNMaFM/kHgw0f8c=", "h1:vpiOm/gRP/bmvJrwKEFB94RSuQ09cUjf4GToTerxQ+c=", "h1:xqSVf22el4bXZxGWLAY+rgiyrGdduE0EHss5Udz2k50=", + "zh:04037e0a5e59bf0f5c63939a63cd2ae902ba42110561e18a5e115d32dbbc6490", + "zh:061d32086b861859f8650903806f051d4163227cf86877904cd6292662b715c7", + "zh:3763c2ef6c1022df765f0d254d883c540ec96e0bd4761c897480359e46a8e560", + "zh:64872eee45a1ca7c2b63f5cc898cd5ded1e208b09d29642514e8f8948754d913", + "zh:66c6b280992e73d9fe7cd91dab7a1d1567f3b58f6fcda23049e6f506b58fc252", + "zh:7ca650a9d47564c11d301925d60c1ec48a1c541c6f016ebee3631434f718ad03", + "zh:91debc579b4356d49e795bd7ce0a59babdc3d501557f6824e9800f8195063121", + "zh:9781474b13fdd755177ab612173f8629fb96cded4f3992c7a7a91855fff22476", + "zh:a626626519fde75e3a9ad8c2db2294b1fcc8bbe5ca72c50da78182c3c79cf4eb", + "zh:f6c3c6397660d0b0537457dce465a9f6b6a95a5b1f6c0988d1996d115ebc835c", ] } diff --git a/terraform/dns.tf b/terraform/dns.tf new file mode 100644 index 0000000..45c7d05 --- /dev/null +++ b/terraform/dns.tf @@ -0,0 +1,27 @@ +locals { + # GitHub Pages IP + # https://docs.github.com/ja/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site + gh_pages_ips = [ + "185.199.108.153", + "185.199.109.153", + "185.199.110.153", + "185.199.111.153", + ] +} + +resource "cloudflare_record" "minecraft" { + zone_id = data.cloudflare_zone.yohanesu.id + name = "mc" + type = "A" + value = "45.76.188.189" +} + +resource "cloudflare_record" "gh_pages" { + zone_id = data.cloudflare_zone.yohanesu.id + name = "yohane.su" + type = "A" + proxied = true + + for_each = toset(local.gh_pages_ips) + value = each.value +} diff --git a/terraform/oci.tf b/terraform/provider.tf similarity index 59% rename from terraform/oci.tf rename to terraform/provider.tf index a04c878..17f13df 100644 --- a/terraform/oci.tf +++ b/terraform/provider.tf @@ -4,6 +4,11 @@ terraform { source = "hashicorp/oci" version = "4.57.0" } + + cloudflare = { + source = "cloudflare/cloudflare" + version = "3.5.0" + } } } @@ -14,3 +19,11 @@ provider "oci" { fingerprint = var.OCID_FINGERPRINT private_key = var.OCID_PRIVATE_KEY } + +provider "cloudflare" { + api_token = var.CF_DNS_TOKEN +} + +data "cloudflare_zone" "yohanesu" { + name = "yohane.su" +} diff --git a/terraform/variable.tf b/terraform/variable.tf index 3fc9d35..d618560 100644 --- a/terraform/variable.tf +++ b/terraform/variable.tf @@ -6,3 +6,4 @@ variable "OCID_COMPARTMENT" {} variable "OCID_SUBNET" {} variable "OCID_SOURCE" {} variable "OCID_VCN" {} +variable "CF_DNS_TOKEN" {} From 3a1357b4cf282eababda1c4e69436c66342e5b1e Mon Sep 17 00:00:00 2001 From: sksat Date: Mon, 20 Dec 2021 02:53:06 +0900 Subject: [PATCH 2/2] update: allow overwrite cloudflare_record --- terraform/dns.tf | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/terraform/dns.tf b/terraform/dns.tf index 45c7d05..4d30a48 100644 --- a/terraform/dns.tf +++ b/terraform/dns.tf @@ -10,17 +10,19 @@ locals { } resource "cloudflare_record" "minecraft" { - zone_id = data.cloudflare_zone.yohanesu.id - name = "mc" - type = "A" - value = "45.76.188.189" + zone_id = data.cloudflare_zone.yohanesu.id + name = "mc" + type = "A" + value = "45.76.188.189" + allow_overwrite = true } resource "cloudflare_record" "gh_pages" { - zone_id = data.cloudflare_zone.yohanesu.id - name = "yohane.su" - type = "A" - proxied = true + zone_id = data.cloudflare_zone.yohanesu.id + name = "yohane.su" + type = "A" + proxied = true + allow_overwrite = true for_each = toset(local.gh_pages_ips) value = each.value