Skip to content

Commit

Permalink
Feat: 🚀 Added support for multi parameter (#10)
Browse files Browse the repository at this point in the history
* feat: add parameter for multi purpose usage in docDB

* feat: update readme workflow for shared action

* fix: add optional for apply method of parameter

* fix: add kms to basic example

* fix: add kms to instance

* fix: fall back

---------

Co-authored-by: Anmol Nagpal <anmol@clouddrove.com>
  • Loading branch information
nileshgadgi and anmolnagpal committed Feb 8, 2024
1 parent e28254b commit 0ed313d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 76 deletions.
51 changes: 6 additions & 45 deletions .github/workflows/readme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,12 @@ on:
push:
branches:
- master
paths-ignore:
- 'README.md'

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@v5
with:
python-version: '3.x'

- name: 'create readme'
uses: 'clouddrove/github-actions@9.0.3'
with:
actions_subcommand: 'readme'
github_token: '${{ secrets.GITHUB }}'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: 'pre-commit check errors'
uses: pre-commit/action@v3.0.0
continue-on-error: true

- name: 'pre-commit fix erros'
uses: pre-commit/action@v3.0.0
continue-on-error: true

- name: 'push readme'
uses: 'clouddrove/github-actions@9.0.3'
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()
uses: clouddrove/github-shared-workflows/.github/workflows/readme.yml@master
secrets:
TOKEN: ${{ secrets.GITHUB }}
SLACK_WEBHOOK_TERRAFORM: ${{ secrets.SLACK_WEBHOOK_TERRAFORM }}
8 changes: 7 additions & 1 deletion example/secured/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,17 @@ module "documentdb" {
skip_final_snapshot = var.skip_final_snapshot
storage_encrypted = var.storage_encrypted
kms_key_id = module.kms_key.key_arn
tls_enabled = var.tls_enabled
instance_class = var.instance_class
cluster_family = "docdb5.0"
cluster_size = var.cluster_size
deletion_protection = true
preferred_backup_window = "07:00-07:30"
ca_cert_identifier = "rds-ca-rsa2048-g1"
parameters = [
{
apply_method = "immediate"
name = "tls"
value = "enabled"
}
]
}
6 changes: 0 additions & 6 deletions example/secured/variable.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ variable "storage_encrypted" {
default = true
}

variable "tls_enabled" {
type = bool
default = true
description = "When true than cluster using TLS for communication."
}

variable "instance_class" {
type = string
default = "db.t3.medium"
Expand Down
42 changes: 25 additions & 17 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ resource "random_password" "master" {
special = false
}

##-----------------------------------------------------------------------------
## AWS Document DB cluster parameter Group.
##-----------------------------------------------------------------------------

resource "aws_docdb_cluster_parameter_group" "this" {
count = var.enable ? 1 : 0
name = "parameter-group-${var.database_name}"
description = "DB cluster parameter group."
family = var.cluster_family

dynamic "parameter" {
for_each = var.parameters
content {
apply_method = lookup(parameter.value, "apply_method", null)
name = parameter.value.name
value = parameter.value.value
}
}

tags = module.labels.tags
}

##-----------------------------------------------------------------------------
## AWS Document DB Cluster.
##-----------------------------------------------------------------------------
Expand All @@ -47,6 +69,8 @@ resource "aws_docdb_cluster" "this" {
engine_version = var.engine_version
enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
tags = module.labels.tags

depends_on = [aws_docdb_cluster_parameter_group.this]
}

##-----------------------------------------------------------------------------
Expand Down Expand Up @@ -74,20 +98,4 @@ resource "aws_docdb_subnet_group" "this" {
description = "Allowed subnets for DB cluster instances."
subnet_ids = var.subnet_list
tags = module.labels.tags
}

##-----------------------------------------------------------------------------
## AWS Document DB cluster parameter Group.
##-----------------------------------------------------------------------------

resource "aws_docdb_cluster_parameter_group" "this" {
count = var.enable ? 1 : 0
name = "parameter-group-${var.database_name}"
description = "DB cluster parameter group."
family = var.cluster_family
parameter {
name = "tls"
value = var.tls_enabled ? "enabled" : "disabled"
}
tags = module.labels.tags
}
}
18 changes: 11 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ variable "engine_version" {
variable "enabled_cloudwatch_logs_exports" {
type = list(string)
description = "List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery."
default = ["audit", "audit", "profiler"]
default = ["audit", "profiler"]
}

variable "instance_class" {
Expand All @@ -104,12 +104,6 @@ variable "cluster_size" {
description = "Number of DB instances to create in the cluster"
}

variable "tls_enabled" {
type = bool
default = false
description = "When true than cluster using TLS for communication."
}

variable "vpc_security_group_ids" {
type = set(string)
default = null
Expand All @@ -121,6 +115,16 @@ variable "ca_cert_identifier" {
description = "The identifier of the certificate authority (CA) certificate for the DB instance."
}

variable "parameters" {
type = list(object({
apply_method = optional(string)
name = string
value = string
}))
default = []
description = "A list of DocumentDB parameters to apply. Setting parameters to system default values may show a difference on imported resources."
}

##-----------------------------------------------------------------------------
## Labels variables
##-----------------------------------------------------------------------------
Expand Down

0 comments on commit 0ed313d

Please sign in to comment.