Skip to content

Commit

Permalink
Provisioning database using flag
Browse files Browse the repository at this point in the history
Provisioning database using flag
  • Loading branch information
ianuragsingh authored Aug 3, 2023
2 parents e78a9c7 + cd05552 commit 9f672a2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

## Modules

Expand All @@ -31,6 +31,7 @@

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_create_database"></a> [create\_database](#input\_create\_database) | Flag to create database or not | `bool` | `true` | no |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Defines whether this module should create resources | `bool` | `true` | no |
| <a name="input_invoke"></a> [invoke](#input\_invoke) | Defines whether lambda function should be invoked immediately after provisioning | `bool` | `true` | no |
| <a name="input_lambda_name"></a> [lambda\_name](#input\_lambda\_name) | value of lambda name | `string` | n/a | yes |
Expand Down
6 changes: 6 additions & 0 deletions lambda/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def provision_db_and_user(master_secrets_json, secret_json):
conn.autocommit = True
cursor = conn.cursor()

# Create database
create_database = os.environ['CREATE_DATABASE']
if create_database == "true":
sql = "CREATE DATABASE {};".format(database_name)
cursor.execute(sql)

# Create user
sql = "CREATE USER {} WITH PASSWORD '{}' CREATEDB;".format(
username, password)
Expand Down
1 change: 1 addition & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ module "provisoner_lambda" {
environment_variables = {
RDS_HOST = var.rds_endpoint
RDS_PORT = var.rds_port
CREATE_DATABASE = var.create_database ? "true" : "false"
DB_USER_SECRET_MANAGER_NAME = var.rds_user_secret_name
DB_MASTER_SECRET_MANAGER_NAME = var.rds_master_user_secret_name != null ? var.rds_master_user_secret_name : local.master_user_secret_name
}
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ variable "vpc_config" {
description = "VPC configuration for Lambda function"
}

variable "create_database" {
type = bool
default = true
description = "Flag to create database or not"
}

variable "invoke" {
type = bool
default = true
Expand Down
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 4.0"
version = ">= 5.0"
}
}
}

0 comments on commit 9f672a2

Please sign in to comment.