nitinda / terraform-module-aws-cloudwatch-events-target

Terraform Module for AWS CloudWatch Event Target

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Terraform Module: terraform-module-aws-cloudwatch-events-target

General

This module can be used to deploy a CloudWatch Event Target


Prerequisites

This module needs Terraform 0.12.18 or newer. You can download the latest Terraform version from here.


Features

Below are the resources that are launched by this module

  • CloudWatch Event Target

Usage

Using this repo

To use this module, add the following call to your code:

  • Exmaple Target : CodeBuild
module "<layer>_cloudwatch_event_target_<AccountID>" {
  source = "git::https://github.com/nitinda/terraform-module-aws-cloudwatch-events-target.git?ref=master"

  providers = {
    aws = aws.services
  }
  
  arn       = "arn:aws:codebuild:eu-central-1:${var.account_id}:project/code-build-ami-builder"
  rule      = "arn:aws:events:eu-central-1:${var.account_id}:rule/event_rule"
  role_arn  = "arn:aws:iam::${var.account_id}:role/service-role/iam-role-ami-builder-cloudwatch-events"
  target_id = "target-id-code-build-ami-builder"
}
  • Exmaple Target : ECS
module "<layer>_cloudwatch_event_target_<AccountID>" {
  source = "git::https://github.com/nitinda/terraform-module-aws-cloudwatch-events-target.git?ref=master"

  providers = {
    aws = aws.services
  }
  
  arn        = "arn:aws:ecs:eu-central-1:${var.account_id}:cluster/ecs-services"
  rule       = "arn:aws:events:eu-central-1:${var.account_id}:rule/event_rule"
  role_arn   = "arn:aws:iam::${var.account_id}:role/service-role/iam-role-ami-builder-cloudwatch-events"
  target_id  = "target-id-ecs"
  ecs_target = {
    task_count          = 1
    task_definition_arn = "arn:aws:ecs:eu-central-1:${var.account_id}:task-definition/ecs-task-definition:51"
  }
}
  • Exmaple Target : RUN Command
module "<layer>_cloudwatch_event_target_<AccountID>" {
  source = "git::https://github.com/nitinda/terraform-module-aws-cloudwatch-events-target.git?ref=master"

  providers = {
    aws = aws.services
  }
  
  arn                 = "arn:aws:ssm:${var.region}::document/AWS-RunShellScript"
  rule                = "arn:aws:events:eu-central-1:${var.account_id}:rule/event_rule"
  role_arn            = "arn:aws:iam::${var.account_id}:role/service-role/iam-role-ami-builder-cloudwatch-events"
  target_id           = "target-id-run-command"
  input               = "{\"commands\":[\"halt\"]}"
  run_command_targets = {
    key    = "tag:Terminate"
    values = ["midnight"]
  }
}

Inputs

The variables required in order for the module to be successfully called from the deployment repository are the following:

Variable Description Type Argument Status
target_id The unique target assignment ID string Required
rule The name of the rule you want to add targets to string Required
arn The Amazon Resource Name (ARN) associated of the target string Required
role_arn The ARN associated with the role that is used for target invocation string Required
input Valid JSON text passed to the target string Optional
run_command_targets Parameters used when you are using the rule to invoke Amazon EC2 Run Command any Optional
ecs_target Parameters used when you are using the rule to invoke Amazon ECS Task any Optional

Outputs

General

This module has the following outputs:

  • None

Usage

In order for the variables to be accessed at module level please use the syntax below:

module.<module_name>.<output_variable_name>

If an output variable needs to be exposed on root level in order to be accessed through terraform state file follow the steps below:

  • Include the syntax above in the layer outputs.tf terraform file.
  • The output variable is able to be accessed through terraform state file using the syntax below:
"${data.terraform_remote_state.<layer_name>.<output_variable_name>}"

Known Issues / Limitations

Planned changes

  • None

Authors

Deployed and managed by Nitin Das

About

Terraform Module for AWS CloudWatch Event Target

License:MIT License


Languages

Language:HCL 100.0%