Skip to content

Commit 78d335a

Browse files
committed
switch to CloudFlare for DNS and CDN
1 parent 6b416df commit 78d335a

File tree

3 files changed

+47
-65
lines changed

3 files changed

+47
-65
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.DS_Store
22
.terraform
33
*/terraform.tfstate*
4+
env_vars.sh

setup/env_vars.sh.sample

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# To authenticate with CloudFlare.com, set the following environment
2+
# variables:
3+
4+
export TF_VAR_CLOUDFLARE_EMAIL='your@email'
5+
export TF_VAR_CLOUDFLARE_TOKEN='someTOKEN'
6+

setup/main.tf

+40-65
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ provider "azurerm" {
1212
version = "~> 1.3"
1313
}
1414

15+
# Configure the Cloudflare provider
16+
variable CLOUDFLARE_EMAIL {}
17+
variable CLOUDFLARE_TOKEN {}
18+
19+
provider "cloudflare" {
20+
email = "${var.CLOUDFLARE_EMAIL}"
21+
token = "${var.CLOUDFLARE_TOKEN}"
22+
}
1523

1624
#######################################################################
1725
### 1. Resource Group:
@@ -81,77 +89,44 @@ output "css" {
8189
# We need to use a Content Delivery Network (CDN) to map a custom domain
8290
# to the Blob store contents. Specifically, we must use the
8391
# Premium (Verizon) CDN.
84-
resource "azurerm_cdn_profile" "test" {
85-
name = "myfirstcdnprofile"
86-
resource_group_name = "${azurerm_resource_group.serverless.name}"
87-
location = "West US"
88-
sku = "Premium_Verizon"
89-
90-
tags {
91-
environment = "Serverless Example"
92-
}
93-
}
94-
95-
resource "azurerm_cdn_endpoint" "test" {
96-
name = "${random_id.server.hex}"
97-
profile_name = "${azurerm_cdn_profile.test.name}"
98-
location = "${azurerm_resource_group.serverless.location}"
99-
resource_group_name = "${azurerm_resource_group.serverless.name}"
10092

101-
origin {
102-
name = "exampleCdnOrigin"
103-
host_name = "azure.serverlessexample.ga"
104-
}
105-
}
106-
107-
resource "azurerm_cdn_endpoint" "api" {
108-
name = "${random_id.server.hex}"
109-
profile_name = "${azurerm_cdn_profile.test.name}"
110-
location = "${azurerm_resource_group.serverless.location}"
111-
resource_group_name = "${azurerm_resource_group.serverless.name}"
112-
113-
origin {
114-
name = "exampleCdnOrigin"
115-
host_name = "api.serverlessexample.ga"
116-
}
117-
}
93+
# No need, CloudFlare will provide our CDN with just the below DNS
94+
# config
11895

11996
#######################################################################
12097
### 4. DNS:
121-
# You likely created this zone already, when setting up a newly registered
122-
# domain name and configuring the initial NS records.
123-
#
124-
# resource "azurerm_dns_zone" "example" {
125-
# name = "serverlessexample.ga"
126-
# resource_group_name = "${azurerm_resource_group.serverless.name}"
127-
#}
128-
129-
resource "azurerm_dns_a_record" "example" {
130-
name = "meow"
131-
zone_name = "serverlessexample.ga"
132-
resource_group_name = "mydnsrg"
133-
ttl = 300
134-
records = ["${azurerm_container_group.aci-api.ip_address}"]
135-
}
136-
resource "azurerm_dns_cname_record" "exampleapi" {
137-
name = "api"
138-
zone_name = "serverlessexample.ga"
139-
resource_group_name = "mydnsrg"
140-
ttl = 300
141-
# You'll set this up in the "Supplementary" portal for Verizon Premium CDN
142-
record = "meow.azureedge.net"
143-
}
144-
resource "azurerm_dns_cname_record" "example" {
145-
name = "azure"
146-
zone_name = "serverlessexample.ga"
147-
resource_group_name = "mydnsrg"
148-
ttl = 300
149-
# You'll set this up in the "Supplementary" portal for Verizon Premium CDN
150-
record = "serverlessexample.azureedge.net"
98+
# Since we want to make use of a free CDN and SSL termination service,
99+
# head over to CloudFlare.com, create your domain, and use the below to
100+
# configure it.
101+
resource "cloudflare_record" "cfmeow" {
102+
domain = "serverlessexample.ga"
103+
name = "meow"
104+
value = "${azurerm_container_group.aci-api.ip_address}"
105+
type = "A"
106+
# Enabling CDN is as easy as:
107+
proxied = true
108+
# ttl of 1 is "Automatic" in CloudFlare. If you're using CDN, you
109+
# want this
110+
ttl = 1
111+
}
112+
resource "cloudflare_record" "cfapi" {
113+
domain = "serverlessexample.ga"
114+
name = "api"
115+
value = "meow.azureedge.net"
116+
type = "CNAME"
117+
proxied = true
118+
ttl = 1
119+
}
120+
121+
resource "cloudflare_record" "cfazure" {
122+
domain = "serverlessexample.ga"
123+
name = "azure"
124+
value = "serverlessexample.azureedge.net"
125+
type = "CNAME"
126+
proxied = true
127+
ttl = 1
151128
}
152129

153-
154-
155130
#######################################################################
156131
### 5. Azure Container Instance:
157132
resource "random_id" "server" {

0 commit comments

Comments
 (0)