Code Monkey home page Code Monkey logo

terraform-aws-codecommit-sqs's Introduction

Terraform Module For CodeCommit + SQS

CodeCommit repos created using this terraform module is compatible with the Jenkins AWS CodeCommit Trigger Plugin, i.e., changes to the git repo automatically triggers the plugin.

This module is available on the Terraform Registry.

Sample Usage

variable "aws-account-id" {
  default = "my-aws-account-id"
}

variable "aws-region" {
  default = "my-aws-region"
}

variable "sns-topic-prefix" {
  default = "codecommit-"
}

variable "sns-topic-suffix" {
  default = "-topic"
}

provider "aws" {
  region = "${var.aws-region}"
  alias = "default"
}

resource "aws_sqs_queue" "main" {
  name = "codecommit-notifications-queue"
  delay_seconds = 90
  max_message_size = 2048
  message_retention_seconds = 86400
  receive_wait_time_seconds = 10
}

resource "aws_sqs_queue_policy" "sns" {
  queue_url = "${aws_sqs_queue.main.id}"
  policy = "${data.aws_iam_policy_document.sns-sqs-policy.json}"
}

data "aws_iam_policy_document" "sns-sqs-policy" {
  policy_id = "arn:aws:sqs:${var.aws-region}:${var.aws-account-id}:testing/SQSDefaultPolicy"

  statement {
    sid = "SubscribeToSNS"
    effect = "Allow"
    principals {
      type = "AWS"
      identifiers = [ "*" ]
    }
    actions = [ "SQS:SendMessage" ]
    resources = [ "${aws_sqs_queue.main.arn}" ]
    condition {
      test = "ArnLike"
      variable = "aws:SourceArn"
      values = [ "arn:aws:sns:us-east-1:${var.aws-account-id}:${var.sns-topic-prefix}*${var.sns-topic-suffix}" ]
    }
  }
}

module "cc-example_repo" {
  source = "riboseinc/codecommit-sqs/aws"
  reponame = "example-repo"
  aws-account-id = "${var.aws-account-id}"
  sqs-arn = "${aws_sqs_queue.main.arn}"
  sqs-id = "${aws_sqs_queue.main.id}"
  topic-prefix = "${var.sns-topic-prefix}"
  topic-suffix = "${var.sns-topic-suffix}"
  # email-sns-arn = "${aws_sns_topic.codecommit-email.arn}"

  providers = {
    aws = "aws.default"
  }
}

output "cc-example_repo-cc-arn" {
  value = "${module.cc-example_repo.cc-arn}"
}
output "cc-example_repo-sns-name" {
  value = "${module.cc-example_repo.sns-name}"
}
output "cc-example_repo-sns-arn" {
  value = "${module.cc-example_repo.sns-arn}"
}

Enabling With An Email Notification

Some people prefer receiving an email on every commit.

This is how you set it up.

resource "aws_sns_topic" "codecommit-email" {
  name = "codecommit-email-notifications"
  display_name = "CodeCommit notifications"
}

resource "aws_sns_topic_policy" "codecommit-email-sns-policy" {
  arn = "${aws_sns_topic.codecommit-email.arn}"
  policy = "${data.aws_iam_policy_document.codecommit-email-sns-policy.json}"
}

data "aws_iam_policy_document" "codecommit-email-sns-policy" {
  statement {
    sid = "AllowSubscription"
    effect = "Allow"
    principals {
      type = "AWS"
      identifiers = [ "*" ]
    }
    actions = [
      "SNS:Publish",
      "SNS:RemovePermission",
      "SNS:SetTopicAttributes",
      "SNS:DeleteTopic",
      "SNS:ListSubscriptionsByTopic",
      "SNS:GetTopicAttributes",
      "SNS:Receive",
      "SNS:AddPermission",
      "SNS:Subscribe"
    ]
    resources = [ "${aws_sns_topic.codecommit-email.arn}" ]
    condition {
      test = "StringEquals"
      variable = "AWS:SourceOwner"
      values = [ "${var.aws-account-id}" ]
    }
  }

}

output "email-sns-arn" {
  value = "${aws_sns_topic.codecommit-email.arn}"
}

output "email-sns-name" {
  value = "${aws_sns_topic.codecommit-email.name}"
}

# Link it with this module
module "cc-example_repo" {
  source = "riboseinc/codecommit-sqs/aws"
  reponame = "example-repo"
  aws-account-id = "${var.aws-account-id}"
  email-sns-arn = "${aws_sns_topic.codecommit-email.arn}"
  topic-prefix = "${var.sns-topic-prefix}"
  topic-suffix = "${var.sns-topic-suffix}"
  sqs-arn = "${aws_sqs_queue.main.arn}"
  sqs-id = "${aws_sqs_queue.main.id}"

  providers = {
    aws = "aws.default"
  }
}

terraform-aws-codecommit-sqs's People

Contributors

jseiser avatar ronaldtse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

terraform-aws-codecommit-sqs's Issues

email-sns-arn is required

`Upgrading modules...

  • module.cicd_mgmt
    Found version 1.1.1 of riboseinc/codecommit-sqs/aws on registry.terraform.io
    Updating source "riboseinc/codecommit-sqs/aws"

Initializing the backend...

Error: module "cicd_mgmt": missing required argument "email-sns-arn"
`

Your README makes it look like email-sns-arn is not required, but it is.

trigger { name = "email" events = ["all"] destination_arn = "${var.email-sns-arn}" }

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.