{"id":685,"date":"2023-01-08T03:23:00","date_gmt":"2023-01-07T20:23:00","guid":{"rendered":"https:\/\/rotreein.com\/?p=685"},"modified":"2025-01-04T07:57:22","modified_gmt":"2025-01-04T00:57:22","slug":"atlantis-for-terraform","status":"publish","type":"post","link":"https:\/\/rotreein.com\/?p=685","title":{"rendered":"Integrate Terraform CI\/CD with Atlantis"},"content":{"rendered":"\n<p><br>Atlantis is a powerful automation tool designed to streamline collaboration and code review workflows for Terraform infrastructure as code (IaC). It acts as a bridge between version control systems (VCS) like Git and Terraform, facilitating a smooth and efficient process for managing infrastructure changes<\/p>\n\n\n\n<p>On this case, we deployed the Atlantis on Ubuntu VM<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Install Terraform<\/strong><\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"tomorrow\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">wget https:\/\/releases.hashicorp.com\/terraform\/1.4.4\/terraform_1.4.4_linux_amd64.zip\nunzip terraform_1.4.4_linux_amd64.zip \nsudo mv terraform \/usr\/local\/bin\/\nterraform<\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><br><strong>Install Atlantis<\/strong><\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"tomorrow\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">sudo apt install git -y\nwget https:\/\/github.com\/runatlantis\/atlantis\/releases\/download\/v0.23.3\/atlantis_linux_amd64.zip\nunzip atlantis_linux_amd64.zip \nsudo cp atlantis \/usr\/local\/bin\/<\/pre>\n\n\n\n<p><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Create Personal Token<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"832\" height=\"922\" src=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-132718.png\" alt=\"\" class=\"wp-image-686\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-132718.png 832w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-132718-271x300.png 271w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-132718-768x851.png 768w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/figure>\n\n\n\n<p><br><br><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"435\" src=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-1024x435.png\" alt=\"\" class=\"wp-image-687\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-1024x435.png 1024w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-300x127.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-768x326.png 768w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image.png 1317w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><br><br><strong>Create Service Account<\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"975\" height=\"474\" src=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-133723.png\" alt=\"\" class=\"wp-image-688\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-133723.png 975w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-133723-300x146.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-20230402-133723-768x373.png 768w\" sizes=\"(max-width: 975px) 100vw, 975px\" \/><\/figure>\n\n\n\n<p><br><br>Run the gcloud config command inside the Atlantis VM to set credential with service account<\/p>\n\n\n\n<pre data-mode=\"text\" data-theme=\"tomorrow\" data-fontsize=\"15\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">cloud_sandboxgcp_gmail_com@vm-atlantis-staging-1:~$  gcloud config set account 501066779977-compute@developer.gserviceaccount.com\n\nUpdated property [core\/account].<\/pre>\n\n\n\n<p><br>Create Altantis directory to store the Atlantis configurations<\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"tomorrow\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">mkdir -p \/opt\/terraform\/atlantis-workdi<\/pre>\n\n\n\n<p><br>Create repos.yaml on \/opt\/terraform\/atlantis-workdir<\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">repos:\n# Allow a specific repo to override.\n- id: github.com\/rohmattriindra\/tf-infra-gcp\n  allowed_overrides: [apply_requirements, workflow]\n  allow_custom_workflows: true\n  apply_requirements: [approved]\n  <\/pre>\n\n\n\n<p><br><\/p>\n\n\n\n<p class=\"has-medium-font-size\">Run the Atlantis server<\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"tomorrow\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">atlantis server --atlantis-url=http:\/\/34.126.185.33 --gh-user=rohmattriindra --gh-token=ghp_VcOefm8MUwuoz3JU356yQtVDummy --gh-webhook-secret=\"0uNbW5pOBQfQvDummyDummyF\" --repo-whitelist=github.com\/rohmattriindra\/tf-infra-gcp --data-dir=\/opt\/terraform\/atlantis-workdir --repo-config=\/opt\/terraform\/atlantis-workdir\/repos.yaml<\/pre>\n\n\n\n<p><br><\/p>\n\n\n\n<p>Create Atlantis.yml on the root directory, you can find sample on this repo <a href=\"https:\/\/github.com\/rohmattriindra\/tf-infra-gcp\/blob\/master\/atlantis.yaml\">https:\/\/github.com\/rohmattriindra\/tf-infra-gcp\/blob\/master\/atlantis.yaml<\/a><\/p>\n\n\n\n<pre data-mode=\"php\" data-theme=\"monokai\" data-fontsize=\"14\" data-lines=\"Infinity\" class=\"wp-block-simple-code-block-ace\">version: 3\nautomerge: true\nprojects:\n  # staging-networks\n  - name: staging-network\n    dir: infrastructure\/environments\/staging\/network\n    autoplan:\n      enabled: true\n      when_modified: [\"..\/..\/..\/stack\/network\/*.tf*\", \"terraform.tfvars\"]\n    workspace: staging\n    workflow: terraform\n    apply_requirements: [mergeable]. # without this command when we pu\n\nworkflows:\n  terraform:\n    plan:\n      steps:\n      - env: \n              name: PROJECT_DIR\n              command: echo $PROJECT_NAME | cut -d- -f2\n\n      - run: |\n              rm -rf .terraform\n              terraform -chdir=\"..\/..\/..\/stacks\/$PROJECT_DIR\/\" init -backend-config=prefix=\"$WORKSPACE\/$PROJECT_DIR\" --reconfigure\n              terraform -chdir=\"..\/..\/..\/stacks\/$PROJECT_DIR\/\" plan -var-file=\"..\/..\/environments\/$WORKSPACE\/$PROJECT_DIR\/terraform.tfvars\"\n    apply:\n      steps:\n      - env: \n              name: PROJECT_DIR\n              command: echo $PROJECT_NAME | cut -d- -f2\n\n      - run: |\n              terraform -chdir=\"..\/..\/..\/stacks\/$PROJECT_DIR\/\" init -backend-config=prefix=\"$WORKSPACE\/$PROJECT_DIR\" --reconfigure\n              terraform -chdir=\"..\/..\/..\/stacks\/$PROJECT_DIR\/\" apply --auto-approve -var-file=\"..\/..\/environments\/$WORKSPACE\/$PROJECT_DIR\/terraform.tfvars\"\n<\/pre>\n\n\n\n<p><br>This is a sample result of the change in firewall resources<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"655\" src=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-6-1024x655.png\" alt=\"\" class=\"wp-image-718\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-6-1024x655.png 1024w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-6-300x192.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-6-768x491.png 768w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-6.png 1257w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"855\" src=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-7.png\" alt=\"\" class=\"wp-image-720\" srcset=\"https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-7.png 907w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-7-300x283.png 300w, https:\/\/rotreein.com\/wp-content\/uploads\/2024\/05\/image-7-768x724.png 768w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Atlantis is a powerful automation tool designed to streamline collaboration and code review workflows for Terraform infrastructure as code (IaC). It acts as a bridge between version control systems (VCS) like Git and Terraform, facilitating a smooth and efficient process for managing infrastructure changes On this case, we deployed the Atlantis on Ubuntu VM Install&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"_links":{"self":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/685"}],"collection":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=685"}],"version-history":[{"count":37,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/685\/revisions"}],"predecessor-version":[{"id":798,"href":"https:\/\/rotreein.com\/index.php?rest_route=\/wp\/v2\/posts\/685\/revisions\/798"}],"wp:attachment":[{"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rotreein.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}