@@ -12,6 +12,14 @@ provider "azurerm" {
12
12
version = " ~> 1.3"
13
13
}
14
14
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
+ }
15
23
16
24
# ######################################################################
17
25
# ## 1. Resource Group:
@@ -81,77 +89,44 @@ output "css" {
81
89
# We need to use a Content Delivery Network (CDN) to map a custom domain
82
90
# to the Blob store contents. Specifically, we must use the
83
91
# 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 } "
100
92
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
118
95
119
96
# ######################################################################
120
97
# ## 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
151
128
}
152
129
153
-
154
-
155
130
# ######################################################################
156
131
# ## 5. Azure Container Instance:
157
132
resource "random_id" "server" {
0 commit comments