diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml new file mode 100644 index 0000000..3646f9f --- /dev/null +++ b/.github/workflows/readme.yml @@ -0,0 +1,54 @@ +name: 'Create README.md file' +on: + push: + branches: + - master + +jobs: + readme-create: + name: 'readme-create' + runs-on: ubuntu-latest + steps: + - name: 'Checkout' + uses: actions/checkout@master + + - name: Set up Python 3.7. + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: 'create readme' + uses: 'clouddrove/github-actions@v4.0' + with: + actions_subcommand: 'readme' + github_token: '${{ secrets.GITHUB}}' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} + + + - name: pre-commit check errors + uses: pre-commit/action@v2.0.0 + continue-on-error: true + + - name: pre-commit fix erros + uses: pre-commit/action@v2.0.0 + continue-on-error: true + + - name: 'push readme' + uses: 'clouddrove/github-actions@v4.0' + continue-on-error: true + with: + actions_subcommand: 'push' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN}} + + - name: 'Slack Notification' + uses: clouddrove/action-slack@v2 + with: + status: ${{ job.status }} + fields: repo,author + author_name: 'CloudDrove' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required + if: always() \ No newline at end of file diff --git a/.github/workflows/terraform.yml b/.github/workflows/terraform.yml index 556d0eb..160e806 100644 --- a/.github/workflows/terraform.yml +++ b/.github/workflows/terraform.yml @@ -1,57 +1,54 @@ name: 'Terraform GitHub Actions' on: - - pull_request + pull_request: + branches: + - master jobs: terraform: name: 'Terraform' runs-on: ubuntu-latest steps: - - name: 'Checkout' uses: actions/checkout@master + - name: Configure AWS Credentials + uses: clouddrove/configure-aws-credentials@v1 + with: + aws-access-key-id: ${{ secrets.TEST_AWS_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.TEST_AWS_ACCESS_SECRET_KEY }} + aws-region: us-east-2 + - name: 'Terraform Format' - uses: clouddrove/github-actions@v2.0 + uses: 'clouddrove/github-actions@v4.0' with: actions_subcommand: 'fmt' - - name: 'Terraform Init' - uses: clouddrove/github-actions@v2.0 + - name: 'Terraform init' + uses: 'clouddrove/github-actions@v4.0' with: actions_subcommand: 'init' tf_actions_working_dir: ./_example - - name: Configure AWS Credentials - uses: clouddrove/configure-aws-credentials@v1 + - name: 'Terraform validate' + uses: 'clouddrove/github-actions@v4.0' with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: us-east-2 + actions_subcommand: 'validate' + tf_actions_working_dir: ./_example - - name: 'Terraform Plan' - uses: clouddrove/github-actions@v2.0 + - name: 'Terraform plan' + uses: 'clouddrove/github-actions@v4.0' with: actions_subcommand: 'plan' tf_actions_working_dir: ./_example - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: 'Terratest' - uses: clouddrove/github-actions@v2.0 - with: - actions_subcommand: 'terratest' - tf_actions_working_dir: ./_test - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: 'Slack Notification' uses: clouddrove/action-slack@v2 with: status: ${{ job.status }} fields: repo,author - author_name: 'Clouddrove' + author_name: 'CloudDrove' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # required - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }} # required - if: always() + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }} # required + if: always() \ No newline at end of file diff --git a/.gitignore b/.gitignore index 797a1bb..a279a61 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .terraform .idea *.iml +go.sum \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1269ee7..9a789cb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,13 +1,13 @@ repos: - repo: git://github.com/antonbabenko/pre-commit-terraform - rev: v1.12.0 + rev: v1.43.0 hooks: - id: terraform_fmt - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.0.0 + rev: v3.2.0 hooks: - id: check-merge-conflict - - id: trailing-whitespace - id: check-yaml - - id: check-added-large-files \ No newline at end of file + - id: check-added-large-files + - id: trailing-whitespace \ No newline at end of file diff --git a/LICENSE b/LICENSE index 136d77d..807110a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Cloud Drove +Copyright (c) 2020 Cloud Drove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md deleted file mode 100644 index 2c08610..0000000 --- a/README.md +++ /dev/null @@ -1,157 +0,0 @@ - - -

- - -

- Terraform AWS Cloudtrail -

- -

- Terraform module to provision an AWS CloudTrail with encrypted S3 bucket. This bucket is used to store CloudTrail logs. -

- -

- - - Terraform - - - Licence - - - -

-

- - - - - - - - - - - -

