Skip to content

Instantly share code, notes, and snippets.

View hendrixroa's full-sized avatar
🏠
Working from home

Hendrix Roa hendrixroa

🏠
Working from home
View GitHub Profile
@hendrixroa
hendrixroa / module_cron_task_ecs.tf
Last active May 4, 2023 16:30
Module terraform definition to create a cron task launched by a cloudwatch scheduler event
module "noiselesstech_cron" {
source = "hendrixroa/cron-ecs-task/aws"
app = "noiselesstech"
# Compute resources
cpu_unit = 1024
memory = 2048
# Cron
@hendrixroa
hendrixroa / aws_ecs_cluster.tf
Last active May 4, 2023 16:32
AWS ECS cluster using fargate only
resource "aws_ecs_cluster" "main" {
name = var.app_name
capacity_providers = ["FARGATE"]
}
@hendrixroa
hendrixroa / cloudwatch_event_rule_5_minutes.tf
Created May 4, 2023 01:01
Cloudwatch event rule for run every 5 minutes
resource "aws_cloudwatch_event_rule" "cron_five_minutes" {
name = "cron_rate_5"
description = "Schedule trigger for run every 5 minutes"
schedule_expression = "rate(5 minutes)"
is_enabled = true
}
@hendrixroa
hendrixroa / aws_ec2_security_group.tf
Created May 3, 2023 01:31
AWS EC2 Security group using custom VPC
resource "aws_security_group" "sample" {
name = "sample"
description = "security group"
vpc_id = module.vpc.vpc_id
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
@hendrixroa
hendrixroa / spring_boot_sample_comman_line.java
Created May 3, 2023 01:00
Sample in spring boot to display and use a timer
package com.blog.noiselesstech;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.util.concurrent.TimeUnit;
@hendrixroa
hendrixroa / aws_vpc_module.tf
Created May 3, 2023 00:36
AWS VPC Ready to use module snippet
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "NoiselessVPC"
cidr = "10.0.0.0/16"
azs = ["${var.region}a", "${var.region}b", "${var.region}c"]
private_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
public_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
}
@hendrixroa
hendrixroa / aws_ecs _events_task.tf
Last active May 4, 2023 16:33
AWS Clouwatch event to perform an ECS Task
resource "aws_cloudwatch_event_target" "main" {
target_id = "${var.app}-target"
arn = var.ecs_cluster
rule = var.event_rule
role_arn = var.ecs_event_role
ecs_target {
task_count = 1
task_definition_arn = aws_ecs_task_definition.main.arn
launch_type = "FARGATE"
@hendrixroa
hendrixroa / aws_iam_ecs_events.tf
Last active May 4, 2023 16:34
AWS IAM role and policy to perform ECS events task
resource "aws_iam_role" "ecs_events" {
name = "ecs_events"
assume_role_policy = <<DOC
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
@hendrixroa
hendrixroa / aws_ecs_task_execution.tf
Last active May 4, 2023 16:34
AWS IAM roles and policies to perform task in ECS
resource "aws_iam_role" "ecs_task_execution" {
name = "noiselesstech_task_execution_role"
assume_role_policy = <<DOC
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
@hendrixroa
hendrixroa / aws_ecs_task_definition.tf
Last active May 2, 2023 22:38
AWS ECS Task definition
resource "aws_ecs_task_definition" "main" {
family = "${var.app}-service"
requires_compatibilities = ["FARGATE"]
network_mode = "awsvpc"
execution_role_arn = var.execution_role_arn
cpu = var.cpu_unit
memory = var.memory
container_definitions = data.template_file.main.rendered
}