├── .github ├── FUNDING.yml ├── renovate.json └── workflows │ └── pipeline.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── examples ├── multiple-containers │ ├── main.tf │ └── mock_provider.tf └── test │ ├── custom_iam_policy.tf │ ├── main.tf │ └── mock_provider.tf ├── files └── iam │ └── ecs_task_execution_iam_role.json ├── main.tf ├── outputs.tf ├── variables.tf └── versions.tf /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: jnonino 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "labels": ["enhancement"] 6 | } 7 | -------------------------------------------------------------------------------- /.github/workflows/pipeline.yml: -------------------------------------------------------------------------------- 1 | name: Terraform 2 | on: 3 | push: 4 | branches: [main] 5 | pull_request: 6 | types: [opened, reopened, synchronize] 7 | branches: [main] 8 | release: 9 | types: [published] 10 | 11 | env: 12 | DEFAULT_REGION: us-east-1 13 | AWS_ACCESS_KEY_ID: localstack 14 | AWS_SECRET_ACCESS_KEY: localstack 15 | 16 | jobs: 17 | check-format: 18 | runs-on: ubuntu-latest 19 | container: hashicorp/terraform 20 | steps: 21 | - name: Checkout repository 22 | uses: actions/checkout@v4 23 | - name: Terraform Format Check 24 | run: terraform fmt -check -recursive -diff 25 | 26 | validations: 27 | runs-on: ubuntu-latest 28 | container: hashicorp/terraform 29 | strategy: 30 | matrix: { 31 | dir: ['examples/test', 'examples/multiple-containers'] 32 | } 33 | services: 34 | localstack: 35 | image: localstack/localstack 36 | env: 37 | SERVICES: apigateway,cloudformation,cloudwatch,dynamodb,es,firehose,iam,kinesis,lambda,route53,redshift,s3,secretsmanager,ses,sns,sqs,ssm,stepfunctions,sts 38 | ports: 39 | - 4566:4566 40 | steps: 41 | - name: Checkout repository 42 | uses: actions/checkout@v4 43 | - name: Terraform Init 44 | run: terraform init -upgrade 45 | working-directory: ${{ matrix.dir }} 46 | - name: Terraform Validate 47 | run: terraform validate 48 | working-directory: ${{ matrix.dir }} 49 | - name: Terraform Plan (Mock) 50 | run: terraform plan 51 | working-directory: ${{ matrix.dir }} 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .terraform.lock.hcl 2 | 3 | # Created by https://www.toptal.com/developers/gitignore/api/linux,macos,windows,terraform,sublimetext,visualstudiocode 4 | # Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,windows,terraform,sublimetext,visualstudiocode 5 | 6 | ### Linux ### 7 | *~ 8 | 9 | # temporary files which can be created if a process still has a handle open of a deleted file 10 | .fuse_hidden* 11 | 12 | # KDE directory preferences 13 | .directory 14 | 15 | # Linux trash folder which might appear on any partition or disk 16 | .Trash-* 17 | 18 | # .nfs files are created when an open file is removed but is still being accessed 19 | .nfs* 20 | 21 | ### macOS ### 22 | # General 23 | .DS_Store 24 | .AppleDouble 25 | .LSOverride 26 | 27 | # Icon must end with two \r 28 | Icon 29 | 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | .com.apple.timemachine.donotpresent 42 | 43 | # Directories potentially created on remote AFP share 44 | .AppleDB 45 | .AppleDesktop 46 | Network Trash Folder 47 | Temporary Items 48 | .apdisk 49 | 50 | ### macOS Patch ### 51 | # iCloud generated files 52 | *.icloud 53 | 54 | ### SublimeText ### 55 | # Cache files for Sublime Text 56 | *.tmlanguage.cache 57 | *.tmPreferences.cache 58 | *.stTheme.cache 59 | 60 | # Workspace files are user-specific 61 | *.sublime-workspace 62 | 63 | # Project files should be checked into the repository, unless a significant 64 | # proportion of contributors will probably not be using Sublime Text 65 | # *.sublime-project 66 | 67 | # SFTP configuration file 68 | sftp-config.json 69 | sftp-config-alt*.json 70 | 71 | # Package control specific files 72 | Package Control.last-run 73 | Package Control.ca-list 74 | Package Control.ca-bundle 75 | Package Control.system-ca-bundle 76 | Package Control.cache/ 77 | Package Control.ca-certs/ 78 | Package Control.merged-ca-bundle 79 | Package Control.user-ca-bundle 80 | oscrypto-ca-bundle.crt 81 | bh_unicode_properties.cache 82 | 83 | # Sublime-github package stores a github token in this file 84 | # https://packagecontrol.io/packages/sublime-github 85 | GitHub.sublime-settings 86 | 87 | ### Terraform ### 88 | # Local .terraform directories 89 | **/.terraform/* 90 | 91 | # .tfstate files 92 | *.tfstate 93 | *.tfstate.* 94 | 95 | # Crash log files 96 | crash.log 97 | crash.*.log 98 | 99 | # Exclude all .tfvars files, which are likely to contain sensitive data, such as 100 | # password, private keys, and other secrets. These should not be part of version 101 | # control as they are data points which are potentially sensitive and subject 102 | # to change depending on the environment. 103 | *.tfvars 104 | *.tfvars.json 105 | 106 | # Ignore override files as they are usually used to override resources locally and so 107 | # are not checked in 108 | override.tf 109 | override.tf.json 110 | *_override.tf 111 | *_override.tf.json 112 | 113 | # Include override files you do wish to add to version control using negated pattern 114 | # !example_override.tf 115 | 116 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 117 | # example: *tfplan* 118 | 119 | # Ignore CLI configuration files 120 | .terraformrc 121 | terraform.rc 122 | 123 | ### VisualStudioCode ### 124 | .vscode/* 125 | !.vscode/settings.json 126 | !.vscode/tasks.json 127 | !.vscode/launch.json 128 | !.vscode/extensions.json 129 | !.vscode/*.code-snippets 130 | 131 | # Local History for Visual Studio Code 132 | .history/ 133 | 134 | # Built Visual Studio Code Extensions 135 | *.vsix 136 | 137 | ### VisualStudioCode Patch ### 138 | # Ignore all local history of files 139 | .history 140 | .ionide 141 | 142 | ### Windows ### 143 | # Windows thumbnail cache files 144 | Thumbs.db 145 | Thumbs.db:encryptable 146 | ehthumbs.db 147 | ehthumbs_vista.db 148 | 149 | # Dump file 150 | *.stackdump 151 | 152 | # Folder config file 153 | [Dd]esktop.ini 154 | 155 | # Recycle Bin used on file shares 156 | $RECYCLE.BIN/ 157 | 158 | # Windows Installer files 159 | *.cab 160 | *.msi 161 | *.msix 162 | *.msm 163 | *.msp 164 | 165 | # Windows shortcuts 166 | *.lnk 167 | 168 | # End of https://www.toptal.com/developers/gitignore/api/linux,macos,windows,terraform,sublimetext,visualstudiocode 169 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | fail_fast: true 2 | 3 | repos: 4 | - repo: https://github.com/antonbabenko/pre-commit-terraform 5 | rev: v1.77.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases 6 | hooks: 7 | - id: terraform_fmt 8 | - id: terraform_docs 9 | args: ["--args=--lockfile=false"] 10 | - id: terraform_validate 11 | - repo: https://github.com/pre-commit/pre-commit-hooks 12 | rev: v4.4.0 # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases 13 | hooks: 14 | - id: check-merge-conflict 15 | - id: end-of-file-fixer 16 | - id: trailing-whitespace 17 | - id: check-added-large-files 18 | - id: check-case-conflict 19 | - id: detect-private-key 20 | - id: check-yaml 21 | files: ^(.github/workflows).*$ 22 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Citizen Code of Conduct 2 | 3 | ## 1. Purpose 4 | 5 | A primary goal of Terraform AWS ECS Fargate Task Definition is to be inclusive to the largest number of contributors, with the most varied and diverse backgrounds possible. As such, we are committed to providing a friendly, safe and welcoming environment for all, regardless of gender, sexual orientation, ability, ethnicity, socioeconomic status, and religion (or lack thereof). 6 | 7 | This code of conduct outlines our expectations for all those who participate in our community, as well as the consequences for unacceptable behavior. 8 | 9 | We invite all those who participate in Terraform AWS ECS Fargate Task Definition to help us create safe and positive experiences for everyone. 10 | 11 | ## 2. Open [Source/Culture/Tech] Citizenship 12 | 13 | A supplemental goal of this Code of Conduct is to increase open [source/culture/tech] citizenship by encouraging participants to recognize and strengthen the relationships between our actions and their effects on our community. 14 | 15 | Communities mirror the societies in which they exist and positive action is essential to counteract the many forms of inequality and abuses of power that exist in society. 16 | 17 | If you see someone who is making an extra effort to ensure our community is welcoming, friendly, and encourages all participants to contribute to the fullest extent, we want to know. 18 | 19 | ## 3. Expected Behavior 20 | 21 | The following behaviors are expected and requested of all community members: 22 | 23 | * Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community. 24 | * Exercise consideration and respect in your speech and actions. 25 | * Attempt collaboration before conflict. 26 | * Refrain from demeaning, discriminatory, or harassing behavior and speech. 27 | * Be mindful of your surroundings and of your fellow participants. Alert community leaders if you notice a dangerous situation, someone in distress, or violations of this Code of Conduct, even if they seem inconsequential. 28 | * Remember that community event venues may be shared with members of the public; please be respectful to all patrons of these locations. 29 | 30 | ## 4. Unacceptable Behavior 31 | 32 | The following behaviors are considered harassment and are unacceptable within our community: 33 | 34 | * Violence, threats of violence or violent language directed against another person. 35 | * Sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory jokes and language. 36 | * Posting or displaying sexually explicit or violent material. 37 | * Posting or threatening to post other people's personally identifying information ("doxing"). 38 | * Personal insults, particularly those related to gender, sexual orientation, race, religion, or disability. 39 | * Inappropriate photography or recording. 40 | * Inappropriate physical contact. You should have someone's consent before touching them. 41 | * Unwelcome sexual attention. This includes, sexualized comments or jokes; inappropriate touching, groping, and unwelcomed sexual advances. 42 | * Deliberate intimidation, stalking or following (online or in person). 43 | * Advocating for, or encouraging, any of the above behavior. 44 | * Sustained disruption of community events, including talks and presentations. 45 | 46 | ## 5. Weapons Policy 47 | 48 | No weapons will be allowed at Terraform AWS ECS Fargate Task Definition events, community spaces, or in other spaces covered by the scope of this Code of Conduct. Weapons include but are not limited to guns, explosives (including fireworks), and large knives such as those used for hunting or display, as well as any other item used for the purpose of causing injury or harm to others. Anyone seen in possession of one of these items will be asked to leave immediately, and will only be allowed to return without the weapon. Community members are further expected to comply with all state and local laws on this matter. 49 | 50 | ## 6. Consequences of Unacceptable Behavior 51 | 52 | Unacceptable behavior from any community member, including sponsors and those with decision-making authority, will not be tolerated. 53 | 54 | Anyone asked to stop unacceptable behavior is expected to comply immediately. 55 | 56 | If a community member engages in unacceptable behavior, the community organizers may take any action they deem appropriate, up to and including a temporary ban or permanent expulsion from the community without warning (and without refund in the case of a paid event). 57 | 58 | ## 7. Reporting Guidelines 59 | 60 | If you are subject to or witness unacceptable behavior, or have any other concerns, please notify a community organizer as soon as possible. noninojulian@gmail.com. 61 | 62 | 63 | 64 | Additionally, community organizers are available to help community members engage with local law enforcement or to otherwise help those experiencing unacceptable behavior feel safe. In the context of in-person events, organizers will also provide escorts as desired by the person experiencing distress. 65 | 66 | ## 8. Addressing Grievances 67 | 68 | If you feel you have been falsely or unfairly accused of violating this Code of Conduct, you should notify CN Services with a concise description of your grievance. Your grievance will be handled in accordance with our existing governing policies. 69 | 70 | 71 | 72 | ## 9. Scope 73 | 74 | We expect all community participants (contributors, paid or otherwise; sponsors; and other guests) to abide by this Code of Conduct in all community venues--online and in-person--as well as in all one-on-one communications pertaining to community business. 75 | 76 | This code of conduct and its related procedures also applies to unacceptable behavior occurring outside the scope of community activities when such behavior has the potential to adversely affect the safety and well-being of community members. 77 | 78 | ## 10. Contact info 79 | 80 | noninojulian@gmail.com 81 | 82 | ## 11. License and attribution 83 | 84 | The Citizen Code of Conduct is distributed by [Stumptown Syndicate](http://stumptownsyndicate.org) under a [Creative Commons Attribution-ShareAlike license](http://creativecommons.org/licenses/by-sa/3.0/). 85 | 86 | Portions of text derived from the [Django Code of Conduct](https://www.djangoproject.com/conduct/) and the [Geek Feminism Anti-Harassment Policy](http://geekfeminism.wikia.com/wiki/Conference_anti-harassment/Policy). 87 | 88 | _Revision 2.3. Posted 6 March 2017._ 89 | 90 | _Revision 2.2. Posted 4 February 2016._ 91 | 92 | _Revision 2.1. Posted 23 June 2014._ 93 | 94 | _Revision 2.0, adopted by the [Stumptown Syndicate](http://stumptownsyndicate.org) board on 10 January 2013. Posted 17 March 2013._ 95 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 Julian Nonino, Maria Florencia Caro 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS ECS Fargate Task Definition Terraform Module # 2 | 3 | This Terraform module creates an AWS ECS Fargate task definition. 4 | 5 | [![](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition/workflows/terraform/badge.svg)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition/actions?query=workflow%3Aterraform) 6 | [![](https://img.shields.io/github/license/cn-terraform/terraform-aws-ecs-fargate-task-definition)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition) 7 | [![](https://img.shields.io/github/issues/cn-terraform/terraform-aws-ecs-fargate-task-definition)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition) 8 | [![](https://img.shields.io/github/issues-closed/cn-terraform/terraform-aws-ecs-fargate-task-definition)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition) 9 | [![](https://img.shields.io/github/languages/code-size/cn-terraform/terraform-aws-ecs-fargate-task-definition)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition) 10 | [![](https://img.shields.io/github/repo-size/cn-terraform/terraform-aws-ecs-fargate-task-definition)](https://github.com/cn-terraform/terraform-aws-ecs-fargate-task-definition) 11 | 12 | ## Usage 13 | 14 | Check versions for this module on: 15 | * Github Releases: 16 | * Terraform Module Registry: 17 | 18 | ## Install pre commit hooks. 19 | 20 | Pleas run this command right after cloning the repository. 21 | 22 | pre-commit install 23 | 24 | For that you may need to install the following tools: 25 | * [Pre-commit](https://pre-commit.com/) 26 | * [Terraform Docs](https://terraform-docs.io/) 27 | 28 | In order to run all checks at any point run the following command: 29 | 30 | pre-commit run --all-files 31 | 32 | 33 | ## Requirements 34 | 35 | | Name | Version | 36 | |------|---------| 37 | | [terraform](#requirement\_terraform) | >= 0.13 | 38 | | [aws](#requirement\_aws) | >= 4.0.0 | 39 | 40 | ## Providers 41 | 42 | | Name | Version | 43 | |------|---------| 44 | | [aws](#provider\_aws) | >= 4.0.0 | 45 | 46 | ## Modules 47 | 48 | | Name | Source | Version | 49 | |------|--------|---------| 50 | | [container\_definition](#module\_container\_definition) | cloudposse/ecs-container-definition/aws | 0.60.1 | 51 | 52 | ## Resources 53 | 54 | | Name | Type | 55 | |------|------| 56 | | [aws_ecs_task_definition.td](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecs_task_definition) | resource | 57 | | [aws_iam_policy.ecs_task_execution_role_custom_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | 58 | | [aws_iam_role.ecs_task_execution_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | 59 | | [aws_iam_role_policy_attachment.ecs_task_execution_role_custom_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 60 | | [aws_iam_role_policy_attachment.ecs_task_execution_role_policy_attach](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 61 | 62 | ## Inputs 63 | 64 | | Name | Description | Type | Default | Required | 65 | |------|-------------|------|---------|:--------:| 66 | | [command](#input\_command) | The command that is passed to the container | `list(string)` | `null` | no | 67 | | [container\_cpu](#input\_container\_cpu) | (Optional) The number of cpu units to reserve for the container. This is optional for tasks using Fargate launch type and the total amount of container\_cpu of all containers in a task will need to be lower than the task-level cpu value | `number` | `1024` | no | 68 | | [container\_definition](#input\_container\_definition) | Container definition overrides which allows for extra keys or overriding existing keys. | `map(any)` | `{}` | no | 69 | | [container\_depends\_on](#input\_container\_depends\_on) | The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY |
list(object({
containerName = string
condition = string
}))
| `[]` | no | 70 | | [container\_image](#input\_container\_image) | The image used to start the container. Images in the Docker Hub registry available by default | `string` | `null` | no | 71 | | [container\_memory](#input\_container\_memory) | (Optional) The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container\_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container\_memory of all containers in a task will need to be lower than the task memory value | `number` | `4096` | no | 72 | | [container\_memory\_reservation](#input\_container\_memory\_reservation) | (Optional) The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container\_memory hard limit | `number` | `2048` | no | 73 | | [container\_name](#input\_container\_name) | The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, \_ allowed) | `string` | `null` | no | 74 | | [containers](#input\_containers) | Container definitions to use for the task. If this is used, all other container options will be ignored. | `any` | `[]` | no | 75 | | [disable\_networking](#input\_disable\_networking) | When this parameter is true, networking is disabled within the container. | `bool` | `null` | no | 76 | | [dns\_search\_domains](#input\_dns\_search\_domains) | Container DNS search domains. A list of DNS search domains that are presented to the container | `list(string)` | `[]` | no | 77 | | [dns\_servers](#input\_dns\_servers) | Container DNS servers. This is a list of strings specifying the IP addresses of the DNS servers | `list(string)` | `[]` | no | 78 | | [docker\_labels](#input\_docker\_labels) | The configuration options to send to the `docker_labels` | `map(string)` | `null` | no | 79 | | [docker\_security\_options](#input\_docker\_security\_options) | A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems. | `list(string)` | `[]` | no | 80 | | [ecs\_task\_execution\_role\_custom\_policies](#input\_ecs\_task\_execution\_role\_custom\_policies) | (Optional) Custom policies to attach to the ECS task execution role. For example for reading secrets from AWS Systems Manager Parameter Store or Secrets Manager | `list(string)` | `[]` | no | 81 | | [entrypoint](#input\_entrypoint) | The entry point that is passed to the container | `list(string)` | `null` | no | 82 | | [environment](#input\_environment) | The environment variables to pass to the container. This is a list of maps. map\_environment overrides environment |
list(object({
name = string
value = string
}))
| `[]` | no | 83 | | [environment\_files](#input\_environment\_files) | One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps |
list(object({
value = string
type = string
}))
| `[]` | no | 84 | | [ephemeral\_storage\_size](#input\_ephemeral\_storage\_size) | The number of GBs to provision for ephemeral storage on Fargate tasks. Must be greater than or equal to 21 and less than or equal to 200 | `number` | `0` | no | 85 | | [essential](#input\_essential) | Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value | `bool` | `true` | no | 86 | | [execution\_role\_arn](#input\_execution\_role\_arn) | (Optional) The ARN of IAM role that grants permissions to start the containers defined in a task (e.g populate environment variables from AWS Secrets Manager). If not specified, `aws_iam_role.ecs_task_execution_role.arn` is used | `string` | `null` | no | 87 | | [extra\_hosts](#input\_extra\_hosts) | A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps |
list(object({
ipAddress = string
hostname = string
}))
| `null` | no | 88 | | [firelens\_configuration](#input\_firelens\_configuration) | The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html |
object({
type = string
options = map(string)
})
| `null` | no | 89 | | [healthcheck](#input\_healthcheck) | (Optional) A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries) |
object({
command = list(string)
retries = number
timeout = number
interval = number
startPeriod = number
})
| `null` | no | 90 | | [hostname](#input\_hostname) | The hostname to use for your container. | `string` | `null` | no | 91 | | [iam\_partition](#input\_iam\_partition) | IAM partition to use when referencing standard policies. GovCloud and some other regions use different partitions | `string` | `"aws"` | no | 92 | | [interactive](#input\_interactive) | When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated. | `bool` | `null` | no | 93 | | [ipc\_mode](#input\_ipc\_mode) | (Optional) IPC resource namespace to be used for the containers in the task The valid values are host, task, and none. | `string` | `null` | no | 94 | | [links](#input\_links) | List of container names this container can communicate with without port mappings | `list(string)` | `[]` | no | 95 | | [linux\_parameters](#input\_linux\_parameters) | Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html |
object({
capabilities = object({
add = list(string)
drop = list(string)
})
devices = list(object({
containerPath = string
hostPath = string
permissions = list(string)
}))
initProcessEnabled = bool
maxSwap = number
sharedMemorySize = number
swappiness = number
tmpfs = list(object({
containerPath = string
mountOptions = list(string)
size = number
}))
})
| `null` | no | 96 | | [log\_configuration](#input\_log\_configuration) | Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html | `any` | `null` | no | 97 | | [map\_environment](#input\_map\_environment) | The environment variables to pass to the container. This is a map of string: {key: value}. map\_environment overrides environment | `map(string)` | `null` | no | 98 | | [map\_secrets](#input\_map\_secrets) | The secrets variables to pass to the container. This is a map of string: {key: value}. map\_secrets overrides secrets | `map(string)` | `null` | no | 99 | | [mount\_points](#input\_mount\_points) | Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional. | `list(any)` | `[]` | no | 100 | | [name\_prefix](#input\_name\_prefix) | Name prefix for resources on AWS | `any` | n/a | yes | 101 | | [permissions\_boundary](#input\_permissions\_boundary) | (Optional) The ARN of the policy that is used to set the permissions boundary for the `ecs_task_execution_role` role. | `string` | `null` | no | 102 | | [pid\_mode](#input\_pid\_mode) | (Optional) Process namespace to use for the containers in the task. The valid values are host and task | `string` | `null` | no | 103 | | [placement\_constraints](#input\_placement\_constraints) | (Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement\_constraints is 10. |
list(object({
expression = string # Cluster Query Language expression to apply to the constraint. For more information, see Cluster Query Language in the Amazon EC2 Container Service Developer Guide.
type = string # Type of constraint. Use memberOf to restrict selection to a group of valid candidates. Note that distinctInstance is not supported in task definitions.
}))
| `[]` | no | 104 | | [port\_mappings](#input\_port\_mappings) | The port mappings to configure for the container. This is a list of maps. Each map should contain "containerPort", "hostPort", and "protocol", where "protocol" is one of "tcp" or "udp". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort |
list(object({
name = optional(string)
containerPort = number
hostPort = number
protocol = string
}))
|
[
{
"containerPort": 80,
"hostPort": 80,
"protocol": "tcp"
}
]
| no | 105 | | [privileged](#input\_privileged) | When this variable is `true`, the container is given elevated privileges on the host container instance (similar to the root user). This parameter is not supported for Windows containers or tasks using the Fargate launch type. | `bool` | `null` | no | 106 | | [proxy\_configuration](#input\_proxy\_configuration) | (Optional) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain "container\_name", "properties" and "type" |
list(object({
container_name = string # Name of the container that will serve as the App Mesh proxy.
properties = list(object({ # Set of network configuration parameters to provide the Container Network Interface (CNI) plugin, specified a key-value mapping.
name = string
value = string
}))
type = string # Proxy type. The default value is APPMESH. The only supported value is APPMESH.
}))
| `[]` | no | 107 | | [pseudo\_terminal](#input\_pseudo\_terminal) | When this parameter is true, a TTY is allocated. | `bool` | `null` | no | 108 | | [readonly\_root\_filesystem](#input\_readonly\_root\_filesystem) | Determines whether a container is given read-only access to its root filesystem. Due to how Terraform type casts booleans in json it is required to double quote this value | `bool` | `false` | no | 109 | | [repository\_credentials](#input\_repository\_credentials) | Container repository credentials; required when using a private repo. This map currently supports a single key; "credentialsParameter", which should be the ARN of a Secrets Manager's secret holding the credentials | `map(string)` | `null` | no | 110 | | [resource\_requirements](#input\_resource\_requirements) | The type and amount of a resource to assign to a container. The only supported resource is a GPU. |
list(object({
type = string
value = string
}))
| `null` | no | 111 | | [runtime\_platform\_cpu\_architecture](#input\_runtime\_platform\_cpu\_architecture) | Must be set to either X86\_64 or ARM64 | `string` | `"X86_64"` | no | 112 | | [runtime\_platform\_operating\_system\_family](#input\_runtime\_platform\_operating\_system\_family) | If the requires\_compatibilities is FARGATE this field is required. The valid values for Amazon ECS tasks that are hosted on Fargate are LINUX, WINDOWS\_SERVER\_2019\_FULL, WINDOWS\_SERVER\_2019\_CORE, WINDOWS\_SERVER\_2022\_FULL, and WINDOWS\_SERVER\_2022\_CORE. | `string` | `"LINUX"` | no | 113 | | [secrets](#input\_secrets) | The secrets to pass to the container. This is a list of maps |
list(object({
name = string
valueFrom = string
}))
| `[]` | no | 114 | | [skip\_destroy](#input\_skip\_destroy) | (Optional) Whether to retain the old revision when the resource is destroyed or replacement is necessary. Default is false. | `bool` | `false` | no | 115 | | [start\_timeout](#input\_start\_timeout) | Time duration (in seconds) to wait before giving up on resolving dependencies for a container | `number` | `null` | no | 116 | | [stop\_timeout](#input\_stop\_timeout) | Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own | `number` | `null` | no | 117 | | [system\_controls](#input\_system\_controls) | A list of namespaced kernel parameters to set in the container, mapping to the --sysctl option to docker run. This is a list of maps: { namespace = "", value = ""} | `list(map(string))` | `[]` | no | 118 | | [tags](#input\_tags) | Resource tags | `map(string)` | `{}` | no | 119 | | [task\_role\_arn](#input\_task\_role\_arn) | (Optional) The ARN of IAM role that grants permissions to the actual application once the container is started (e.g access an S3 bucket or DynamoDB database). If not specified, `aws_iam_role.ecs_task_execution_role.arn` is used | `string` | `null` | no | 120 | | [ulimits](#input\_ulimits) | Container ulimit settings. This is a list of maps, where each map should contain "name", "hardLimit" and "softLimit" |
list(object({
name = string
hardLimit = number
softLimit = number
}))
| `null` | no | 121 | | [user](#input\_user) | The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group. The default (null) will use the container's configured `USER` directive or root if not set. | `string` | `null` | no | 122 | | [volumes](#input\_volumes) | (Optional) A set of volume blocks that containers in your task may use |
list(object({
host_path = string
name = string
docker_volume_configuration = list(object({
autoprovision = bool
driver = string
driver_opts = map(string)
labels = map(string)
scope = string
}))
efs_volume_configuration = list(object({
file_system_id = string
root_directory = string
transit_encryption = string
transit_encryption_port = string
authorization_config = list(object({
access_point_id = string
iam = string
}))
}))
}))
| `[]` | no | 123 | | [volumes\_from](#input\_volumes\_from) | A list of VolumesFrom maps which contain "sourceContainer" (name of the container that has the volumes to mount) and "readOnly" (whether the container can write to the volume) |
list(object({
sourceContainer = string
readOnly = bool
}))
| `[]` | no | 124 | | [working\_directory](#input\_working\_directory) | The working directory to run commands inside the container | `string` | `null` | no | 125 | 126 | ## Outputs 127 | 128 | | Name | Description | 129 | |------|-------------| 130 | | [aws\_ecs\_task\_definition\_td\_arn](#output\_aws\_ecs\_task\_definition\_td\_arn) | Full ARN of the Task Definition (including both family and revision). | 131 | | [aws\_ecs\_task\_definition\_td\_family](#output\_aws\_ecs\_task\_definition\_td\_family) | The family of the Task Definition. | 132 | | [aws\_ecs\_task\_definition\_td\_revision](#output\_aws\_ecs\_task\_definition\_td\_revision) | The revision of the task in a particular family. | 133 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_arn](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_arn) | The Amazon Resource Name (ARN) specifying the role. | 134 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_create\_date](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_create\_date) | The creation date of the IAM role. | 135 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_description](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_description) | The description of the role. | 136 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_id](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_id) | The ID of the role. | 137 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_name](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_name) | The name of the role. | 138 | | [aws\_iam\_role\_ecs\_task\_execution\_role\_unique\_id](#output\_aws\_iam\_role\_ecs\_task\_execution\_role\_unique\_id) | The stable and unique string identifying the role. | 139 | | [container\_name](#output\_container\_name) | Name of the container | 140 | 141 | -------------------------------------------------------------------------------- /examples/multiple-containers/main.tf: -------------------------------------------------------------------------------- 1 | module "container-definition-1" { 2 | source = "cloudposse/ecs-container-definition/aws" 3 | version = "0.58.1" 4 | container_name = "container-1" 5 | container_image = "ubuntu-1" 6 | } 7 | 8 | module "container-definition-2" { 9 | source = "cloudposse/ecs-container-definition/aws" 10 | version = "0.58.1" 11 | container_name = "container-2" 12 | container_image = "ubuntu-2" 13 | } 14 | 15 | module "td" { 16 | source = "../../" 17 | name_prefix = "multiple-containers" 18 | 19 | additional_containers = [ 20 | module.container-definition-1.json_map_object, 21 | module.container-definition-2.json_map_object, 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /examples/multiple-containers/mock_provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = ">= 4" 7 | } 8 | } 9 | } 10 | 11 | provider "aws" { 12 | region = "us-east-1" 13 | skip_credentials_validation = true 14 | skip_requesting_account_id = true 15 | skip_metadata_api_check = true 16 | s3_use_path_style = true 17 | 18 | endpoints { 19 | apigateway = "http://localstack:4566" 20 | cloudformation = "http://localstack:4566" 21 | cloudwatch = "http://localstack:4566" 22 | dynamodb = "http://localstack:4566" 23 | es = "http://localstack:4566" 24 | firehose = "http://localstack:4566" 25 | iam = "http://localstack:4566" 26 | kinesis = "http://localstack:4566" 27 | lambda = "http://localstack:4566" 28 | route53 = "http://localstack:4566" 29 | redshift = "http://localstack:4566" 30 | s3 = "http://localstack:4566" 31 | secretsmanager = "http://localstack:4566" 32 | ses = "http://localstack:4566" 33 | sns = "http://localstack:4566" 34 | sqs = "http://localstack:4566" 35 | ssm = "http://localstack:4566" 36 | stepfunctions = "http://localstack:4566" 37 | sts = "http://localstack:4566" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/test/custom_iam_policy.tf: -------------------------------------------------------------------------------- 1 | # ecs_task_execution_role_custom_policies = [ 2 | # jsonencode( 3 | # { 4 | # "Version" : "2012-10-17", 5 | # "Statement" : [ 6 | # { 7 | # "Effect" : "Allow", 8 | # "Action" : [ 9 | # "secretsmanager:GetSecretValue" 10 | # ], 11 | # "Resource" : [ 12 | # "arn:aws:secretsmanager:AWS_REGION:AWS_ACC:secret:SECRET_NAME" 13 | # ] 14 | # } 15 | # ] 16 | # } 17 | # ) 18 | # ] 19 | 20 | #This also works 21 | 22 | # ecs_task_execution_role_custom_policies = [ 23 | # "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"secretsmanager:GetSecretValue\"],\"Resource\":[\"arn:aws:secretsmanager:AWS_REGION:AWS_ACC:secret:SECRET_NAME\"]}]}" 24 | # ] 25 | -------------------------------------------------------------------------------- /examples/test/main.tf: -------------------------------------------------------------------------------- 1 | module "td" { 2 | source = "../../" 3 | name_prefix = "test" 4 | container_image = "ubuntu" 5 | container_name = "test" 6 | } 7 | -------------------------------------------------------------------------------- /examples/test/mock_provider.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = ">= 4" 7 | } 8 | } 9 | } 10 | 11 | provider "aws" { 12 | region = "us-east-1" 13 | skip_credentials_validation = true 14 | skip_requesting_account_id = true 15 | skip_metadata_api_check = true 16 | s3_use_path_style = true 17 | 18 | endpoints { 19 | apigateway = "http://localstack:4566" 20 | cloudformation = "http://localstack:4566" 21 | cloudwatch = "http://localstack:4566" 22 | dynamodb = "http://localstack:4566" 23 | es = "http://localstack:4566" 24 | firehose = "http://localstack:4566" 25 | iam = "http://localstack:4566" 26 | kinesis = "http://localstack:4566" 27 | lambda = "http://localstack:4566" 28 | route53 = "http://localstack:4566" 29 | redshift = "http://localstack:4566" 30 | s3 = "http://localstack:4566" 31 | secretsmanager = "http://localstack:4566" 32 | ses = "http://localstack:4566" 33 | sns = "http://localstack:4566" 34 | sqs = "http://localstack:4566" 35 | ssm = "http://localstack:4566" 36 | stepfunctions = "http://localstack:4566" 37 | sts = "http://localstack:4566" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /files/iam/ecs_task_execution_iam_role.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Principal": { 7 | "Service": "ecs-tasks.amazonaws.com" 8 | }, 9 | "Action": "sts:AssumeRole", 10 | "Sid": "" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # AWS ECS Task Execution Role 3 | #------------------------------------------------------------------------------ 4 | resource "aws_iam_role" "ecs_task_execution_role" { 5 | count = var.execution_role_arn == null ? 1 : 0 6 | name = "${var.name_prefix}-ecs-task-execution-role" 7 | assume_role_policy = file("${path.module}/files/iam/ecs_task_execution_iam_role.json") 8 | permissions_boundary = var.permissions_boundary 9 | tags = var.tags 10 | } 11 | 12 | resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_policy_attach" { 13 | count = var.execution_role_arn == null ? 1 : 0 14 | role = aws_iam_role.ecs_task_execution_role[0].name 15 | policy_arn = "arn:${var.iam_partition}:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy" 16 | } 17 | 18 | resource "aws_iam_policy" "ecs_task_execution_role_custom_policy" { 19 | count = var.execution_role_arn == null ? length(var.ecs_task_execution_role_custom_policies) : 0 20 | name = "${var.name_prefix}-ecs-task-execution-role-custom-policy-${count.index}" 21 | description = "A custom policy for ${var.name_prefix}-ecs-task-execution-role IAM Role" 22 | policy = var.ecs_task_execution_role_custom_policies[count.index] 23 | tags = var.tags 24 | } 25 | 26 | resource "aws_iam_role_policy_attachment" "ecs_task_execution_role_custom_policy" { 27 | count = var.execution_role_arn == null ? length(var.ecs_task_execution_role_custom_policies) : 0 28 | role = aws_iam_role.ecs_task_execution_role[0].name 29 | policy_arn = aws_iam_policy.ecs_task_execution_role_custom_policy[count.index].arn 30 | } 31 | 32 | #------------------------------------------------------------------------------ 33 | # ECS Task Definition 34 | #------------------------------------------------------------------------------ 35 | # Container Definition 36 | module "container_definition" { 37 | source = "cloudposse/ecs-container-definition/aws" 38 | version = "0.61.2" 39 | 40 | command = var.command 41 | container_cpu = var.container_cpu 42 | container_definition = var.container_definition_overrides 43 | container_depends_on = var.container_depends_on 44 | container_image = var.container_image 45 | container_memory = var.container_memory 46 | container_memory_reservation = var.container_memory_reservation 47 | container_name = var.container_name 48 | disable_networking = var.disable_networking 49 | dns_search_domains = var.dns_search_domains 50 | dns_servers = var.dns_servers 51 | docker_labels = var.docker_labels 52 | docker_security_options = var.docker_security_options 53 | entrypoint = var.entrypoint 54 | environment = var.environment 55 | environment_files = var.environment_files 56 | essential = var.essential 57 | extra_hosts = var.extra_hosts 58 | firelens_configuration = var.firelens_configuration 59 | healthcheck = var.healthcheck 60 | hostname = var.hostname 61 | interactive = var.interactive 62 | links = var.links 63 | linux_parameters = var.linux_parameters 64 | log_configuration = var.log_configuration 65 | map_environment = var.map_environment 66 | map_secrets = var.map_secrets 67 | mount_points = var.mount_points 68 | port_mappings = var.port_mappings 69 | privileged = var.privileged 70 | pseudo_terminal = var.pseudo_terminal 71 | readonly_root_filesystem = var.readonly_root_filesystem 72 | repository_credentials = var.repository_credentials 73 | resource_requirements = var.resource_requirements 74 | secrets = var.secrets 75 | start_timeout = var.start_timeout 76 | stop_timeout = var.stop_timeout 77 | system_controls = var.system_controls 78 | ulimits = var.ulimits 79 | user = var.user 80 | volumes_from = var.volumes_from 81 | working_directory = var.working_directory 82 | } 83 | 84 | # Task Definition 85 | resource "aws_ecs_task_definition" "td" { 86 | container_definitions = jsonencode(concat(var.additional_containers, [module.container_definition.json_map_object])) 87 | cpu = var.container_cpu 88 | execution_role_arn = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].arn : var.execution_role_arn 89 | family = "${var.name_prefix}-td" 90 | ipc_mode = var.ipc_mode 91 | memory = var.container_memory 92 | network_mode = "awsvpc" # awsvpc required for Fargate tasks 93 | task_role_arn = var.task_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].arn : var.task_role_arn 94 | 95 | runtime_platform { 96 | cpu_architecture = var.runtime_platform_cpu_architecture 97 | operating_system_family = var.runtime_platform_operating_system_family 98 | } 99 | 100 | pid_mode = var.pid_mode 101 | 102 | dynamic "placement_constraints" { 103 | for_each = var.placement_constraints 104 | content { 105 | expression = lookup(placement_constraints.value, "expression", null) 106 | type = placement_constraints.value.type 107 | } 108 | } 109 | 110 | dynamic "proxy_configuration" { 111 | for_each = var.proxy_configuration 112 | content { 113 | container_name = proxy_configuration.value.container_name 114 | properties = lookup(proxy_configuration.value, "properties", null) 115 | type = lookup(proxy_configuration.value, "type", null) 116 | } 117 | } 118 | 119 | dynamic "ephemeral_storage" { 120 | for_each = var.ephemeral_storage_size == 0 ? [] : [var.ephemeral_storage_size] 121 | content { 122 | size_in_gib = var.ephemeral_storage_size 123 | } 124 | } 125 | 126 | requires_compatibilities = ["FARGATE"] 127 | skip_destroy = var.skip_destroy 128 | 129 | dynamic "volume" { 130 | for_each = var.volumes 131 | content { 132 | name = volume.value.name 133 | 134 | host_path = lookup(volume.value, "host_path", null) 135 | 136 | dynamic "docker_volume_configuration" { 137 | for_each = lookup(volume.value, "docker_volume_configuration", []) 138 | content { 139 | autoprovision = lookup(docker_volume_configuration.value, "autoprovision", null) 140 | driver = lookup(docker_volume_configuration.value, "driver", null) 141 | driver_opts = lookup(docker_volume_configuration.value, "driver_opts", null) 142 | labels = lookup(docker_volume_configuration.value, "labels", null) 143 | scope = lookup(docker_volume_configuration.value, "scope", null) 144 | } 145 | } 146 | 147 | dynamic "efs_volume_configuration" { 148 | for_each = lookup(volume.value, "efs_volume_configuration", []) 149 | content { 150 | file_system_id = lookup(efs_volume_configuration.value, "file_system_id", null) 151 | root_directory = lookup(efs_volume_configuration.value, "root_directory", null) 152 | transit_encryption = lookup(efs_volume_configuration.value, "transit_encryption", null) 153 | transit_encryption_port = lookup(efs_volume_configuration.value, "transit_encryption_port", null) 154 | dynamic "authorization_config" { 155 | for_each = lookup(efs_volume_configuration.value, "authorization_config", []) 156 | content { 157 | access_point_id = lookup(authorization_config.value, "access_point_id", null) 158 | iam = lookup(authorization_config.value, "iam", null) 159 | } 160 | } 161 | } 162 | } 163 | } 164 | } 165 | 166 | tags = var.tags 167 | } 168 | 169 | # TODO - Add this missing parameter 170 | # inference_accelerator - (Optional) Configuration block(s) with Inference Accelerators settings. Detailed below. 171 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # AWS ECS Task Execution Role 3 | #------------------------------------------------------------------------------ 4 | output "aws_iam_role_ecs_task_execution_role_arn" { 5 | description = "The Amazon Resource Name (ARN) specifying the role." 6 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].arn : var.execution_role_arn 7 | } 8 | 9 | output "aws_iam_role_ecs_task_execution_role_create_date" { 10 | description = "The creation date of the IAM role." 11 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].create_date : null 12 | } 13 | 14 | output "aws_iam_role_ecs_task_execution_role_description" { 15 | description = "The description of the role." 16 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].description : null 17 | } 18 | 19 | output "aws_iam_role_ecs_task_execution_role_id" { 20 | description = "The ID of the role." 21 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].id : null 22 | } 23 | 24 | output "aws_iam_role_ecs_task_execution_role_name" { 25 | description = "The name of the role." 26 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].name : null 27 | } 28 | 29 | output "aws_iam_role_ecs_task_execution_role_unique_id" { 30 | description = "The stable and unique string identifying the role." 31 | value = var.execution_role_arn == null ? aws_iam_role.ecs_task_execution_role[0].unique_id : null 32 | } 33 | 34 | #------------------------------------------------------------------------------ 35 | # ECS Task Definition 36 | #------------------------------------------------------------------------------ 37 | output "aws_ecs_task_definition_td_arn" { 38 | description = "Full ARN of the Task Definition (including both family and revision)." 39 | value = aws_ecs_task_definition.td.arn 40 | } 41 | 42 | output "aws_ecs_task_definition_td_family" { 43 | description = "The family of the Task Definition." 44 | value = aws_ecs_task_definition.td.family 45 | } 46 | 47 | output "aws_ecs_task_definition_td_revision" { 48 | description = "The revision of the task in a particular family." 49 | value = aws_ecs_task_definition.td.revision 50 | } 51 | output "container_name" { 52 | description = "Name of the container" 53 | value = var.container_name 54 | } 55 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------ 2 | # Misc 3 | #------------------------------------------------------------------------------ 4 | variable "name_prefix" { 5 | description = "Name prefix for resources on AWS" 6 | } 7 | 8 | variable "tags" { 9 | type = map(string) 10 | default = {} 11 | description = "Resource tags" 12 | } 13 | 14 | #------------------------------------------------------------------------------ 15 | # AWS ECS Container Definition Variables for Cloudposse module 16 | #------------------------------------------------------------------------------ 17 | variable "command" { 18 | type = list(string) 19 | description = "The command that is passed to the container" 20 | default = null 21 | } 22 | 23 | variable "container_cpu" { 24 | # https://docs.aws.amazon.com/AmazonECS/latest/developerguide/AWS_Fargate.html#fargate-task-defs 25 | type = number 26 | description = "(Optional) The number of cpu units to reserve for the container. This is optional for tasks using Fargate launch type and the total amount of container_cpu of all containers in a task will need to be lower than the task-level cpu value" 27 | default = 1024 # 1 vCPU 28 | } 29 | 30 | variable "container_definition_overrides" { 31 | type = map(any) 32 | description = "Container definition overrides which allows for extra keys or overriding existing keys." 33 | default = {} 34 | } 35 | 36 | variable "container_depends_on" { 37 | type = list(object({ 38 | containerName = string 39 | condition = string 40 | })) 41 | description = "The dependencies defined for container startup and shutdown. A container can contain multiple dependencies. When a dependency is defined for container startup, for container shutdown it is reversed. The condition can be one of START, COMPLETE, SUCCESS or HEALTHY" 42 | default = [] 43 | } 44 | 45 | variable "container_image" { 46 | type = string 47 | default = null 48 | description = "The image used to start the container. Images in the Docker Hub registry available by default" 49 | } 50 | 51 | variable "container_memory" { 52 | type = number 53 | description = "(Optional) The amount of memory (in MiB) to allow the container to use. This is a hard limit, if the container attempts to exceed the container_memory, the container is killed. This field is optional for Fargate launch type and the total amount of container_memory of all containers in a task will need to be lower than the task memory value" 54 | default = 4096 # 4 GB 55 | } 56 | 57 | variable "container_memory_reservation" { 58 | type = number 59 | description = "(Optional) The amount of memory (in MiB) to reserve for the container. If container needs to exceed this threshold, it can do so up to the set container_memory hard limit" 60 | default = 2048 # 2 GB 61 | } 62 | 63 | variable "container_name" { 64 | type = string 65 | default = null 66 | description = "The name of the container. Up to 255 characters ([a-z], [A-Z], [0-9], -, _ allowed)" 67 | } 68 | 69 | variable "disable_networking" { 70 | type = bool 71 | description = "When this parameter is true, networking is disabled within the container." 72 | default = null 73 | } 74 | 75 | variable "dns_search_domains" { 76 | type = list(string) 77 | description = "Container DNS search domains. A list of DNS search domains that are presented to the container" 78 | default = [] 79 | } 80 | 81 | variable "dns_servers" { 82 | type = list(string) 83 | description = "Container DNS servers. This is a list of strings specifying the IP addresses of the DNS servers" 84 | default = [] 85 | } 86 | 87 | variable "docker_labels" { 88 | type = map(string) 89 | description = "The configuration options to send to the `docker_labels`" 90 | default = null 91 | } 92 | 93 | variable "docker_security_options" { 94 | type = list(string) 95 | description = "A list of strings to provide custom labels for SELinux and AppArmor multi-level security systems." 96 | default = [] 97 | } 98 | 99 | variable "entrypoint" { 100 | type = list(string) 101 | description = "The entry point that is passed to the container" 102 | default = null 103 | } 104 | 105 | variable "environment" { 106 | type = list(object({ 107 | name = string 108 | value = string 109 | })) 110 | description = "The environment variables to pass to the container. This is a list of maps. map_environment overrides environment" 111 | default = [] 112 | } 113 | 114 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_EnvironmentFile.html 115 | variable "environment_files" { 116 | type = list(object({ 117 | value = string 118 | type = string 119 | })) 120 | description = "One or more files containing the environment variables to pass to the container. This maps to the --env-file option to docker run. The file must be hosted in Amazon S3. This option is only available to tasks using the EC2 launch type. This is a list of maps" 121 | default = [] 122 | } 123 | 124 | variable "essential" { 125 | type = bool 126 | description = "Determines whether all other containers in a task are stopped, if this container fails or stops for any reason. Due to how Terraform type casts booleans in json it is required to double quote this value" 127 | default = true 128 | } 129 | 130 | variable "extra_hosts" { 131 | type = list(object({ 132 | ipAddress = string 133 | hostname = string 134 | })) 135 | description = "A list of hostnames and IP address mappings to append to the /etc/hosts file on the container. This is a list of maps" 136 | default = null 137 | } 138 | 139 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html 140 | variable "firelens_configuration" { 141 | type = object({ 142 | type = string 143 | options = map(string) 144 | }) 145 | description = "The FireLens configuration for the container. This is used to specify and configure a log router for container logs. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_FirelensConfiguration.html" 146 | default = null 147 | } 148 | 149 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html 150 | variable "healthcheck" { 151 | description = "(Optional) A map containing command (string), timeout, interval (duration in seconds), retries (1-10, number of times to retry before marking container unhealthy), and startPeriod (0-300, optional grace period to wait, in seconds, before failed healthchecks count toward retries)" 152 | type = object({ 153 | command = list(string) 154 | retries = number 155 | timeout = number 156 | interval = number 157 | startPeriod = number 158 | }) 159 | default = null 160 | } 161 | 162 | variable "hostname" { 163 | type = string 164 | description = "The hostname to use for your container." 165 | default = null 166 | } 167 | 168 | variable "interactive" { 169 | type = bool 170 | description = "When this parameter is true, this allows you to deploy containerized applications that require stdin or a tty to be allocated." 171 | default = null 172 | } 173 | 174 | variable "links" { 175 | type = list(string) 176 | description = "List of container names this container can communicate with without port mappings" 177 | default = [] 178 | } 179 | 180 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html 181 | variable "linux_parameters" { 182 | type = object({ 183 | capabilities = object({ 184 | add = list(string) 185 | drop = list(string) 186 | }) 187 | devices = list(object({ 188 | containerPath = string 189 | hostPath = string 190 | permissions = list(string) 191 | })) 192 | initProcessEnabled = bool 193 | maxSwap = number 194 | sharedMemorySize = number 195 | swappiness = number 196 | tmpfs = list(object({ 197 | containerPath = string 198 | mountOptions = list(string) 199 | size = number 200 | })) 201 | }) 202 | description = "Linux-specific modifications that are applied to the container, such as Linux kernel capabilities. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LinuxParameters.html" 203 | default = null 204 | } 205 | 206 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html 207 | variable "log_configuration" { 208 | type = any 209 | description = "Log configuration options to send to a custom log driver for the container. For more details, see https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_LogConfiguration.html" 210 | default = null 211 | } 212 | 213 | variable "map_environment" { 214 | type = map(string) 215 | description = "The environment variables to pass to the container. This is a map of string: {key: value}. map_environment overrides environment" 216 | default = null 217 | } 218 | 219 | variable "map_secrets" { 220 | type = map(string) 221 | description = "The secrets variables to pass to the container. This is a map of string: {key: value}. map_secrets overrides secrets" 222 | default = null 223 | } 224 | 225 | variable "mount_points" { 226 | type = list(any) 227 | description = "Container mount points. This is a list of maps, where each map should contain a `containerPath` and `sourceVolume`. The `readOnly` key is optional." 228 | default = [] 229 | } 230 | 231 | variable "port_mappings" { 232 | description = "The port mappings to configure for the container. This is a list of maps. Each map should contain \"containerPort\", \"hostPort\", and \"protocol\", where \"protocol\" is one of \"tcp\" or \"udp\". If using containers in a task with the awsvpc or host network mode, the hostPort can either be left blank or set to the same value as the containerPort" 233 | type = list(object({ 234 | name = optional(string) 235 | containerPort = number 236 | hostPort = number 237 | protocol = string 238 | })) 239 | default = [ 240 | { 241 | containerPort = 80 242 | hostPort = 80 243 | protocol = "tcp" 244 | } 245 | ] 246 | } 247 | 248 | variable "privileged" { 249 | type = bool 250 | description = "When this variable is `true`, the container is given elevated privileges on the host container instance (similar to the root user). This parameter is not supported for Windows containers or tasks using the Fargate launch type." 251 | default = null 252 | } 253 | 254 | variable "pseudo_terminal" { 255 | type = bool 256 | description = "When this parameter is true, a TTY is allocated. " 257 | default = null 258 | } 259 | 260 | variable "readonly_root_filesystem" { 261 | type = bool 262 | description = "Determines whether a container is given read-only access to its root filesystem. Due to how Terraform type casts booleans in json it is required to double quote this value" 263 | default = false 264 | } 265 | 266 | variable "repository_credentials" { 267 | type = map(string) 268 | description = "Container repository credentials; required when using a private repo. This map currently supports a single key; \"credentialsParameter\", which should be the ARN of a Secrets Manager's secret holding the credentials" 269 | default = null 270 | } 271 | 272 | # https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ResourceRequirement.html 273 | variable "resource_requirements" { 274 | type = list(object({ 275 | type = string 276 | value = string 277 | })) 278 | description = "The type and amount of a resource to assign to a container. The only supported resource is a GPU." 279 | default = null 280 | } 281 | 282 | variable "secrets" { 283 | type = list(object({ 284 | name = string 285 | valueFrom = string 286 | })) 287 | description = "The secrets to pass to the container. This is a list of maps" 288 | default = [] 289 | } 290 | 291 | variable "start_timeout" { 292 | type = number 293 | description = "Time duration (in seconds) to wait before giving up on resolving dependencies for a container" 294 | default = null 295 | } 296 | 297 | variable "stop_timeout" { 298 | type = number 299 | description = "Time duration (in seconds) to wait before the container is forcefully killed if it doesn't exit normally on its own" 300 | default = null 301 | } 302 | 303 | variable "system_controls" { 304 | type = list(map(string)) 305 | description = "A list of namespaced kernel parameters to set in the container, mapping to the --sysctl option to docker run. This is a list of maps: { namespace = \"\", value = \"\"}" 306 | default = [] 307 | } 308 | 309 | variable "ulimits" { 310 | type = list(object({ 311 | name = string 312 | hardLimit = number 313 | softLimit = number 314 | })) 315 | description = "Container ulimit settings. This is a list of maps, where each map should contain \"name\", \"hardLimit\" and \"softLimit\"" 316 | default = null 317 | } 318 | 319 | variable "user" { 320 | type = string 321 | description = "The user to run as inside the container. Can be any of these formats: user, user:group, uid, uid:gid, user:gid, uid:group. The default (null) will use the container's configured `USER` directive or root if not set." 322 | default = null 323 | } 324 | 325 | variable "volumes_from" { 326 | type = list(object({ 327 | sourceContainer = string 328 | readOnly = bool 329 | })) 330 | description = "A list of VolumesFrom maps which contain \"sourceContainer\" (name of the container that has the volumes to mount) and \"readOnly\" (whether the container can write to the volume)" 331 | default = [] 332 | } 333 | 334 | variable "working_directory" { 335 | type = string 336 | description = "The working directory to run commands inside the container" 337 | default = null 338 | } 339 | 340 | #------------------------------------------------------------------------------ 341 | # AWS ECS Task Definition Variables 342 | #------------------------------------------------------------------------------ 343 | variable "additional_containers" { 344 | description = "Additional container definitions (sidecars) to use for the task." 345 | default = [] #Use json_map_object from outputs of cloudposse/ecs-container-definition/aws 346 | type = any 347 | } 348 | 349 | variable "ecs_task_execution_role_custom_policies" { 350 | description = "(Optional) Custom policies to attach to the ECS task execution role. For example for reading secrets from AWS Systems Manager Parameter Store or Secrets Manager" 351 | type = list(string) 352 | default = [] 353 | } 354 | 355 | variable "iam_partition" { 356 | description = "IAM partition to use when referencing standard policies. GovCloud and some other regions use different partitions" 357 | type = string 358 | default = "aws" 359 | } 360 | 361 | variable "permissions_boundary" { 362 | description = "(Optional) The ARN of the policy that is used to set the permissions boundary for the `ecs_task_execution_role` role." 363 | type = string 364 | default = null 365 | } 366 | 367 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#task_definition_ipcmode 368 | variable "ipc_mode" { 369 | type = string 370 | description = "(Optional) IPC resource namespace to be used for the containers in the task The valid values are host, task, and none." 371 | default = null 372 | } 373 | 374 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#runtime-platform 375 | variable "runtime_platform_cpu_architecture" { 376 | type = string 377 | description = "Must be set to either X86_64 or ARM64" 378 | default = "X86_64" 379 | } 380 | 381 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#runtime-platform 382 | variable "runtime_platform_operating_system_family" { 383 | type = string 384 | default = "LINUX" 385 | description = "If the requires_compatibilities is FARGATE this field is required. The valid values for Amazon ECS tasks that are hosted on Fargate are LINUX, WINDOWS_SERVER_2019_FULL, WINDOWS_SERVER_2019_CORE, WINDOWS_SERVER_2022_FULL, and WINDOWS_SERVER_2022_CORE." 386 | } 387 | 388 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#task_definition_pidmode 389 | variable "pid_mode" { 390 | type = string 391 | description = "(Optional) Process namespace to use for the containers in the task. The valid values are host and task" 392 | default = null 393 | } 394 | 395 | variable "placement_constraints" { 396 | description = "(Optional) A set of placement constraints rules that are taken into consideration during task placement. Maximum number of placement_constraints is 10." 397 | type = list(object({ 398 | expression = string # Cluster Query Language expression to apply to the constraint. For more information, see Cluster Query Language in the Amazon EC2 Container Service Developer Guide. 399 | type = string # Type of constraint. Use memberOf to restrict selection to a group of valid candidates. Note that distinctInstance is not supported in task definitions. 400 | })) 401 | default = [] 402 | } 403 | 404 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#proxyConfiguration 405 | variable "proxy_configuration" { 406 | description = "(Optional) The proxy configuration details for the App Mesh proxy. This is a list of maps, where each map should contain \"container_name\", \"properties\" and \"type\"" 407 | type = list(object({ 408 | container_name = string # Name of the container that will serve as the App Mesh proxy. 409 | properties = list(object({ # Set of network configuration parameters to provide the Container Network Interface (CNI) plugin, specified a key-value mapping. 410 | name = string 411 | value = string 412 | })) 413 | type = string # Proxy type. The default value is APPMESH. The only supported value is APPMESH. 414 | })) 415 | default = [] 416 | } 417 | 418 | # https://docs.aws.amazon.com/AmazonECS/latest/userguide/task_definition_parameters.html#task_definition_ephemeralStorage 419 | variable "ephemeral_storage_size" { 420 | type = number 421 | description = "The number of GBs to provision for ephemeral storage on Fargate tasks. Must be greater than or equal to 21 and less than or equal to 200" 422 | default = 0 423 | 424 | validation { 425 | condition = var.ephemeral_storage_size == 0 || (var.ephemeral_storage_size >= 21 && var.ephemeral_storage_size <= 200) 426 | error_message = "The ephemeral_storage_size value must be inclusively between 21 and 200." 427 | } 428 | } 429 | 430 | variable "skip_destroy" { 431 | type = bool 432 | description = "(Optional) Whether to retain the old revision when the resource is destroyed or replacement is necessary. Default is false." 433 | default = false 434 | } 435 | 436 | variable "task_role_arn" { 437 | description = "(Optional) The ARN of IAM role that grants permissions to the actual application once the container is started (e.g access an S3 bucket or DynamoDB database). If not specified, `aws_iam_role.ecs_task_execution_role.arn` is used" 438 | type = string 439 | default = null 440 | } 441 | 442 | variable "execution_role_arn" { 443 | description = "(Optional) The ARN of IAM role that grants permissions to start the containers defined in a task (e.g populate environment variables from AWS Secrets Manager). If not specified, `aws_iam_role.ecs_task_execution_role.arn` is used" 444 | type = string 445 | default = null 446 | } 447 | 448 | variable "volumes" { 449 | description = "(Optional) A set of volume blocks that containers in your task may use" 450 | type = list(object({ 451 | host_path = string 452 | name = string 453 | docker_volume_configuration = list(object({ 454 | autoprovision = bool 455 | driver = string 456 | driver_opts = map(string) 457 | labels = map(string) 458 | scope = string 459 | })) 460 | efs_volume_configuration = list(object({ 461 | file_system_id = string 462 | root_directory = string 463 | transit_encryption = string 464 | transit_encryption_port = string 465 | authorization_config = list(object({ 466 | access_point_id = string 467 | iam = string 468 | })) 469 | })) 470 | })) 471 | default = [] 472 | } 473 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13" 3 | required_providers { 4 | aws = { 5 | source = "hashicorp/aws" 6 | version = ">= 4.0.0" 7 | } 8 | } 9 | } 10 | --------------------------------------------------------------------------------