-
- - -We eat, drink, sleep and most importantly love **DevOps**. We are working towards strategies for standardizing architecture while ensuring security for the infrastructure. We are strong believer of the philosophy Bigger problems are always solved by breaking them into smaller manageable problems. Resonating with microservices architecture, it is considered best-practice to run database, cluster, storage in smaller connected yet manageable pieces within the infrastructure. - -This module is basically combination of [Terraform open source](https://www.terraform.io/) and includes automatation tests and examples. It also helps to create and improve your infrastructure with minimalistic code instead of maintaining the whole infrastructure code yourself. - -We have [*fifty plus terraform modules*][terraform_modules]. A few of them are comepleted and are available for open source usage while a few others are in progress. - - - - -## Prerequisites - -This module has a few dependencies: - -- [Terraform 0.12](https://learn.hashicorp.com/terraform/getting-started/install.html) -- [Go](https://golang.org/doc/install) -- [github.com/stretchr/testify/assert](https://github.com/stretchr/testify) -- [github.com/gruntwork-io/terratest/modules/terraform](https://github.com/gruntwork-io/terratest) - - - - - - - -## Examples - - -**IMPORTANT:** Since the `master` branch used in `source` varies based on new modifications, we suggest that you use the release versions [here](https://github.com/clouddrove/terraform-aws-cloudtrail/releases). - - -### Simple Example -Here is an example of how you can use this module in your inventory structure: -```hcl - module "cloudtrail" { - source = "git::https://github.com/clouddrove/terraform-aws-cloudtrail.git?ref=tags/0.12.3" - name = "cloudtrail" - application = "clouddrove" - environment = "security" - label_order = ["environment", "name", "application"] - s3_bucket_name = "s3-logs" - enable_logging = true - enable_log_file_validation = true - include_global_service_events = true - is_multi_region_trail = false - kms_key_id = "arn:aws:kms:eu-west-1:xxxxxxxxx:key/xxxxxx-xxxx-xxxx-xxxxx" - } -``` - - - - - - -## Inputs - -| Name | Description | Type | Default | Required | -|------|-------------|:----:|:-----:|:-----:| -| application | Application \(e.g. `cd` or `clouddrove`\). | string | `""` | no | -| attributes | Additional attributes \(e.g. `1`\). | list(string) | `` | no | -| cloud\_watch\_logs\_group\_arn | Specifies a log group name using an Amazon Resource Name \(ARN\), that represents the log group to which CloudTrail logs will be delivered. | string | `""` | no | -| cloud\_watch\_logs\_role\_arn | Specifies the role for the CloudWatch Logs endpoint to assume to write to a user’s log group. | string | `""` | no | -| enable\_log\_file\_validation | Specifies whether log file integrity validation is enabled. Creates signed digest for validated contents of logs. | bool | `"true"` | no | -| enable\_logging | Enable logging for the trail. | bool | `"true"` | no | -| enabled\_cloudtrail | If true, deploy the resources for the module. | bool | `"true"` | no | -| environment | Environment \(e.g. `prod`, `dev`, `staging`\). | string | `""` | no | -| event\_selector | Specifies an event selector for enabling data event logging, It needs to be a list of map values. See: https://www.terraform.io/docs/providers/aws/r/cloudtrail.html for details on this map variable. | list(string) | `` | no | -| include\_global\_service\_events | Specifies whether the trail is publishing events from global services such as IAM to the log files. | bool | `"false"` | no | -| is\_multi\_region\_trail | Specifies whether the trail is created in the current region or in all regions. | bool | `"false"` | no | -| is\_organization\_trail | The trail is an AWS Organizations trail. | bool | `"false"` | no | -| kms\_key\_id | Specifies the KMS key ARN to use to encrypt the logs delivered by CloudTrail. | string | `""` | no | -| label\_order | Label order, e.g. `name`,`application`. | list | `` | no | -| managedby | ManagedBy, eg 'CloudDrove' or 'AnmolNagpal'. | string | `"anmol@clouddrove.com"` | no | -| name | Name \(e.g. `app` or `cluster`\). | string | n/a | yes | -| s3\_bucket\_name | S3 bucket name for CloudTrail log. | string | n/a | yes | -| tags | Additional tags \(e.g. map\(`BusinessUnit`,`XYZ`\). | map(string) | `` | no | - -## Outputs - -| Name | Description | -|------|-------------| -| arn | The Amazon Resource Name of the trail. | -| home\_region | The region in which the trail was created. | -| id | The name of the trail. | -| tags | A mapping of tags to assign to the resource. | - - - - -## Testing -In this module testing is performed with [terratest](https://github.com/gruntwork-io/terratest) and it creates a small piece of infrastructure, matches the output like ARN, ID and Tags name etc and destroy infrastructure in your AWS account. This testing is written in GO, so you need a [GO environment](https://golang.org/doc/install) in your system. - -You need to run the following command in the testing folder: -```hcl - go test -run Test -``` - - - -## Feedback -If you come accross a bug or have any feedback, please log it in our [issue tracker](https://github.com/clouddrove/terraform-aws-cloudtrail/issues), or feel free to drop us an email at [hello@clouddrove.com](mailto:hello@clouddrove.com). - -If you have found it worth your time, go ahead and give us a ★ on [our GitHub](https://github.com/clouddrove/terraform-aws-cloudtrail)! - -## About us - -At [CloudDrove][website], we offer expert guidance, implementation support and services to help organisations accelerate their journey to the cloud. Our services include docker and container orchestration, cloud migration and adoption, infrastructure automation, application modernisation and remediation, and performance engineering. - -

We are The Cloud Experts!

-
-

We ❤️ Open Source and you can check out our other modules to get help with your new Cloud ideas.

- - [website]: https://clouddrove.com - [github]: https://github.com/clouddrove - [linkedin]: https://cpco.io/linkedin - [twitter]: https://twitter.com/clouddrove/ - [email]: https://clouddrove.com/contact-us.html - [terraform_modules]: https://github.com/clouddrove?utf8=%E2%9C%93&q=terraform-&type=&language= diff --git a/README.yaml b/README.yaml index ed68c2d..e779f64 100644 --- a/README.yaml +++ b/README.yaml @@ -5,7 +5,7 @@ # # Name of this project -name : Terraform AWS Cloudtrail +name: Terraform AWS Cloudtrail # License of this project license: "MIT" @@ -16,13 +16,14 @@ github_repo: clouddrove/terraform-aws-cloudtrail # Badges to display badges: - name: "Terraform" - image: "https://img.shields.io/badge/Terraform-v0.12-green" + image: "https://img.shields.io/badge/terraform-v0.13-green" url: "https://www.terraform.io" - name: "Licence" image: "https://img.shields.io/badge/License-MIT-blue.svg" url: "LICENSE.md" # description of this project +# yamllint disable rule:line-length description: |- Terraform module to provision an AWS CloudTrail with encrypted S3 bucket. This bucket is used to store CloudTrail logs. @@ -31,12 +32,14 @@ include: - "terraform.md" # How to use this project -usage : |- +# yamllint disable rule:line-length +usage: |- ### Simple Example Here is an example of how you can use this module in your inventory structure: ```hcl module "cloudtrail" { - source = "git::https://github.com/clouddrove/terraform-aws-cloudtrail.git?ref=tags/0.12.3" + source = "clouddrove/cloudtrail/aws" + version = "0.13.0" name = "cloudtrail" application = "clouddrove" environment = "security" @@ -48,4 +51,4 @@ usage : |- is_multi_region_trail = false kms_key_id = "arn:aws:kms:eu-west-1:xxxxxxxxx:key/xxxxxx-xxxx-xxxx-xxxxx" } - ``` \ No newline at end of file + ``` diff --git a/_example/example.tf b/_example/example.tf index dfae22e..ea179fd 100644 --- a/_example/example.tf +++ b/_example/example.tf @@ -3,10 +3,9 @@ provider "aws" { } module "s3_logs" { - source = "git::https://github.com/clouddrove/terraform-aws-s3.git?ref=tags/0.12.1" - + source = "clouddrove/s3/aws" + version = "0.13.0" name = "bucket-log" - region = "eu-west-1" application = "clouddrove" environment = "security" label_order = ["environment", "name", "application"] @@ -19,8 +18,8 @@ module "s3_logs" { } module "kms_key" { - source = "git::https://github.com/clouddrove/terraform-aws-kms.git?ref=tags/0.12.1" - + source = "clouddrove/kms/aws" + version = "0.13.0" name = "kms" application = "clouddrove" environment = "test" diff --git a/_test/go.mod b/_test/go.mod new file mode 100644 index 0000000..7cda99b --- /dev/null +++ b/_test/go.mod @@ -0,0 +1,8 @@ +module github.com/clouddrove/terraform-aws-cloudtrail/_example + +go 1.13 + +require ( + github.com/gruntwork-io/terratest v0.30.6 + github.com/stretchr/testify v1.6.1 +) diff --git a/main.tf b/main.tf index ae273ef..d3b33c6 100644 --- a/main.tf +++ b/main.tf @@ -7,7 +7,7 @@ # for resources. You can use terraform-labels to implement a strict naming # convention. module "labels" { - source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.12.0" + source = "git::https://github.com/clouddrove/terraform-labels.git?ref=tags/0.13.0" name = var.name application = var.application @@ -33,4 +33,9 @@ resource "aws_cloudtrail" "default" { kms_key_id = var.kms_key_id is_organization_trail = var.is_organization_trail tags = module.labels.tags + sns_topic_name = var.sns_topic_name + event_selector { + read_write_type = "All" + include_management_events = true + } } \ No newline at end of file diff --git a/variables.tf b/variables.tf index ef741e9..08a1751 100644 --- a/variables.tf +++ b/variables.tf @@ -106,4 +106,10 @@ variable "is_organization_trail" { type = bool default = false description = "The trail is an AWS Organizations trail." +} + +variable "sns_topic_name" { + type = string + default = "testing" + description = "Specifies the name of the Amazon SNS topic defined for notification of log file delivery." } \ No newline at end of file diff --git a/versions.tf b/versions.tf index 5e90985..a8a23bd 100644 --- a/versions.tf +++ b/versions.tf @@ -1,4 +1,10 @@ # Terraform version terraform { - required_version = ">= 0.12" + required_version = ">= 0.13" + required_providers { + aws = { + source = "hashicorp/aws" + version = "3.10.0" + } + } }