[{"data":1,"prerenderedAt":1649},["ShallowReactive",2],{"post:terraform-infra-personal":3},{"id":4,"title":5,"body":6,"date":1634,"description":1635,"draft":1636,"extension":1637,"meta":1638,"navigation":147,"path":1639,"seo":1640,"stem":1641,"tags":1642,"__hash__":1648},"posts\u002Fposts\u002Fterraform-infra-personal.md","Automating My Site Infrastructure with Terraform",{"type":7,"value":8,"toc":1625},"minimark",[9,18,65,69,79,90,99,102,110,227,230,251,258,409,412,524,527,533,554,560,654,661,677,680,686,695,794,807,817,904,911,914,919,942,945,979,982,985,1065,1072,1085,1127,1130,1139,1149,1255,1258,1265,1345,1356,1402,1405,1595,1605,1612,1615,1618,1621],[10,11,12,13,17],"p",{},"I just reworked my personal site to automate ",[14,15,16],"em",{},"nearly"," all of its setup in terraform (with some help from GPT Luna), and thought I'd blog a bit about how it works.",[19,20,21,29,35,41,47,53,59],"ul",{},[22,23,24],"li",{},[25,26,28],"a",{"href":27},"#define-services-and-variables","Define services and variables",[22,30,31],{},[25,32,34],{"href":33},"#domain-registration","Domain Registration",[22,36,37],{},[25,38,40],{"href":39},"#dns-records","DNS Records",[22,42,43],{},[25,44,46],{"href":45},"#netlify-hosting","Netlify Hosting",[22,48,49],{},[25,50,52],{"href":51},"#uptime-robot","Uptime Robot",[22,54,55],{},[25,56,58],{"href":57},"#validate-on-push","Validate On Push",[22,60,61],{},[25,62,64],{"href":63},"#conclusion","Conclusion",[66,67,28],"h2",{"id":68},"define-services-and-variables",[10,70,71,72,78],{},"For a simple site like ",[25,73,77],{"href":74,"rel":75},"https:\u002F\u002Fmichaelborn.me",[76],"nofollow","michaelborn.me",", there are just a few services I needed:",[19,80,81,84,87],{},[22,82,83],{},"Cloudflare (domain registration and DNS management)",[22,85,86],{},"Netlify (static site hosting)",[22,88,89],{},"Uptime Robot (uptime monitors)",[10,91,92,93,98],{},"Later, I'd like to add ",[25,94,97],{"href":95,"rel":96},"https:\u002F\u002Fsentry.io",[76],"sentry.io","... but we'll leave that for another day. 🙂",[10,100,101],{},"For each of these I needed to grab an API key or token from my account settings, as well as a few other details. Note that neither Cloudflare domain registration nor Netlify site setup are programmable at this time, so you'll need to set those up through the UI before continuing.",[10,103,104,105,109],{},"Once I had the api keys\u002Ftokens and a few other details, I recorded them in a vcs-ignored ",[106,107,108],"code",{},".tfvars"," file:",[111,112,117],"pre",{"className":113,"code":114,"language":115,"meta":116,"style":116},"language-sh shiki shiki-themes github-light github-dark","# terraform.tfvars\ndomain = \"michaelborn.me\"\n\nnetlify_site_name = \"mysitename\"\nnetlify_team_slug = \"myteamslug\"\n\ncloudflare_account_id = \"xyz_123\"\ncloudflare_api_token = \"cloudflare_api_token_here\"\n\nnetlify_api_token    = \"netlify_api_token_here\"\nuptimerobot_api_key  = \"uptime_robot_api_key\"\n","sh","",[106,118,119,128,142,149,160,171,176,187,198,203,215],{"__ignoreMap":116},[120,121,124],"span",{"class":122,"line":123},"line",1,[120,125,127],{"class":126},"sJ8bj","# terraform.tfvars\n",[120,129,131,135,139],{"class":122,"line":130},2,[120,132,134],{"class":133},"sScJk","domain",[120,136,138],{"class":137},"sZZnC"," =",[120,140,141],{"class":137}," \"michaelborn.me\"\n",[120,143,145],{"class":122,"line":144},3,[120,146,148],{"emptyLinePlaceholder":147},true,"\n",[120,150,152,155,157],{"class":122,"line":151},4,[120,153,154],{"class":133},"netlify_site_name",[120,156,138],{"class":137},[120,158,159],{"class":137}," \"mysitename\"\n",[120,161,163,166,168],{"class":122,"line":162},5,[120,164,165],{"class":133},"netlify_team_slug",[120,167,138],{"class":137},[120,169,170],{"class":137}," \"myteamslug\"\n",[120,172,174],{"class":122,"line":173},6,[120,175,148],{"emptyLinePlaceholder":147},[120,177,179,182,184],{"class":122,"line":178},7,[120,180,181],{"class":133},"cloudflare_account_id",[120,183,138],{"class":137},[120,185,186],{"class":137}," \"xyz_123\"\n",[120,188,190,193,195],{"class":122,"line":189},8,[120,191,192],{"class":133},"cloudflare_api_token",[120,194,138],{"class":137},[120,196,197],{"class":137}," \"cloudflare_api_token_here\"\n",[120,199,201],{"class":122,"line":200},9,[120,202,148],{"emptyLinePlaceholder":147},[120,204,206,209,212],{"class":122,"line":205},10,[120,207,208],{"class":133},"netlify_api_token",[120,210,211],{"class":137},"    =",[120,213,214],{"class":137}," \"netlify_api_token_here\"\n",[120,216,218,221,224],{"class":122,"line":217},11,[120,219,220],{"class":133},"uptimerobot_api_key",[120,222,223],{"class":137},"  =",[120,225,226],{"class":137}," \"uptime_robot_api_key\"\n",[10,228,229],{},"For anyone following along, it it is HIGHLY important you ignore this file from your VCS of choice!",[111,231,233],{"className":113,"code":232,"language":115,"meta":116,"style":116},"echo 'terraform.tfvars' >> .gitignore\n",[106,234,235],{"__ignoreMap":116},[120,236,237,241,244,248],{"class":122,"line":123},[120,238,240],{"class":239},"sj4cs","echo",[120,242,243],{"class":137}," 'terraform.tfvars'",[120,245,247],{"class":246},"szBVR"," >>",[120,249,250],{"class":137}," .gitignore\n",[10,252,253,254,257],{},"After defining the various api keys and secrets, I then created ",[106,255,256],{},"main.tf"," to define the basic providers I'll be working with, and the terraform provider versions:",[111,259,263],{"className":260,"code":261,"language":262,"meta":116,"style":116},"language-hcl shiki shiki-themes github-light github-dark","terraform {\n  required_version = \">= 1.8\"\n\n  required_providers {\n    cloudflare = {\n      source  = \"cloudflare\u002Fcloudflare\"\n      version = \"~> 5.0\"\n    }\n    netlify = {\n      source  = \"netlify\u002Fnetlify\"\n      version = \"~> 0.4.0\"\n    }\n    uptimerobot = {\n      source  = \"uptimerobot\u002Fuptimerobot\"\n      version = \"~> 1.15\"\n    }\n  }\n}\n","hcl",[106,264,265,274,284,288,295,304,315,325,330,339,348,357,362,372,382,392,397,403],{"__ignoreMap":116},[120,266,267,270],{"class":122,"line":123},[120,268,269],{"class":133},"terraform",[120,271,273],{"class":272},"sVt8B"," {\n",[120,275,276,279,281],{"class":122,"line":130},[120,277,278],{"class":272},"  required_version",[120,280,138],{"class":246},[120,282,283],{"class":137}," \">= 1.8\"\n",[120,285,286],{"class":122,"line":144},[120,287,148],{"emptyLinePlaceholder":147},[120,289,290,293],{"class":122,"line":151},[120,291,292],{"class":133},"  required_providers",[120,294,273],{"class":272},[120,296,297,300,302],{"class":122,"line":162},[120,298,299],{"class":272},"    cloudflare",[120,301,138],{"class":246},[120,303,273],{"class":272},[120,305,306,309,312],{"class":122,"line":173},[120,307,308],{"class":272},"      source  ",[120,310,311],{"class":246},"=",[120,313,314],{"class":137}," \"cloudflare\u002Fcloudflare\"\n",[120,316,317,320,322],{"class":122,"line":178},[120,318,319],{"class":272},"      version ",[120,321,311],{"class":246},[120,323,324],{"class":137}," \"~> 5.0\"\n",[120,326,327],{"class":122,"line":189},[120,328,329],{"class":272},"    }\n",[120,331,332,335,337],{"class":122,"line":200},[120,333,334],{"class":272},"    netlify",[120,336,138],{"class":246},[120,338,273],{"class":272},[120,340,341,343,345],{"class":122,"line":205},[120,342,308],{"class":272},[120,344,311],{"class":246},[120,346,347],{"class":137}," \"netlify\u002Fnetlify\"\n",[120,349,350,352,354],{"class":122,"line":217},[120,351,319],{"class":272},[120,353,311],{"class":246},[120,355,356],{"class":137}," \"~> 0.4.0\"\n",[120,358,360],{"class":122,"line":359},12,[120,361,329],{"class":272},[120,363,365,368,370],{"class":122,"line":364},13,[120,366,367],{"class":272},"    uptimerobot",[120,369,138],{"class":246},[120,371,273],{"class":272},[120,373,375,377,379],{"class":122,"line":374},14,[120,376,308],{"class":272},[120,378,311],{"class":246},[120,380,381],{"class":137}," \"uptimerobot\u002Fuptimerobot\"\n",[120,383,385,387,389],{"class":122,"line":384},15,[120,386,319],{"class":272},[120,388,311],{"class":246},[120,390,391],{"class":137}," \"~> 1.15\"\n",[120,393,395],{"class":122,"line":394},16,[120,396,329],{"class":272},[120,398,400],{"class":122,"line":399},17,[120,401,402],{"class":272},"  }\n",[120,404,406],{"class":122,"line":405},18,[120,407,408],{"class":272},"}\n",[10,410,411],{},"Then I configured each provider with their api keys:",[111,413,415],{"className":260,"code":414,"language":262,"meta":116,"style":116},"provider \"cloudflare\" {\n  api_token = var.cloudflare_api_token\n}\n\nprovider \"netlify\" {\n  token             = var.netlify_api_token\n  default_team_slug = var.netlify_team_slug\n}\n\nprovider \"uptimerobot\" {\n  api_key = var.uptimerobot_api_key\n}\n",[106,416,417,427,443,447,451,460,475,489,493,497,506,520],{"__ignoreMap":116},[120,418,419,422,425],{"class":122,"line":123},[120,420,421],{"class":133},"provider",[120,423,424],{"class":239}," \"cloudflare\"",[120,426,273],{"class":272},[120,428,429,432,434,437,440],{"class":122,"line":130},[120,430,431],{"class":272},"  api_token",[120,433,138],{"class":246},[120,435,436],{"class":272}," var",[120,438,439],{"class":246},".",[120,441,442],{"class":272},"cloudflare_api_token\n",[120,444,445],{"class":122,"line":144},[120,446,408],{"class":272},[120,448,449],{"class":122,"line":151},[120,450,148],{"emptyLinePlaceholder":147},[120,452,453,455,458],{"class":122,"line":162},[120,454,421],{"class":133},[120,456,457],{"class":239}," \"netlify\"",[120,459,273],{"class":272},[120,461,462,465,468,470,472],{"class":122,"line":173},[120,463,464],{"class":272},"  token",[120,466,467],{"class":246},"             =",[120,469,436],{"class":272},[120,471,439],{"class":246},[120,473,474],{"class":272},"netlify_api_token\n",[120,476,477,480,482,484,486],{"class":122,"line":178},[120,478,479],{"class":272},"  default_team_slug",[120,481,138],{"class":246},[120,483,436],{"class":272},[120,485,439],{"class":246},[120,487,488],{"class":272},"netlify_team_slug\n",[120,490,491],{"class":122,"line":189},[120,492,408],{"class":272},[120,494,495],{"class":122,"line":200},[120,496,148],{"emptyLinePlaceholder":147},[120,498,499,501,504],{"class":122,"line":205},[120,500,421],{"class":133},[120,502,503],{"class":239}," \"uptimerobot\"",[120,505,273],{"class":272},[120,507,508,511,513,515,517],{"class":122,"line":217},[120,509,510],{"class":272},"  api_key",[120,512,138],{"class":246},[120,514,436],{"class":272},[120,516,439],{"class":246},[120,518,519],{"class":272},"uptimerobot_api_key\n",[120,521,522],{"class":122,"line":359},[120,523,408],{"class":272},[66,525,34],{"id":526},"domain-registration",[10,528,529,530,109],{},"Next I needed to set up the cloudflare zone for my domain. Again, this requires some cloudflare information in our ",[106,531,532],{},"terraform.tfvars",[111,534,536],{"className":113,"code":535,"language":115,"meta":116,"style":116},"cloudflare_account_id = \"xyz_123\"\ncloudflare_api_token = \"cloudflare_api_token_here\"\n",[106,537,538,546],{"__ignoreMap":116},[120,539,540,542,544],{"class":122,"line":123},[120,541,181],{"class":133},[120,543,138],{"class":137},[120,545,186],{"class":137},[120,547,548,550,552],{"class":122,"line":130},[120,549,192],{"class":133},[120,551,138],{"class":137},[120,553,197],{"class":137},[10,555,556,557,109],{},"Once we have the cloudflare account authenticated, we can define the cloudflare \"zone\" for this domain by creating a new ",[106,558,559],{},"cloudflare.tf",[111,561,563],{"className":260,"code":562,"language":262,"meta":116,"style":116},"resource \"cloudflare_zone\" \"main\" {\n  account = {\n    id = var.cloudflare_account_id\n  }\n  name = var.domain\n  type = \"full\"\n\n  lifecycle {\n    prevent_destroy = true\n  }\n}\n",[106,564,565,578,587,597,601,615,625,629,636,646,650],{"__ignoreMap":116},[120,566,567,570,573,576],{"class":122,"line":123},[120,568,569],{"class":133},"resource",[120,571,572],{"class":239}," \"cloudflare_zone\"",[120,574,575],{"class":239}," \"main\"",[120,577,273],{"class":272},[120,579,580,583,585],{"class":122,"line":130},[120,581,582],{"class":272},"  account",[120,584,138],{"class":246},[120,586,273],{"class":272},[120,588,589,592,594],{"class":122,"line":144},[120,590,591],{"class":272},"    id ",[120,593,311],{"class":246},[120,595,596],{"class":272}," var.cloudflare_account_id\n",[120,598,599],{"class":122,"line":151},[120,600,402],{"class":272},[120,602,603,606,608,610,612],{"class":122,"line":162},[120,604,605],{"class":272},"  name",[120,607,138],{"class":246},[120,609,436],{"class":272},[120,611,439],{"class":246},[120,613,614],{"class":272},"domain\n",[120,616,617,620,622],{"class":122,"line":173},[120,618,619],{"class":272},"  type",[120,621,138],{"class":246},[120,623,624],{"class":137}," \"full\"\n",[120,626,627],{"class":122,"line":178},[120,628,148],{"emptyLinePlaceholder":147},[120,630,631,634],{"class":122,"line":189},[120,632,633],{"class":133},"  lifecycle",[120,635,273],{"class":272},[120,637,638,641,643],{"class":122,"line":200},[120,639,640],{"class":272},"    prevent_destroy",[120,642,138],{"class":246},[120,644,645],{"class":239}," true\n",[120,647,648],{"class":122,"line":205},[120,649,402],{"class":272},[120,651,652],{"class":122,"line":217},[120,653,408],{"class":272},[10,655,656,657,660],{},"I purposely set ",[106,658,659],{},"lifecycle.prevent_destroy = true"," to prevent terraform from ever destroying (or creating a plan to destroy) this zone. Doing so would be a bit catastrophic for my site, obviously. For my purposes, I consider domain names write-once. 🙂",[662,663,664],"blockquote",{},[10,665,666,667,670,671,676],{},"I actually transferred my domain from Namecheap to Cloudflare during this process for ",[14,668,669],{},"reasons that I'll blog about later",". When I completed the migration, I discovered that Cloudflare's terraform provider no longer supports domain creation! Not that it matters for existing sites, but it's worth knowing that for new projects you'll be required to use the UI to purchase the domain and do the initial setup. See ",[25,672,675],{"href":673,"rel":674},"https:\u002F\u002Fgithub.com\u002Fcloudflare\u002Fterraform-provider-cloudflare\u002Fissues\u002F7470",[76],"this feature request"," for more info.",[66,678,40],{"id":679},"dns-records",[10,681,682,683,685],{},"Next, I needed to record the existing DNS records I have for ",[106,684,77],{},", and point it at the Netlify load balancer.",[10,687,688,689,692,693,109],{},"For each of these, I simply needed to add a ",[106,690,691],{},"cloudflare_dns_record"," resource, name it, and add the block to my ",[106,694,559],{},[111,696,698],{"className":260,"code":697,"language":262,"meta":116,"style":116},"resource \"cloudflare_dns_record\" \"apex\" {\n  zone_id = cloudflare_zone.main.id\n  name    = var.domain\n  content = \"apex-loadbalancer.netlify.com\"\n  type    = \"CNAME\"\n  ttl     = 1     # 1 = \"auto\"; Cloudflare manages it\n  proxied = true  # orange cloud: TLS terminates at Cloudflare's edge\n}\n",[106,699,700,712,732,744,754,763,777,790],{"__ignoreMap":116},[120,701,702,704,707,710],{"class":122,"line":123},[120,703,569],{"class":133},[120,705,706],{"class":239}," \"cloudflare_dns_record\"",[120,708,709],{"class":239}," \"apex\"",[120,711,273],{"class":272},[120,713,714,717,719,722,724,727,729],{"class":122,"line":130},[120,715,716],{"class":272},"  zone_id",[120,718,138],{"class":246},[120,720,721],{"class":272}," cloudflare_zone",[120,723,439],{"class":246},[120,725,726],{"class":272},"main",[120,728,439],{"class":246},[120,730,731],{"class":272},"id\n",[120,733,734,736,738,740,742],{"class":122,"line":144},[120,735,605],{"class":272},[120,737,211],{"class":246},[120,739,436],{"class":272},[120,741,439],{"class":246},[120,743,614],{"class":272},[120,745,746,749,751],{"class":122,"line":151},[120,747,748],{"class":272},"  content",[120,750,138],{"class":246},[120,752,753],{"class":137}," \"apex-loadbalancer.netlify.com\"\n",[120,755,756,758,760],{"class":122,"line":162},[120,757,619],{"class":272},[120,759,211],{"class":246},[120,761,762],{"class":137}," \"CNAME\"\n",[120,764,765,768,771,774],{"class":122,"line":173},[120,766,767],{"class":272},"  ttl",[120,769,770],{"class":246},"     =",[120,772,773],{"class":239}," 1",[120,775,776],{"class":126},"     # 1 = \"auto\"; Cloudflare manages it\n",[120,778,779,782,784,787],{"class":122,"line":178},[120,780,781],{"class":272},"  proxied",[120,783,138],{"class":246},[120,785,786],{"class":239}," true",[120,788,789],{"class":126},"  # orange cloud: TLS terminates at Cloudflare's edge\n",[120,791,792],{"class":122,"line":189},[120,793,408],{"class":272},[662,795,796],{},[10,797,798,799,439],{},"I used GPT Luna heavily for this portion by copy\u002Fpasting DNS records from my cloudflare DNS dashboard. This saved me a ton of time over manually editing these dns record configs, but please note that ",[25,800,803,804],{"href":801,"rel":802},"https:\u002F\u002Fdeveloper.hashicorp.com\u002Fterraform\u002Flanguage\u002Fimport\u002Fgenerating-configuration",[76],"terraform allows generating resource config via ",[106,805,806],{},"terraform plan -generate-config-out=\"generated_resources.tf\"",[10,808,809,810,813,814,816],{},"For the ",[106,811,812],{},"www"," version, I'll just CNAME that to the root ",[106,815,77],{},":",[111,818,820],{"className":260,"code":819,"language":262,"meta":116,"style":116},"resource \"cloudflare_dns_record\" \"www\" {\n  zone_id = cloudflare_zone.main.id\n  name    = local.www_hostname\n  content = var.domain\n  type    = \"CNAME\"\n  ttl     = 1\n  proxied = true\n}\n",[106,821,822,833,849,863,875,883,892,900],{"__ignoreMap":116},[120,823,824,826,828,831],{"class":122,"line":123},[120,825,569],{"class":133},[120,827,706],{"class":239},[120,829,830],{"class":239}," \"www\"",[120,832,273],{"class":272},[120,834,835,837,839,841,843,845,847],{"class":122,"line":130},[120,836,716],{"class":272},[120,838,138],{"class":246},[120,840,721],{"class":272},[120,842,439],{"class":246},[120,844,726],{"class":272},[120,846,439],{"class":246},[120,848,731],{"class":272},[120,850,851,853,855,858,860],{"class":122,"line":144},[120,852,605],{"class":272},[120,854,211],{"class":246},[120,856,857],{"class":272}," local",[120,859,439],{"class":246},[120,861,862],{"class":272},"www_hostname\n",[120,864,865,867,869,871,873],{"class":122,"line":151},[120,866,748],{"class":272},[120,868,138],{"class":246},[120,870,436],{"class":272},[120,872,439],{"class":246},[120,874,614],{"class":272},[120,876,877,879,881],{"class":122,"line":162},[120,878,619],{"class":272},[120,880,211],{"class":246},[120,882,762],{"class":137},[120,884,885,887,889],{"class":122,"line":173},[120,886,767],{"class":272},[120,888,770],{"class":246},[120,890,891],{"class":239}," 1\n",[120,893,894,896,898],{"class":122,"line":178},[120,895,781],{"class":272},[120,897,138],{"class":246},[120,899,645],{"class":239},[120,901,902],{"class":122,"line":189},[120,903,408],{"class":272},[10,905,906,907,910],{},"The ",[106,908,909],{},"ttl=1"," tells Cloudflare to use automatic dns expiry. I know it looks like 1 second, but it's not. 😀",[66,912,46],{"id":913},"netlify-hosting",[10,915,916,917,816],{},"Netlify's terraform support is admittedly pretty weak. You cannot create Netlify projects using terraform, so if you're following this guide you'll have to manually create the netlify site\u002Fproject in the netlify dashboard, then grab the site name and copy it into ",[106,918,532],{},[111,920,922],{"className":113,"code":921,"language":115,"meta":116,"style":116},"netlify_site_name = \"michaelbornme-nuxt\"\nnetlify_team_slug = \"michaelborn\"\n",[106,923,924,933],{"__ignoreMap":116},[120,925,926,928,930],{"class":122,"line":123},[120,927,154],{"class":133},[120,929,138],{"class":137},[120,931,932],{"class":137}," \"michaelbornme-nuxt\"\n",[120,934,935,937,939],{"class":122,"line":130},[120,936,165],{"class":133},[120,938,138],{"class":137},[120,940,941],{"class":137}," \"michaelborn\"\n",[10,943,944],{},"Once I had an existing project and those vars configured in our variable file, I was able to declare the netlify site:",[111,946,948],{"className":260,"code":947,"language":262,"meta":116,"style":116},"data \"netlify_site\" \"main\" {\n  name = var.netlify_site_name\n}\n",[106,949,950,962,975],{"__ignoreMap":116},[120,951,952,955,958,960],{"class":122,"line":123},[120,953,954],{"class":133},"data",[120,956,957],{"class":239}," \"netlify_site\"",[120,959,575],{"class":239},[120,961,273],{"class":272},[120,963,964,966,968,970,972],{"class":122,"line":130},[120,965,605],{"class":272},[120,967,138],{"class":246},[120,969,436],{"class":272},[120,971,439],{"class":246},[120,973,974],{"class":272},"netlify_site_name\n",[120,976,977],{"class":122,"line":144},[120,978,408],{"class":272},[10,980,981],{},"Just to repeat: this does basically nothing besides document the setup. Netlify does not allow writes to the site from terraform!",[10,983,984],{},"Here's where we can actually declare and define some modifiable config - the domain settings for this site:",[111,986,988],{"className":260,"code":987,"language":262,"meta":116,"style":116},"resource \"netlify_site_domain_settings\" \"main\" {\n  site_id        = data.netlify_site.main.id\n  custom_domain  = \"www.${var.domain}\"\n  domain_aliases = []\n}\n",[106,989,990,1001,1025,1051,1061],{"__ignoreMap":116},[120,991,992,994,997,999],{"class":122,"line":123},[120,993,569],{"class":133},[120,995,996],{"class":239}," \"netlify_site_domain_settings\"",[120,998,575],{"class":239},[120,1000,273],{"class":272},[120,1002,1003,1006,1009,1012,1014,1017,1019,1021,1023],{"class":122,"line":130},[120,1004,1005],{"class":272},"  site_id",[120,1007,1008],{"class":246},"        =",[120,1010,1011],{"class":272}," data",[120,1013,439],{"class":246},[120,1015,1016],{"class":272},"netlify_site",[120,1018,439],{"class":246},[120,1020,726],{"class":272},[120,1022,439],{"class":246},[120,1024,731],{"class":272},[120,1026,1027,1030,1032,1035,1038,1041,1043,1045,1048],{"class":122,"line":144},[120,1028,1029],{"class":272},"  custom_domain",[120,1031,223],{"class":246},[120,1033,1034],{"class":137}," \"www.",[120,1036,1037],{"class":246},"${",[120,1039,1040],{"class":272},"var",[120,1042,439],{"class":246},[120,1044,134],{"class":272},[120,1046,1047],{"class":246},"}",[120,1049,1050],{"class":137},"\"\n",[120,1052,1053,1056,1058],{"class":122,"line":151},[120,1054,1055],{"class":272},"  domain_aliases",[120,1057,138],{"class":246},[120,1059,1060],{"class":272}," []\n",[120,1062,1063],{"class":122,"line":162},[120,1064,408],{"class":272},[10,1066,1067,1068,1071],{},"This tells Netlify to use ",[106,1069,1070],{},"www.michaelborn.me"," as the primary domain.",[10,1073,1074,1075,1077,1078,1080,1081,1084],{},"I could have used this section for a redirect from ",[106,1076,77],{}," -> ",[106,1079,1070],{},", buuuut I already handle that via my ",[106,1082,1083],{},"netlify.toml"," config file:",[111,1086,1090],{"className":1087,"code":1088,"language":1089,"meta":116,"style":116},"language-toml shiki shiki-themes github-light github-dark","[[redirects]]\nfrom = \"https:\u002F\u002Fmichaelborn.me\u002F*\"\nto = \"https:\u002F\u002Fwww.michaelborn.me\u002F:splat\"\nstatus = 301\n","toml",[106,1091,1092,1103,1111,1119],{"__ignoreMap":116},[120,1093,1094,1097,1100],{"class":122,"line":123},[120,1095,1096],{"class":272},"[[",[120,1098,1099],{"class":133},"redirects",[120,1101,1102],{"class":272},"]]\n",[120,1104,1105,1108],{"class":122,"line":130},[120,1106,1107],{"class":272},"from = ",[120,1109,1110],{"class":137},"\"https:\u002F\u002Fmichaelborn.me\u002F*\"\n",[120,1112,1113,1116],{"class":122,"line":144},[120,1114,1115],{"class":272},"to = ",[120,1117,1118],{"class":137},"\"https:\u002F\u002Fwww.michaelborn.me\u002F:splat\"\n",[120,1120,1121,1124],{"class":122,"line":151},[120,1122,1123],{"class":272},"status = ",[120,1125,1126],{"class":239},"301\n",[66,1128,52],{"id":1129},"uptime-robot",[10,1131,1132,1133,1138],{},"The last service I set up with terraform was an uptime monitor courtesy of ",[25,1134,1137],{"href":1135,"rel":1136},"https:\u002F\u002Fuptimerobot.com\u002Fpricing\u002F",[76],"Uptime Robot's generous free plan",". (For my personal site, a 5 minute monitor is fine. For client projects, you'll probably want a 60s check.)",[10,1140,1141,1142,1145,1146,1148],{},"This one's pretty straightforward. We define an ",[106,1143,1144],{},"uptimerobot_monitor"," resource for ",[106,1147,77],{},", give it the url to hit and an interval to use, then set a 30 second timeout.",[111,1150,1152],{"className":260,"code":1151,"language":262,"meta":116,"style":116},"resource \"uptimerobot_monitor\" \"www\" {\n  name     = var.domain\n  type     = \"HTTP\"\n  url      = \"https:\u002F\u002Fwww.${var.domain}\"\n  interval = 300\n  timeout  = 30\n\n  check_ssl_errors    = true\n  follow_redirections = true\n}\n",[106,1153,1154,1165,1177,1186,1209,1219,1229,1233,1242,1251],{"__ignoreMap":116},[120,1155,1156,1158,1161,1163],{"class":122,"line":123},[120,1157,569],{"class":133},[120,1159,1160],{"class":239}," \"uptimerobot_monitor\"",[120,1162,830],{"class":239},[120,1164,273],{"class":272},[120,1166,1167,1169,1171,1173,1175],{"class":122,"line":130},[120,1168,605],{"class":272},[120,1170,770],{"class":246},[120,1172,436],{"class":272},[120,1174,439],{"class":246},[120,1176,614],{"class":272},[120,1178,1179,1181,1183],{"class":122,"line":144},[120,1180,619],{"class":272},[120,1182,770],{"class":246},[120,1184,1185],{"class":137}," \"HTTP\"\n",[120,1187,1188,1191,1194,1197,1199,1201,1203,1205,1207],{"class":122,"line":151},[120,1189,1190],{"class":272},"  url",[120,1192,1193],{"class":246},"      =",[120,1195,1196],{"class":137}," \"https:\u002F\u002Fwww.",[120,1198,1037],{"class":246},[120,1200,1040],{"class":272},[120,1202,439],{"class":246},[120,1204,134],{"class":272},[120,1206,1047],{"class":246},[120,1208,1050],{"class":137},[120,1210,1211,1214,1216],{"class":122,"line":162},[120,1212,1213],{"class":272},"  interval",[120,1215,138],{"class":246},[120,1217,1218],{"class":239}," 300\n",[120,1220,1221,1224,1226],{"class":122,"line":173},[120,1222,1223],{"class":272},"  timeout",[120,1225,223],{"class":246},[120,1227,1228],{"class":239}," 30\n",[120,1230,1231],{"class":122,"line":178},[120,1232,148],{"emptyLinePlaceholder":147},[120,1234,1235,1238,1240],{"class":122,"line":189},[120,1236,1237],{"class":272},"  check_ssl_errors",[120,1239,211],{"class":246},[120,1241,645],{"class":239},[120,1243,1244,1247,1249],{"class":122,"line":200},[120,1245,1246],{"class":272},"  follow_redirections",[120,1248,138],{"class":246},[120,1250,645],{"class":239},[120,1252,1253],{"class":122,"line":205},[120,1254,408],{"class":272},[66,1256,58],{"id":1257},"validate-on-push",[10,1259,1260,1261,1264],{},"Before calling this \"done\", I wanted to know my terraform config was valid on each new build. I achieved that via a simple github actions workflow which runs on push any time a file under ",[106,1262,1263],{},"infra\u002F"," is changed:",[111,1266,1270],{"className":1267,"code":1268,"language":1269,"meta":116,"style":116},"language-yaml shiki shiki-themes github-light github-dark","on:\n  push:\n    branches: [main]\n    paths:\n      - \"infra\u002F**\"\n  pull_request:\n    branches: [main]\n    paths:\n      - \"infra\u002F**\"\n","yaml",[106,1271,1272,1280,1288,1301,1308,1316,1323,1333,1339],{"__ignoreMap":116},[120,1273,1274,1277],{"class":122,"line":123},[120,1275,1276],{"class":239},"on",[120,1278,1279],{"class":272},":\n",[120,1281,1282,1286],{"class":122,"line":130},[120,1283,1285],{"class":1284},"s9eBZ","  push",[120,1287,1279],{"class":272},[120,1289,1290,1293,1296,1298],{"class":122,"line":144},[120,1291,1292],{"class":1284},"    branches",[120,1294,1295],{"class":272},": [",[120,1297,726],{"class":137},[120,1299,1300],{"class":272},"]\n",[120,1302,1303,1306],{"class":122,"line":151},[120,1304,1305],{"class":1284},"    paths",[120,1307,1279],{"class":272},[120,1309,1310,1313],{"class":122,"line":162},[120,1311,1312],{"class":272},"      - ",[120,1314,1315],{"class":137},"\"infra\u002F**\"\n",[120,1317,1318,1321],{"class":122,"line":173},[120,1319,1320],{"class":1284},"  pull_request",[120,1322,1279],{"class":272},[120,1324,1325,1327,1329,1331],{"class":122,"line":178},[120,1326,1292],{"class":1284},[120,1328,1295],{"class":272},[120,1330,726],{"class":137},[120,1332,1300],{"class":272},[120,1334,1335,1337],{"class":122,"line":189},[120,1336,1305],{"class":1284},[120,1338,1279],{"class":272},[120,1340,1341,1343],{"class":122,"line":200},[120,1342,1312],{"class":272},[120,1344,1315],{"class":137},[10,1346,1347,1348,1351,1352,1355],{},"If one of those changes is detected, a simple ",[106,1349,1350],{},"validate"," job clones the repo and runs ",[106,1353,1354],{},"terraform validate"," on the infra directory:",[111,1357,1359],{"className":1267,"code":1358,"language":1269,"meta":116,"style":116},"- name: terraform validate\n  uses: dflook\u002Fterraform-validate@v2\n  with:\n    path: infra\n",[106,1360,1361,1375,1385,1392],{"__ignoreMap":116},[120,1362,1363,1366,1369,1372],{"class":122,"line":123},[120,1364,1365],{"class":272},"- ",[120,1367,1368],{"class":1284},"name",[120,1370,1371],{"class":272},": ",[120,1373,1374],{"class":137},"terraform validate\n",[120,1376,1377,1380,1382],{"class":122,"line":130},[120,1378,1379],{"class":1284},"  uses",[120,1381,1371],{"class":272},[120,1383,1384],{"class":137},"dflook\u002Fterraform-validate@v2\n",[120,1386,1387,1390],{"class":122,"line":144},[120,1388,1389],{"class":1284},"  with",[120,1391,1279],{"class":272},[120,1393,1394,1397,1399],{"class":122,"line":151},[120,1395,1396],{"class":1284},"    path",[120,1398,1371],{"class":272},[120,1400,1401],{"class":137},"infra\n",[10,1403,1404],{},"The entire workflow looks like this:",[111,1406,1408],{"className":1267,"code":1407,"language":1269,"meta":116,"style":116},"name: Terraform Validate\n\non:\n  push:\n    branches: [main]\n    paths:\n      - \"infra\u002F**\"\n  pull_request:\n    branches: [main]\n    paths:\n      - \"infra\u002F**\"\n\njobs:\n  validate:\n    name: Validate Terraform config\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions\u002Fcheckout@v7\n\n      - name: terraform validate\n        uses: dflook\u002Fterraform-validate@v2\n        with:\n          path: infra\n",[106,1409,1410,1419,1423,1429,1435,1445,1451,1457,1463,1473,1479,1485,1489,1496,1503,1513,1523,1530,1541,1552,1557,1568,1577,1585],{"__ignoreMap":116},[120,1411,1412,1414,1416],{"class":122,"line":123},[120,1413,1368],{"class":1284},[120,1415,1371],{"class":272},[120,1417,1418],{"class":137},"Terraform Validate\n",[120,1420,1421],{"class":122,"line":130},[120,1422,148],{"emptyLinePlaceholder":147},[120,1424,1425,1427],{"class":122,"line":144},[120,1426,1276],{"class":239},[120,1428,1279],{"class":272},[120,1430,1431,1433],{"class":122,"line":151},[120,1432,1285],{"class":1284},[120,1434,1279],{"class":272},[120,1436,1437,1439,1441,1443],{"class":122,"line":162},[120,1438,1292],{"class":1284},[120,1440,1295],{"class":272},[120,1442,726],{"class":137},[120,1444,1300],{"class":272},[120,1446,1447,1449],{"class":122,"line":173},[120,1448,1305],{"class":1284},[120,1450,1279],{"class":272},[120,1452,1453,1455],{"class":122,"line":178},[120,1454,1312],{"class":272},[120,1456,1315],{"class":137},[120,1458,1459,1461],{"class":122,"line":189},[120,1460,1320],{"class":1284},[120,1462,1279],{"class":272},[120,1464,1465,1467,1469,1471],{"class":122,"line":200},[120,1466,1292],{"class":1284},[120,1468,1295],{"class":272},[120,1470,726],{"class":137},[120,1472,1300],{"class":272},[120,1474,1475,1477],{"class":122,"line":205},[120,1476,1305],{"class":1284},[120,1478,1279],{"class":272},[120,1480,1481,1483],{"class":122,"line":217},[120,1482,1312],{"class":272},[120,1484,1315],{"class":137},[120,1486,1487],{"class":122,"line":359},[120,1488,148],{"emptyLinePlaceholder":147},[120,1490,1491,1494],{"class":122,"line":364},[120,1492,1493],{"class":1284},"jobs",[120,1495,1279],{"class":272},[120,1497,1498,1501],{"class":122,"line":374},[120,1499,1500],{"class":1284},"  validate",[120,1502,1279],{"class":272},[120,1504,1505,1508,1510],{"class":122,"line":384},[120,1506,1507],{"class":1284},"    name",[120,1509,1371],{"class":272},[120,1511,1512],{"class":137},"Validate Terraform config\n",[120,1514,1515,1518,1520],{"class":122,"line":394},[120,1516,1517],{"class":1284},"    runs-on",[120,1519,1371],{"class":272},[120,1521,1522],{"class":137},"ubuntu-latest\n",[120,1524,1525,1528],{"class":122,"line":399},[120,1526,1527],{"class":1284},"    steps",[120,1529,1279],{"class":272},[120,1531,1532,1534,1536,1538],{"class":122,"line":405},[120,1533,1312],{"class":272},[120,1535,1368],{"class":1284},[120,1537,1371],{"class":272},[120,1539,1540],{"class":137},"Checkout\n",[120,1542,1544,1547,1549],{"class":122,"line":1543},19,[120,1545,1546],{"class":1284},"        uses",[120,1548,1371],{"class":272},[120,1550,1551],{"class":137},"actions\u002Fcheckout@v7\n",[120,1553,1555],{"class":122,"line":1554},20,[120,1556,148],{"emptyLinePlaceholder":147},[120,1558,1560,1562,1564,1566],{"class":122,"line":1559},21,[120,1561,1312],{"class":272},[120,1563,1368],{"class":1284},[120,1565,1371],{"class":272},[120,1567,1374],{"class":137},[120,1569,1571,1573,1575],{"class":122,"line":1570},22,[120,1572,1546],{"class":1284},[120,1574,1371],{"class":272},[120,1576,1384],{"class":137},[120,1578,1580,1583],{"class":122,"line":1579},23,[120,1581,1582],{"class":1284},"        with",[120,1584,1279],{"class":272},[120,1586,1588,1591,1593],{"class":122,"line":1587},24,[120,1589,1590],{"class":1284},"          path",[120,1592,1371],{"class":272},[120,1594,1401],{"class":137},[10,1596,1597,1598,1601,1602,1604],{},"I quickly tested this by adding a space in ",[106,1599,1600],{},"terraform {...}"," immediately breaking my ",[106,1603,256],{}," file. Here's what that failure looks like:",[10,1606,1607],{},[1608,1609],"img",{"alt":1610,"src":1611},"example of broken terraform config causing a build failure. Image shows 'Error: Unsupported block type... Blocks of type \"terraf\" are not expected here.'","\u002Fimages\u002Fblog\u002Fterraform-validation-failure-github-actions.png",[66,1613,64],{"id":1614},"conclusion",[10,1616,1617],{},"This is a simple terraform setup for a simple personal site. Terraform becomes a lot more useful when working with AWS, Azure, or other cloud hosting providers that \"treat servers like cattle\". My one gripe is that much of this setup (cloudflare and netlify) still requires manual UI work. Well, what are you going to do? I'm still happy with the result!",[10,1619,1620],{},"Note that I used GPT Luna heavily to create the initial terraform config, so I can't take all the credit for this. I've adjusted it to my liking, and have simplified my setup a bit for this post.",[1622,1623,1624],"style",{},"html pre.shiki code .sJ8bj, html code.shiki .sJ8bj{--shiki-default:#6A737D;--shiki-dark:#6A737D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}",{"title":116,"searchDepth":130,"depth":130,"links":1626},[1627,1628,1629,1630,1631,1632,1633],{"id":68,"depth":130,"text":28},{"id":526,"depth":130,"text":34},{"id":679,"depth":130,"text":40},{"id":913,"depth":130,"text":46},{"id":1129,"depth":130,"text":52},{"id":1257,"depth":130,"text":58},{"id":1614,"depth":130,"text":64},"2026-12-03T09:15:00-05:00","I just reworked my personal site to automate nearly all of its setup in terraform (with some help from GPT Luna), and thought I'd blog a bit about how it works.",false,"md",{},"\u002Fposts\u002Fterraform-infra-personal",{"title":5,"description":1635},"posts\u002Fterraform-infra-personal",[269,1643,1644,1645,1646,1647],"cloudflare","namecheap","uptime","dns","infrastructure","Xd67xOpzLAL0MGcBayVYRSA-IMBWWPIQh1KS-I4YxZY",1796398509072]