Difference between revisions of "Terraform resource: cloudflare record"

From wikieduonline
Jump to navigation Jump to search
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record
+
<code>cloudflare_record</code>
 +
* https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/resources/record
  
[[proxied]]
+
* Required: <code>name, type and [[zone_id]]</code>
 +
* Options: <code>[[proxied]]</code>
  
 
== Official example ==
 
== Official example ==
Line 34: Line 36:
 
  }
 
  }
  
== Exampl with data [[cloudflare_zones]] ==
+
== Example with data [[cloudflare_zones]] ==
  
 
https://github.com/djangoflow/terraform-kubernetes-django/blob/main/modules/cloudflare/main.tf  
 
https://github.com/djangoflow/terraform-kubernetes-django/blob/main/modules/cloudflare/main.tf  
data "cloudflare_zones" "zones" {
 
  filter {}
 
}
 
  
  locals {
+
  {{cloudflare_zones_django_example}}
  zones = {for zone in data.cloudflare_zones.zones.zones : zone.name => zone.id}
+
 
}
+
== Related ==
+
* [[Terraform resource: aws route53 record]]
resource "cloudflare_record" "record" {
 
  for_each = var.records
 
  name    = each.key
 
  type    = each.value.type
 
  value    = each.value.value
 
  proxied  = each.value.proxied
 
  zone_id  = lookup(local.zones, regex(".*?([^.]+\\.[^.]+)$", each.key)[0])
 
  lifecycle {
 
    ignore_changes = [zone_id]
 
  }
 
}
 
  
 
== See also ==
 
== See also ==
Line 62: Line 50:
 
[[Category:Cloudflare]]
 
[[Category:Cloudflare]]
 
[[Category:Terraform]]
 
[[Category:Terraform]]
 +
[[Category:Terraform]]
 +
[[Category:DNS]]

Latest revision as of 08:52, 29 May 2024

cloudflare_record

Official example[edit]

 resource "cloudflare_record" "example" {
 zone_id = var.cloudflare_zone_id
 name    = "terraform"
 value   = "192.0.2.1"
 type    = "A"
 ttl     = 3600
}


# Add a record to the domain
resource "cloudflare_record" "example" {
  zone_id = var.cloudflare_zone_id
  name    = "terraform"
  value   = "192.0.2.1"
  type    = "A"
  ttl     = 3600
}

# Add a record requiring a data map
resource "cloudflare_record" "_sip_tls" {
 zone_id = var.cloudflare_zone_id
 name    = "_sip._tls"
 type    = "SRV"

 data {
   service  = "_sip"
   proto    = "_tls"
   name     = "terraform-srv"
   priority = 0
   weight   = 0
   port     = 443
   target   = "example.com"
 }
}

Example with data cloudflare_zones[edit]

https://github.com/djangoflow/terraform-kubernetes-django/blob/main/modules/cloudflare/main.tf

 data "cloudflare_zones" "zones" {
  filter {}
}

locals {
  zones = {for zone in data.cloudflare_zones.zones.zones : zone.name => zone.id}
}

resource "cloudflare_record" "record" {
  for_each = var.records
  name     = each.key
  type     = each.value.type
  value    = each.value.value
  proxied  = each.value.proxied
  zone_id  = lookup(local.zones, regex(".*?([^.]+\\.[^.]+)$", each.key)[0])
  lifecycle {
    ignore_changes = [zone_id]
  }
}

Related[edit]

See also[edit]

Advertising: