Giter Club home page Giter Club logo

terraform-aws-postgresql-user-creation's Introduction

terraform-postgresql-user-creation

Auto create PostgresSQL user

Terraform versions

  • Terraform >= 0.13
  • AWS provider >= 3.20

Overview

  • Architecture diagram Architecture

  • Sequence diagram Workflow

  1. The module must execute after RDS create successfull
  2. If the user was created in the past, the lambda will detect and skip the creation process.

Usage

resource "aws_security_group" "lambda" {
  vpc_id = var.vpc_id

  tags   = merge(var.tags, {
    Name        = "${var.project}-${terraform.workspace}-${var.name}-lambda"
    Environment = "${var.project}-${terraform.workspace}"
  })
}

resource "aws_security_group_rule" "to_rds" {
  security_group_id        = aws_security_group.lambda.id
  type                     = "egress"
  protocol                 = "tcp"
  from_port                = 5432
  to_port                  = 5432
  source_security_group_id = aws_security_group.rds.id
}

resource "aws_security_group_rule" "to_ssm" {
  security_group_id        = aws_security_group.lambda.id
  type                     = "egress"
  protocol                 = "tcp"
  from_port                = 443
  to_port                  = 443
  cidr_blocks              = ["0.0.0.0/0"]
}

module "rds_account_creation" {
  source              = "git::https://github.com/KKStream/terraform-aws-postgresql-user-creation"
  project             = var.project
  name                = var.name
  db_endpoint         = var.rds.internal_domain_name
  db_port             = local.rds_port
  db_name             = local.rds_db_name

  db_master_username  = local.rds_master_username
  db_master_password  = local.rds_master_password
  db_new_user_name    = local.rds_airflow_username

  vpc_id              = var.vpc_id
  subnet_ids          = var.rds_subnet_ids
  security_group_ids  = [aws_security_group.lambda.id]
  package_bucket_name = "package-bucket-name"

  depends_on = [aws_security_group.lambda, aws_rds_cluster.rds]
}

Inputs

Name Description Type Default Required
project project for current app string no yes
name name for current app string no yes
vpc_id The VPC ID for the ECS Cluster string no yes
subnet_ids Subnet IDs for Lambda list(string) no yes
security_group_ids Security groups for Lambda list(string) no yes
db_endpoint Database endpoint string no yes
db_name Database name string no yes
db_port The port for the database number 5432 no
db_master_username The user name of the database master string no yes
db_master_password The password of the database master string no yes
db_new_user_name The user of the database, this user can login string no yes
package_bucket_name The s3 package bucket for storing lambda package string no yes
invocation_failure_target_arn SNS arn for deployment failure. Use for database user creation failure string "" no
tags A map of tags to add to resources, default use Name & Environment tags. map(string) {} no

Outputs

Name Description
user_sm_arn where the username and password of the database user stored in
master_sm_arn where the username and password of the database master stored in

terraform-aws-postgresql-user-creation's People

Contributors

matrix0415 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.