-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 22bd677
Showing
69 changed files
with
3,291 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| files/2309944673836897605-key.pem |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Local .terraform directories | ||
| **/.terraform/* | ||
|
|
||
| # .tfstate files | ||
| *.tfstate | ||
| *.tfstate.* | ||
|
|
||
| # Crash log files | ||
| crash.log | ||
| crash.*.log | ||
|
|
||
| # Exclude all .tfvars files, which are likely to contain sensitive data, such as | ||
| # password, private keys, and other secrets. These should not be part of version | ||
| # control as they are data points which are potentially sensitive and subject | ||
| # to change depending on the environment. | ||
| *.tfvars | ||
| *.tfvars.json | ||
|
|
||
| # Ignore override files as they are usually used to override resources locally and so | ||
| # are not checked in | ||
| override.tf | ||
| override.tf.json | ||
| *_override.tf | ||
| *_override.tf.json | ||
|
|
||
| # Include override files you do wish to add to version control using negated pattern | ||
| # !example_override.tf | ||
|
|
||
| # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan | ||
| # example: *tfplan* | ||
|
|
||
| # Ignore CLI configuration files | ||
| .terraformrc | ||
| terraform.rc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #### How to use this file: https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners | ||
| # These owners will be the default owners for everything in the repo. Unless a later match takes precedence | ||
| * @roknsound/terraform-reviewers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ## Code of Conduct | ||
| This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). | ||
| For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact | ||
| opensource-codeofconduct@amazon.com with any additional questions or comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Contributing Guidelines | ||
|
|
||
| Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional | ||
| documentation, we greatly value feedback and contributions from our community. | ||
|
|
||
| Please read through this document before submitting any issues or pull requests to ensure we have all the necessary | ||
| information to effectively respond to your bug report or contribution. | ||
|
|
||
|
|
||
| ## Reporting Bugs/Feature Requests | ||
|
|
||
| We welcome you to use the GitHub issue tracker to report bugs or suggest features. | ||
|
|
||
| When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already | ||
| reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: | ||
|
|
||
| * A reproducible test case or series of steps | ||
| * The version of our code being used | ||
| * Any modifications you've made relevant to the bug | ||
| * Anything unusual about your environment or deployment | ||
|
|
||
|
|
||
| ## Contributing via Pull Requests | ||
| Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: | ||
|
|
||
| 1. You are working against the latest source on the *main* branch. | ||
| 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. | ||
| 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. | ||
|
|
||
| To send us a pull request, please: | ||
|
|
||
| 1. Fork the repository. | ||
| 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. | ||
| 3. Ensure local tests pass. | ||
| 4. Commit to your fork using clear commit messages. | ||
| 5. Send us a pull request, answering any default questions in the pull request interface. | ||
| 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. | ||
|
|
||
| GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and | ||
| [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). | ||
|
|
||
|
|
||
| ## Finding contributions to work on | ||
| Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. | ||
|
|
||
|
|
||
| ## Code of Conduct | ||
| This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). | ||
| For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact | ||
| opensource-codeofconduct@amazon.com with any additional questions or comments. | ||
|
|
||
|
|
||
| ## Security issue notifications | ||
| If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. | ||
|
|
||
|
|
||
| ## Licensing | ||
|
|
||
| See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
| the Software, and to permit persons to whom the Software is furnished to do so. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
| FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
| COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
| IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
| CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| # AWS CodePipeline CI/CD example | ||
| Terraform is an infrastructure-as-code (IaC) tool that helps you create, update, and version your infrastructure in a secure and repeatable manner. | ||
|
|
||
| The scope of this pattern is to provide a guide and ready to use terraform configurations to setup validation pipelines with end-to-end tests based on AWS CodePipeline, AWS CodeBuild, AWS CodeCommit and Terraform. | ||
|
|
||
| The created pipeline uses the best practices for infrastructure validation and has the below stages | ||
|
|
||
| - validate - This stage focuses on terraform IaC validation tools and commands such as terraform validate, terraform format, tfsec, tflint and checkov | ||
| - plan - This stage creates an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure. | ||
| - apply - This stage uses the plan created above to provision the infrastructure in the test account. | ||
| - destroy - This stage destroys the infrastructure created in the above stage. | ||
| Running these four stages ensures the integrity of the terraform configurations. | ||
|
|
||
| ## Directory Structure | ||
| ```shell | ||
| |-- CODE_OF_CONDUCT.md | ||
| |-- CONTRIBUTING.md | ||
| |-- LICENSE | ||
| |-- README.md | ||
| |-- data.tf | ||
| |-- examples | ||
| | `-- terraform.tfvars | ||
| |-- locals.tf | ||
| |-- main.tf | ||
| |-- modules | ||
| | |-- codebuild | ||
| | | |-- README.md | ||
| | | |-- main.tf | ||
| | | |-- outputs.tf | ||
| | | `-- variables.tf | ||
| | |-- codecommit | ||
| | | |-- README.md | ||
| | | |-- data.tf | ||
| | | |-- main.tf | ||
| | | |-- outputs.tf | ||
| | | `-- variables.tf | ||
| | |-- codepipeline | ||
| | | |-- README.md | ||
| | | |-- main.tf | ||
| | | |-- outputs.tf | ||
| | | `-- variables.tf | ||
| | |-- iam-role | ||
| | | |-- README.md | ||
| | | |-- data.tf | ||
| | | |-- main.tf | ||
| | | |-- outputs.tf | ||
| | | `-- variables.tf | ||
| | |-- kms | ||
| | | |-- README.md | ||
| | | |-- main.tf | ||
| | | |-- outputs.tf | ||
| | | `-- variables.tf | ||
| | `-- s3 | ||
| | |-- README.md | ||
| | |-- main.tf | ||
| | |-- outputs.tf | ||
| | `-- variables.tf | ||
| |-- templates | ||
| | |-- buildspec_apply.yml | ||
| | |-- buildspec_destroy.yml | ||
| | |-- buildspec_plan.yml | ||
| | |-- buildspec_validate.yml | ||
| | `-- scripts | ||
| | `-- tf_ssp_validation.sh | ||
| `-- variables.tf | ||
| ``` | ||
| ## Installation | ||
|
|
||
| #### Step 1: Clone this repository. | ||
|
|
||
| ```shell | ||
| git@github.com:aws-samples/aws-codepipeline-terraform-cicd-samples.git | ||
| ``` | ||
| Note: If you don't have git installed, [install git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). | ||
| #### Step 2: Update the variables in `examples/terraform.tfvars` based on your requirement. Make sure you ae updating the variables project_name, environment, source_repo_name, source_repo_branch, create_new_repo, stage_input and build_projects. | ||
| - If you are planning to use an existing terraform CodeCommit repository, then update the variable create_new_repo as false and provide the name of your existing repo under the variable source_repo_name | ||
| - If you are planning to create new terraform CodeCommit repository, then update the variable create_new_repo as true and provide the name of your new repo under the variable source_repo_name | ||
| #### Step 3: Update remote backend configuration as required | ||
| #### Step 4: Configure the AWS Command Line Interface (AWS CLI) where this IaC is being executed. For more information, see [Configuring the AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). | ||
| #### Step 5: Initialize the directory. Run terraform init | ||
| #### Step 6: Start a Terraform run using the command terraform apply | ||
| Note: Sample terraform.tfvars are available in the examples directory. You may use the below command if you need to provide this sample tfvars as an input to the apply command. | ||
| ```shell | ||
| terraform apply -var-file=./examples/terraform.tfvars | ||
| ``` | ||
| ## Pre-Requisites | ||
| #### Step 1: You would get source_repo_clone_url_http as an output of the installation step. Clone the repository to your local. | ||
| git clone <source_repo_clone_url_http> | ||
| #### Step 2: Clone this repository. | ||
| ```shell | ||
| git@github.com:aws-samples/aws-eks-accelerator-for-terraform.git | ||
| ``` | ||
| Note: If you don't have git installed, [install git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). | ||
|
|
||
| #### Step 3: Copy the templates folder to the AWS CodeCommit sourcecode repository which contains the terraform code to be deployed. | ||
| ```shell | ||
| cd examples/ci-cd/aws-codepipeline | ||
| cp -r templates $YOUR_CODECOMMIT_REPO_ROOT | ||
| ``` | ||
|
|
||
|
|
||
| #### Step 4: Update the variables in the template files with appropriate values and push the same. | ||
|
|
||
| #### Step 5: Trigger the pipeline created in the Installation step. | ||
|
|
||
| **Note1**: The IAM Role used by the newly created pipeline is very restrictive and follows the Principle of least privilege. Please update the IAM Policy with the required permissions. | ||
| Alternatively, use the _**create_new_role = false**_ option to use an existing IAM role and specify the role name using the variable _**codepipeline_iam_role_name**_ | ||
|
|
||
| **Note2**: If the **create_new_repo** flag is set to **true**, a new blank repository will be created with the name assigned to the variable **_source_repo_name_**. Since this repository will not be containing the templates folder specified in Step 3 nor any code files, the initial run of the pipeline will be marked as failed in the _Download-Source_ stage itself. | ||
|
|
||
| **Note3**: If the **create_new_repo** flag is set to **false** to use an existing repository, ensure the pre-requisite steps specified in step 3 have been done on the target repository. | ||
|
|
||
| <!-- BEGIN_TF_DOCS --> | ||
| ## Requirements | ||
|
|
||
| | Name | Version | | ||
| |------|-----------| | ||
| | <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | \>= 1.0.0 | | ||
|
|
||
|
|
||
| ## Providers | ||
|
|
||
| | Name | Version | | ||
| |------|------------| | ||
| | <a name="provider_aws"></a> [aws](#provider\_aws) | \>= 4.20.1 | | ||
|
|
||
| ## Modules | ||
|
|
||
| | Name | Source | Version | | ||
| |------|--------|---------| | ||
| | <a name="module_codebuild_terraform"></a> [codebuild\_terraform](#module\_codebuild\_terraform) | ./modules/codebuild | n/a | | ||
| | <a name="module_codecommit_infrastructure_source_repo"></a> [codecommit\_infrastructure\_source\_repo](#module\_codecommit\_infrastructure\_source\_repo) | ./modules/codecommit | n/a | | ||
| | <a name="module_codepipeline_iam_role"></a> [codepipeline\_iam\_role](#module\_codepipeline\_iam\_role) | ./modules/iam-role | n/a | | ||
| | <a name="module_codepipeline_kms"></a> [codepipeline\_kms](#module\_codepipeline\_kms) | ./modules/kms | n/a | | ||
| | <a name="module_codepipeline_terraform"></a> [codepipeline\_terraform](#module\_codepipeline\_terraform) | ./modules/codepipeline | n/a | | ||
| | <a name="module_s3_artifacts_bucket"></a> [s3\_artifacts\_bucket](#module\_s3\_artifacts\_bucket) | ./modules/s3 | n/a | | ||
|
|
||
| ## Resources | ||
|
|
||
| | Name | Type | | ||
| |------|------| | ||
| | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | | ||
| | [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source | | ||
|
|
||
| ## Inputs | ||
|
|
||
| | Name | Description | Type | Default | Required | | ||
| |------|-------------|------|---------|:--------:| | ||
| | <a name="input_build_project_source"></a> [build\_project\_source](#input\_build\_project\_source) | aws/codebuild/standard:4.0 | `string` | `"CODEPIPELINE"` | no | | ||
| | <a name="input_build_projects"></a> [build\_projects](#input\_build\_projects) | Tags to be attached to the CodePipeline | `list(string)` | n/a | yes | | ||
| | <a name="input_builder_compute_type"></a> [builder\_compute\_type](#input\_builder\_compute\_type) | Relative path to the Apply and Destroy build spec file | `string` | `"BUILD_GENERAL1_SMALL"` | no | | ||
| | <a name="input_builder_image"></a> [builder\_image](#input\_builder\_image) | Docker Image to be used by codebuild | `string` | `"aws/codebuild/amazonlinux2-x86_64-standard:3.0"` | no | | ||
| | <a name="input_builder_image_pull_credentials_type"></a> [builder\_image\_pull\_credentials\_type](#input\_builder\_image\_pull\_credentials\_type) | Image pull credentials type used by codebuild project | `string` | `"CODEBUILD"` | no | | ||
| | <a name="input_builder_type"></a> [builder\_type](#input\_builder\_type) | Type of codebuild run environment | `string` | `"LINUX_CONTAINER"` | no | | ||
| | <a name="input_codepipeline_iam_role_name"></a> [codepipeline\_iam\_role\_name](#input\_codepipeline\_iam\_role\_name) | Name of the IAM role to be used by the Codepipeline | `string` | `"codepipeline-role"` | no | | ||
| | <a name="input_create_new_repo"></a> [create\_new\_repo](#input\_create\_new\_repo) | Whether to create a new repository. Values are true or false. Defaulted to true always. | `bool` | `true` | no | | ||
| | <a name="input_create_new_role"></a> [create\_new\_role](#input\_create\_new\_role) | Whether to create a new IAM Role. Values are true or false. Defaulted to true always. | `bool` | `true` | no | | ||
| | <a name="input_environment"></a> [environment](#input\_environment) | Environment in which the script is run. Eg: dev, prod, etc | `string` | n/a | yes | | ||
| | <a name="input_project_name"></a> [project\_name](#input\_project\_name) | Unique name for this project | `string` | n/a | yes | | ||
| | <a name="input_repo_approvers_arn"></a> [repo\_approvers\_arn](#input\_repo\_approvers\_arn) | ARN or ARN pattern for the IAM User/Role/Group that can be used for approving Pull Requests | `string` | n/a | yes | | ||
| | <a name="input_source_repo_branch"></a> [source\_repo\_branch](#input\_source\_repo\_branch) | Default branch in the Source repo for which CodePipeline needs to be configured | `string` | n/a | yes | | ||
| | <a name="input_source_repo_name"></a> [source\_repo\_name](#input\_source\_repo\_name) | Source repo name of the CodeCommit repository | `string` | n/a | yes | | ||
| | <a name="input_stage_input"></a> [stage\_input](#input\_stage\_input) | Tags to be attached to the CodePipeline | `list(map(any))` | n/a | yes | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| |------|-------------| | ||
| | <a name="output_codebuild_arn"></a> [codebuild\_arn](#output\_codebuild\_arn) | The ARN of the Codebuild Project | | ||
| | <a name="output_codebuild_name"></a> [codebuild\_name](#output\_codebuild\_name) | The Name of the Codebuild Project | | ||
| | <a name="output_codecommit_arn"></a> [codecommit\_arn](#output\_codecommit\_arn) | The ARN of the Codecommit repository | | ||
| | <a name="output_codecommit_name"></a> [codecommit\_name](#output\_codecommit\_name) | The name of the Codecommit repository | | ||
| | <a name="output_codecommit_url"></a> [codecommit\_url](#output\_codecommit\_url) | The Clone URL of the Codecommit repository | | ||
| | <a name="output_codepipeline_arn"></a> [codepipeline\_arn](#output\_codepipeline\_arn) | The ARN of the CodePipeline | | ||
| | <a name="output_codepipeline_name"></a> [codepipeline\_name](#output\_codepipeline\_name) | The Name of the CodePipeline | | ||
| | <a name="output_iam_arn"></a> [iam\_arn](#output\_iam\_arn) | The ARN of the IAM Role used by the CodePipeline | | ||
| | <a name="output_kms_arn"></a> [kms\_arn](#output\_kms\_arn) | The ARN of the KMS key used in the codepipeline | | ||
| | <a name="output_s3_arn"></a> [s3\_arn](#output\_s3\_arn) | The ARN of the S3 Bucket | | ||
| | <a name="output_s3_bucket_name"></a> [s3\_bucket\_name](#output\_s3\_bucket\_name) | The Name of the S3 Bucket | | ||
| <!-- END_TF_DOCS --> | ||
|
|
||
| ## Security | ||
|
|
||
| See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. | ||
|
|
||
| ## License | ||
|
|
||
| This library is licensed under the MIT-0 License. See the LICENSE file. | ||
|
|
Oops, something went wrong.