Skip to content

Commit

Permalink
Merge pull request #5 from tomarv2/develop
Browse files Browse the repository at this point in the history
Pulling refs/heads/develop into main
  • Loading branch information
tomarv2 authored Mar 28, 2022
2 parents e6f67df + e47a861 commit a34e3d9
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 57 deletions.
70 changes: 58 additions & 12 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ on:
pull_request:
push:
branches:
- main
- develop
- main

jobs:
# Min Terraform version(s)
getDirectories:
name: Get root directories
runs-on: ubuntu-latest
Expand All @@ -25,13 +24,13 @@ jobs:
- name: Build matrix
id: matrix
run: |
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/providers.tf', '') for x in glob.glob('./**/providers.tf', recursive=True)]))")
echo "::set-output name=directories::$DIRS"
outputs:
directories: ${{ steps.matrix.outputs.directories }}

preCommitMinVersions:
name: Min TF validate
name: Min validate
needs: getDirectories
runs-on: ubuntu-latest
strategy:
Expand All @@ -58,11 +57,9 @@ jobs:
with:
terraform_version: ${{ steps.minMax.outputs.minVersion }}

- name: Install pre-commit dependencies
- name: Install pre-commit
run: pip install pre-commit


# Max Terraform version
getBaseVersion:
name: Module max TF version
runs-on: ubuntu-latest
Expand All @@ -78,7 +75,7 @@ jobs:
maxVersion: ${{ steps.minMax.outputs.maxVersion }}

