{"id":385,"date":"2021-02-14T13:56:53","date_gmt":"2021-02-14T18:56:53","guid":{"rendered":"https:\/\/chasberndt.com\/?p=385"},"modified":"2021-02-14T13:58:06","modified_gmt":"2021-02-14T18:58:06","slug":"using-terraform-to-manage-digitalocean-resources","status":"publish","type":"post","link":"https:\/\/chasberndt.com\/?p=385","title":{"rendered":"Using Terraform to Manage DigitalOcean Resources"},"content":{"rendered":"\n<p>I am a fan of DigitalOcean. What they lack in breath of services they more than make up for with the ease of use, documentation, and tutorials. Last year, I overhauled this website to be driven by Ansible. This year, I want to take this automation to the next level. There are capability gaps using Ansible to create infrastructure that I&#8217;ve had to work around by doing some tasks manually or by writing custom scripts.<\/p>\n\n\n\n<p>An example of this comes when trying to create a managed database cluster. Ansible cannot do this so I wrote a Python script to handle database management.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/seaburr\/WordPressOnDigitalOcean\/tree\/master\/roles\/database-server\">https:\/\/github.com\/seaburr\/WordPressOnDigitalOcean\/tree\/master\/roles\/database-server<\/a><\/p>\n\n\n\n<p>I do not feel DigitalOcean should fill the gaps either. Why? Because Ansible is a <strong>configuration management<\/strong> tool that ensures resources are configured in a <strong>desired state<\/strong>. Infrastructure creation is not Ansible&#8217;s job. There are specific tools for <strong>infrastructure creation<\/strong>&#8230; Enter Terraform.<\/p>\n\n\n\n<p>Terraform is a tool for defining providers (like DigitalOcean or AWS) and the resources (like droplets, load balancers, etc.) that your environment requires. Terraforms intent is to compare your infrastructure to your <strong>desired state<\/strong> and make corrections to bring your resources into compliance. It is a different concern from HOW the infrastructure is configured.<\/p>\n\n\n\n<p>Over the next few months, I&#8217;m going to migrate infrastructure concerns out of Ansible and into Terraform. In fact, I&#8217;ve already got a POC to share.<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/seaburr\/Terraform-On-DO\">https:\/\/github.com\/seaburr\/Terraform-On-DO<\/a><\/p>\n\n\n\n<p>This repository defines the new standard for infrastructure that I am aiming for. <\/p>\n\n\n\n<p>Here&#8217;s a simple mockup of the goal:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><a href=\"https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/terraform_desired_state.png\"><img loading=\"lazy\" decoding=\"async\" width=\"325\" height=\"585\" src=\"https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/terraform_desired_state.png\" alt=\"\" class=\"wp-image-387\" srcset=\"https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/terraform_desired_state.png 325w, https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/terraform_desired_state-167x300.png 167w\" sizes=\"auto, (max-width: 325px) 100vw, 325px\" \/><\/a><\/figure>\n\n\n\n<p>I did try to use the built-in graph functionality of Terraform to show this but it came out looking like this:<\/p>\n\n\n\n<figure class=\"wp-block-jetpack-image-compare\"><div class=\"juxtapose\" data-mode=\"horizontal\"><img loading=\"lazy\" decoding=\"async\" id=\"388\" src=\"https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/download.png\" alt=\"\" width=\"4928\" height=\"1460\" class=\"image-compare__image-before\"\/><img loading=\"lazy\" decoding=\"async\" id=\"389\" src=\"https:\/\/chasberndt.com\/wp-content\/uploads\/2021\/02\/tumblr_o16n2kBlpX1ta3qyvo1_1280.jpg\" alt=\"\" width=\"1024\" height=\"768\" class=\"image-compare__image-after\"\/><\/div><figcaption>I&#8217;ve got boxes full of Pepe!<\/figcaption><\/figure>\n\n\n\n<p>Anyways, it&#8217;s a work in progress. I&#8217;ve run into what I believe is a bug with the DigitalOcean Terraform provider and I&#8217;ve already raised a ticket with them to get resolved.<\/p>\n\n\n\n<p>Next time, let&#8217;s actually learn something and dig into a resource and the provider configuration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am a fan of DigitalOcean. What they lack in breath of services they more than make up for with the ease of use, documentation, and tutorials. Last year, I overhauled this website to be driven by Ansible. This year, I want to take this automation to the next level. There are capability gaps using <a class=\"read-more\" href=\"https:\/\/chasberndt.com\/?p=385\">&hellip;&nbsp;<span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[13,23,12,24,22],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-automation","category-devops","category-process-improvement","category-sre","category-terraform"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385"}],"version-history":[{"count":2,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":390,"href":"https:\/\/chasberndt.com\/index.php?rest_route=\/wp\/v2\/posts\/385\/revisions\/390"}],"wp:attachment":[{"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chasberndt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}