[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"\u002Fp\u002Fdeploy-aws-terraform-github-actions":3},{"id":4,"title":5,"aws":6,"body":7,"categories":514,"createdAt":516,"description":517,"difficulty":518,"extension":519,"image":520,"links":522,"meta":537,"navigation":6,"path":538,"seo":539,"sitemap":540,"stem":542,"tags":543,"toc":549,"type":550,"updatedAt":541,"__hash__":551},"p\u002Fp\u002Fdeploy-aws-terraform-github-actions.md","Deploy Your Terraform IaC with GitHub Actions",true,{"type":8,"value":9},"minimark",[10,14,19,27,387,396,400,409,413,429,454,467,476,480,483,487,490,510],[11,12,13],"p",{},"Deploying Terraform infrastructure can be streamlined with GitHub Actions, saving you time and reducing manual errors. Below, I propose a basic workflow that you can customize to fit your specific needs. This workflow assumes you already have a Terraform project set up and want to automate its deployment to your AWS account.",[15,16,18],"h3",{"id":17},"the-workflow-file","The Workflow File",[11,20,21,22,26],{},"Create a new file in your repository at ",[23,24,25],"code",{},".github\u002Fworkflows\u002Fdeploy.yml"," and paste this YAML workflow.",[28,29,35],"pre",{"className":30,"code":31,"filename":32,"language":33,"meta":34,"style":34},"language-yml shiki shiki-themes min-light min-light plastic","name: Terraform Deploy\n\non:\n  push:\n    branches: [ main ]\n\nenv:\n  AWS_REGION: us-east-1\n\njobs:\n  deploy:\n    runs-on: ubuntu-latest\n    permissions:\n      id-token: write\n      contents: read\n    \n    steps:\n      - name: Checkout code\n        uses: actions\u002Fcheckout@v7\n\n      - name: Set up Terraform\n        uses: hashicorp\u002Fsetup-terraform@v4\n\n      - name: Configure AWS Credentials\n        uses: aws-actions\u002Fconfigure-aws-credentials@v6\n        with:\n          role-to-assume: arn:aws:iam::\u003CACCOUNT_ID>:role\u002FGithubActionsRole\n          aws-region: ${{ env.AWS_REGION }}\n\n      - name: Terraform Init\n        run: terraform init\n\n      - name: Terraform Plan\n        run: terraform plan\n\n      - name: Terraform Apply\n        run: terraform apply -auto-approve\n","deploy.yml","yml","",[23,36,37,54,60,70,78,97,102,110,121,126,134,142,153,161,172,183,189,197,210,221,226,238,248,253,265,275,283,294,305,310,322,333,338,350,360,365,377],{"__ignoreMap":34},[38,39,42,46,50],"span",{"class":40,"line":41},"line",1,[38,43,45],{"class":44},"s6W6U","name",[38,47,49],{"class":48},"siOgq",":",[38,51,53],{"class":52},"sw9Es"," Terraform Deploy\n",[38,55,57],{"class":40,"line":56},2,[38,58,59],{"emptyLinePlaceholder":6},"\n",[38,61,63,67],{"class":40,"line":62},3,[38,64,66],{"class":65},"sAhIg","on",[38,68,69],{"class":48},":\n",[38,71,73,76],{"class":40,"line":72},4,[38,74,75],{"class":44},"  push",[38,77,69],{"class":48},[38,79,81,84,86,90,94],{"class":40,"line":80},5,[38,82,83],{"class":44},"    branches",[38,85,49],{"class":48},[38,87,89],{"class":88},"slmz-"," [ ",[38,91,93],{"class":92},"s9CPO","main",[38,95,96],{"class":88}," ]\n",[38,98,100],{"class":40,"line":99},6,[38,101,59],{"emptyLinePlaceholder":6},[38,103,105,108],{"class":40,"line":104},7,[38,106,107],{"class":44},"env",[38,109,69],{"class":48},[38,111,113,116,118],{"class":40,"line":112},8,[38,114,115],{"class":44},"  AWS_REGION",[38,117,49],{"class":48},[38,119,120],{"class":52}," us-east-1\n",[38,122,124],{"class":40,"line":123},9,[38,125,59],{"emptyLinePlaceholder":6},[38,127,129,132],{"class":40,"line":128},10,[38,130,131],{"class":44},"jobs",[38,133,69],{"class":48},[38,135,137,140],{"class":40,"line":136},11,[38,138,139],{"class":44},"  deploy",[38,141,69],{"class":48},[38,143,145,148,150],{"class":40,"line":144},12,[38,146,147],{"class":44},"    runs-on",[38,149,49],{"class":48},[38,151,152],{"class":52}," ubuntu-latest\n",[38,154,156,159],{"class":40,"line":155},13,[38,157,158],{"class":44},"    permissions",[38,160,69],{"class":48},[38,162,164,167,169],{"class":40,"line":163},14,[38,165,166],{"class":44},"      id-token",[38,168,49],{"class":48},[38,170,171],{"class":52}," write\n",[38,173,175,178,180],{"class":40,"line":174},15,[38,176,177],{"class":44},"      contents",[38,179,49],{"class":48},[38,181,182],{"class":52}," read\n",[38,184,186],{"class":40,"line":185},16,[38,187,188],{"class":88},"    \n",[38,190,192,195],{"class":40,"line":191},17,[38,193,194],{"class":44},"    steps",[38,196,69],{"class":48},[38,198,200,203,205,207],{"class":40,"line":199},18,[38,201,202],{"class":88},"      - ",[38,204,45],{"class":44},[38,206,49],{"class":48},[38,208,209],{"class":52}," Checkout code\n",[38,211,213,216,218],{"class":40,"line":212},19,[38,214,215],{"class":44},"        uses",[38,217,49],{"class":48},[38,219,220],{"class":52}," actions\u002Fcheckout@v7\n",[38,222,224],{"class":40,"line":223},20,[38,225,59],{"emptyLinePlaceholder":6},[38,227,229,231,233,235],{"class":40,"line":228},21,[38,230,202],{"class":88},[38,232,45],{"class":44},[38,234,49],{"class":48},[38,236,237],{"class":52}," Set up Terraform\n",[38,239,241,243,245],{"class":40,"line":240},22,[38,242,215],{"class":44},[38,244,49],{"class":48},[38,246,247],{"class":52}," hashicorp\u002Fsetup-terraform@v4\n",[38,249,251],{"class":40,"line":250},23,[38,252,59],{"emptyLinePlaceholder":6},[38,254,256,258,260,262],{"class":40,"line":255},24,[38,257,202],{"class":88},[38,259,45],{"class":44},[38,261,49],{"class":48},[38,263,264],{"class":52}," Configure AWS Credentials\n",[38,266,268,270,272],{"class":40,"line":267},25,[38,269,215],{"class":44},[38,271,49],{"class":48},[38,273,274],{"class":52}," aws-actions\u002Fconfigure-aws-credentials@v6\n",[38,276,278,281],{"class":40,"line":277},26,[38,279,280],{"class":44},"        with",[38,282,69],{"class":48},[38,284,286,289,291],{"class":40,"line":285},27,[38,287,288],{"class":44},"          role-to-assume",[38,290,49],{"class":48},[38,292,293],{"class":52}," arn:aws:iam::\u003CACCOUNT_ID>:role\u002FGithubActionsRole\n",[38,295,297,300,302],{"class":40,"line":296},28,[38,298,299],{"class":44},"          aws-region",[38,301,49],{"class":48},[38,303,304],{"class":52}," ${{ env.AWS_REGION }}\n",[38,306,308],{"class":40,"line":307},29,[38,309,59],{"emptyLinePlaceholder":6},[38,311,313,315,317,319],{"class":40,"line":312},30,[38,314,202],{"class":88},[38,316,45],{"class":44},[38,318,49],{"class":48},[38,320,321],{"class":52}," Terraform Init\n",[38,323,325,328,330],{"class":40,"line":324},31,[38,326,327],{"class":44},"        run",[38,329,49],{"class":48},[38,331,332],{"class":52}," terraform init\n",[38,334,336],{"class":40,"line":335},32,[38,337,59],{"emptyLinePlaceholder":6},[38,339,341,343,345,347],{"class":40,"line":340},33,[38,342,202],{"class":88},[38,344,45],{"class":44},[38,346,49],{"class":48},[38,348,349],{"class":52}," Terraform Plan\n",[38,351,353,355,357],{"class":40,"line":352},34,[38,354,327],{"class":44},[38,356,49],{"class":48},[38,358,359],{"class":52}," terraform plan\n",[38,361,363],{"class":40,"line":362},35,[38,364,59],{"emptyLinePlaceholder":6},[38,366,368,370,372,374],{"class":40,"line":367},36,[38,369,202],{"class":88},[38,371,45],{"class":44},[38,373,49],{"class":48},[38,375,376],{"class":52}," Terraform Apply\n",[38,378,380,382,384],{"class":40,"line":379},37,[38,381,327],{"class":44},[38,383,49],{"class":48},[38,385,386],{"class":52}," terraform apply -auto-approve\n",[388,389,390],"warning",{},[11,391,392,395],{},[23,393,394],{},"\u003CACCOUNT_ID>"," has to be replaced by your AWS account ID.",[15,397,399],{"id":398},"oidc-authentication","OIDC Authentication",[11,401,402,403,408],{},"This workflow uses OpenID Connect (OIDC) to securely authenticate with AWS, eliminating the need for long-lived credentials. If you’re new to OIDC or need help setting it up, I’ve written a ",[404,405,407],"a",{"href":406},"\u002Fp\u002Fgithub-aws-oidc-secure-connection","dedicated post"," explaining how to configure the OIDC connection between GitHub and your AWS account.",[15,410,412],{"id":411},"the-iam-role-permissions","The IAM Role Permissions",[11,414,415,416,420,421,424,425,428],{},"OIDC controls ",[417,418,419],"em",{},"who"," can assume the ",[23,422,423],{},"GithubActionsRole",", but the role still needs an IAM policy describing ",[417,426,427],{},"what"," it can do once assumed. For Terraform, that policy boils down to two things:",[430,431,432,440],"ul",{},[433,434,435,439],"li",{},[436,437,438],"strong",{},"Resource permissions:"," access to every AWS service your Terraform code manages (S3, VPC, RDS, and so on) so it can create, update, and delete those resources.",[433,441,442,445,446,449,450,453],{},[436,443,444],{},"Backend permissions:"," if you store state remotely, read\u002Fwrite access to the S3 bucket holding the state file. With S3 native locking (",[23,447,448],{},"use_lockfile = true","), the lock is a ",[23,451,452],{},".tflock"," file in that same bucket, so no DynamoDB table or permissions are needed anymore.",[455,456,457],"note",{},[11,458,459,460,463,464,466],{},"DynamoDB-based state locking is deprecated since Terraform 1.11. If your backend still uses ",[23,461,462],{},"dynamodb_table",", switch to ",[23,465,448],{}," and drop the table.",[388,468,469],{},[11,470,471,472,475],{},"Grant only what your stack actually touches, following the principle of least privilege. Attaching ",[23,473,474],{},"AdministratorAccess"," is tempting to get moving, but a scoped policy keeps a leaked token from reaching the rest of your account.",[15,477,479],{"id":478},"testing","Testing",[11,481,482],{},"The provided workflow does not include any testing steps. For a robust CI\u002FCD pipeline, consider adding unit and integration tests before the deployment job. This ensures your infrastructure changes are validated before being applied.",[15,484,486],{"id":485},"production-best-practices","Production Best Practices",[11,488,489],{},"For production environments, it’s recommended to:",[430,491,492,498,504],{},[433,493,494,497],{},[436,495,496],{},"Pin all versions:"," Freeze the versions of Terraform and GitHub Actions to avoid unexpected updates.",[433,499,500,503],{},[436,501,502],{},"Use approvals:"," For critical stacks, require manual approval before deployment.",[433,505,506,509],{},[436,507,508],{},"Environment separation:"," Deploy to different AWS accounts for staging and production.",[511,512,513],"style",{},"html pre.shiki code .s6W6U, html code.shiki .s6W6U{--shiki-light:#D32F2F;--shiki-default:#D32F2F;--shiki-dark:#E5C07B}html pre.shiki code .siOgq, html code.shiki .siOgq{--shiki-light:#D32F2F;--shiki-default:#D32F2F;--shiki-dark:#A9B2C3}html pre.shiki code .sw9Es, html code.shiki .sw9Es{--shiki-light:#22863A;--shiki-default:#22863A;--shiki-dark:#98C379}html pre.shiki code .sAhIg, html code.shiki .sAhIg{--shiki-light:#1976D2;--shiki-default:#1976D2;--shiki-dark:#56B6C2}html pre.shiki code .slmz-, html code.shiki .slmz-{--shiki-light:#24292EFF;--shiki-default:#24292EFF;--shiki-dark:#A9B2C3}html pre.shiki code .s9CPO, html code.shiki .s9CPO{--shiki-light:#2B5581;--shiki-default:#2B5581;--shiki-dark:#98C379}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}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);}",[515],"DevOps","2025-12-02","Automate Terraform deployments with GitHub Actions. A ready-to-use YAML workflow plus best practices for secure, efficient CI\u002FCD pipelines.","L200","md",{"src":521},"\u002Fcovers\u002Fdeploy-aws-terraform-github-actions.jpg",{"aws":523,"tools":528},[524],{"label":525,"icon":526,"to":527},"IAM","aws:iam","\u002Faws?services=iam",[529,533],{"label":530,"icon":531,"to":532},"Github Actions","logos:github-actions","\u002Fr\u002Fgithub-actions",{"label":534,"icon":535,"to":536},"Terraform","logos:terraform-icon","\u002Fr\u002Fterraform",{},"\u002Fp\u002Fdeploy-aws-terraform-github-actions",{"title":5,"description":517},{"loc":538,"lastmod":541},"2026-10-07","p\u002Fdeploy-aws-terraform-github-actions",[544,545,546,547,548],"Automation","CI\u002FCD","Deployment","IaC","OIDC",false,"Guide","os6Ui7IRsD7CpqsRtiQB_Q9O5rUmLE6eNQkxZJIszEU"]