preCommitMaxVersion:
name: Max TF pre-commit
name: Max pre-commit
runs-on: ubuntu-latest
needs: getBaseVersion
strategy:
Expand All @@ -105,10 +102,59 @@ jobs:
run: |
pip install pre-commit
pip install checkov
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v1.0.1-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
- name: Execute pre-commit
# Run all pre-commit checks on max version supported
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
run: pre-commit run --color=always --show-diff-on-failure --all-files
continue-on-error: true # To avoid pre-commit failure
run: |
pre-commit run --color=always --show-diff-on-failure --all-files
- name: Get current branch name
id: vars
run: |
echo ::set-output name=branch_name::${GITHUB_REF##*/}
- name: "Get branch name and save to env"
env:
IS_PR: ${{ github.EVENT_NAME == 'pull_request' }}
run: |
if ${IS_PR}; then
BRANCH_NAME="${GITHUB_HEAD_REF}"
else
BRANCH_NAME="${GITHUB_REF##*/}"
fi
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV
- uses: actions/checkout@v2
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Render terraform docs and commit changes
if: ${{ env.BRANCH_NAME }} == 'develop'
uses: terraform-docs/gh-actions@main
with:
working-dir: .
output-file: README.md
output-method: inject
git-push: "true"

- name: Commit pre-commit modified files
if: ${{ env.BRANCH_NAME }} == 'develop'
run: |
git config --local user.email "terraform+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git diff-index --quiet HEAD || (git add -A && git commit -m'[bot] update files' --allow-empty && git push -f)
- uses: actions/checkout@v2
- name: Create PR
continue-on-error: true
uses: repo-sync/pull-request@v2
if: ${{ env.BRANCH_NAME }} == 'develop'
with:
source_branch: "develop"
destination_branch: "main"
pr_title: "Pulling ${{ github.ref }} into main"
pr_body: ":crown: *Automated PR*"
pr_label: "auto-pr"
pr_allow_empty: false
github_token: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/state-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: "Mark or close stale issues and PRs"
on:
schedule:
- cron: "0 0 10 * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v4
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
# Staling issues and PR's
days-before-stale: 30
stale-issue-label: stale
stale-pr-label: stale
stale-issue-message: |
This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days
stale-pr-message: |
This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days
# Not stale if have this labels or part of milestone
exempt-issue-labels: bug,wip,on-hold
exempt-pr-labels: bug,wip,on-hold
exempt-all-milestones: true
# Close issue operations
# Label will be automatically removed if the issues are no longer closed nor locked.
days-before-close: 10
delete-branch: false
close-issue-message: This issue was automatically closed because of stale in 10 days
close-pr-message: This PR was automatically closed because of stale in 10 days
24 changes: 11 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ override.tf.json
# example: *tfplan*

.idea/
.vscode/
.terraform.lock.hcl

# go
Expand Down Expand Up @@ -81,15 +82,10 @@ _testmain.go

# Python
# Editors
.vscode/
.idea/

# Vagrant
.vagrant/

# Mac/OSX
.DS_Store

# Windows
Thumbs.db

Expand All @@ -99,9 +95,6 @@ __pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
Expand Down Expand Up @@ -206,9 +199,14 @@ venv.bak/
.dmypy.json
dmypy.json

# ignore test related file(s)
**/test**
**.

# ignore terraform external modules
# Terraform external modules
**/.external_modules

# Test files and directories
**/[Tt]est/*
**/[Tt]ests/*
**/*[Tt]est*/*
**/*[Tt]ests*/*

# remote_backend.tf file
**/remote_backend.tf
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.60.0
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.64.0
hooks:
- id: terraform_fmt
- id: terraform_tflint
Expand All @@ -12,7 +12,7 @@ repos:
- '--args=--only=terraform_documented_outputs'
- '--args=--only=terraform_documented_variables'
- '--args=--only=terraform_typed_variables'
- '--args=--only=terraform_module_pinned_source'
#- '--args=--only=terraform_module_pinned_source'
- '--args=--only=terraform_naming_convention'
- '--args=--only=terraform_required_providers'
- '--args=--only=terraform_standard_module_structure'
Expand Down
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<img src="https://img.shields.io/twitter/follow/varuntomar2019?style=social&logo=twitter"></a>
</p>

# Terraform module for [AWS Elasticache](https://registry.terraform.io/modules/tomarv2/elasticache/aws/latest)
## Terraform module for [AWS Elasticache](https://registry.terraform.io/modules/tomarv2/elasticache/aws/latest)

####

Expand All @@ -22,17 +22,17 @@
> :arrow_right: Terraform module for [Google Memorystore](https://registry.terraform.io/modules/tomarv2/memorystore/google/latest)

## Versions
### Versions

- Module tested for Terraform 1.0.1.
- AWS provider version [3.63](https://registry.terraform.io/providers/hashicorp/aws/latest)
- AWS provider version [3.74](https://registry.terraform.io/providers/hashicorp/aws/latest)
- `main` branch: Provider versions not pinned to keep up with Terraform releases
- `tags` releases: Tags are pinned with versions (use <a href="https://github.com/tomarv2/terraform-aws-elasticache/tags" alt="GitHub tag">
<img src="https://img.shields.io/github/v/tag/tomarv2/terraform-aws-elasticache" /></a> in your releases)

## Usage
### Usage

### Option 1:
#### Option 1:

```
terrafrom init
Expand All @@ -42,9 +42,9 @@ terraform destroy -var='teamid=tryme' -var='prjid=project1'
```
**Note:** With this option please take care of remote state storage

### Option 2:
#### Option 2:

#### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure):
##### Recommended method (stores remote state in S3 using `prjid` and `teamid` to create directory structure):

- Create python 3.8+ virtual environment
```
Expand Down Expand Up @@ -90,17 +90,13 @@ tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'
```

**NOTE:**

- Read more on [tfremote](https://github.com/tomarv2/tfremote)
---

**Note:** Read more on [tfremote](https://github.com/tomarv2/tfremote)
```
terraform {
required_version = ">= 1.0.1"
required_providers {
aws = {
version = "~> 3.63"
version = "~> 3.74"
}
}
}
Expand Down Expand Up @@ -135,18 +131,23 @@ module "security_group" {

Please refer to examples directory [link](examples) for references.

**Note:**

- For more information on redis: [link](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/cluster-create-determine-requirements.html#redis-cluster-configuration)

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.63 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 3.74 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.63 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 3.74 |

## Modules

Expand Down Expand Up @@ -198,7 +199,4 @@ Please refer to examples directory [link](examples) for references.
| <a name="output_aws_elasticache_parameter_group"></a> [aws\_elasticache\_parameter\_group](#output\_aws\_elasticache\_parameter\_group) | Elasticache Parameter Group |
| <a name="output_elasticache_cluster_address"></a> [elasticache\_cluster\_address](#output\_elasticache\_cluster\_address) | Elasticache Cluster address |
| <a name="output_elasticache_id"></a> [elasticache\_id](#output\_elasticache\_id) | Elasticache Id |

**Note:**

- For more information on redis: [link](https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/cluster-create-determine-requirements.html#redis-cluster-configuration)
<!-- END_TF_DOCS -->
2 changes: 1 addition & 1 deletion examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_version = ">= 1.0.1"
required_providers {
aws = {
version = "~> 3.63"
version = "~> 3.74"
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@ module "global" {
}

locals {
shared_tags = tomap(
{
"Name" = "${var.teamid}-${var.prjid}",
"team" = var.teamid,
"project" = var.prjid
}
)
account_id = data.aws_caller_identity.current.account_id
region = data.aws_region.current.name
}
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ output "elasticache_id" {
}

output "elasticache_cluster_address" {
value = aws_elasticache_cluster.default.*.cluster_address
value = aws_elasticache_cluster.default.*.cache_nodes.0.address
description = "Elasticache Cluster address"
}

Expand Down
2 changes: 1 addition & 1 deletion versions.tf → providers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_version = ">= 1.0.1"
required_providers {
aws = {
version = "~> 3.63"
version = "~> 3.74"
}
}
}
9 changes: 9 additions & 0 deletions tags.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
locals {
shared_tags = tomap(
{
"Name" = "${var.teamid}-${var.prjid}",
"Team" = var.teamid,
"Project" = var.prjid
}
)
}

0 comments on commit a34e3d9

Please sign in to comment.