Skip to content

Instantly share code, notes, and snippets.

View madagra's full-sized avatar

Mario Dagrada madagra

View GitHub Profile
resource "aws_lb_target_group" "pypi_tg" {
name = "pypi-tg"
port = 8080
protocol = "HTTP"
vpc_id = var.vpc_id
}
resource "aws_lb_target_group_attachment" "pypi_tg_attachment" {
target_group_arn = aws_lb_target_group.pypi_tg[0].arn
target_id = aws_instance.pypi.id
module "acm" {
source = "terraform-aws-modules/acm/aws"
domain_name = var.domain_name
zone_id = aws_route53_zone.this.zone_id
wait_for_validation = true
tags = {
#cloud-config
repo_update: true
repo_upgrade: all
write_files:
- path: /opt/run_pypi_server.sh
content: |
#!/usr/bin/env bash
sudo yum update -y
data "aws_ssm_parameter" "ec2_ami" {
name = "/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2"
}
resource "aws_instance" "pypi" {
ami = data.aws_ssm_parameter.ec2_ami.value
instance_type = "t3.nano"
user_data = data.template_file.cloud-init.rendered
key_name = "my-keypair"
@madagra
madagra / pypi_server_init_template.tf
Created January 10, 2021 12:59
Cloud init template for private PyPi repo on AWS
data "template_cloudinit_config" "config" {
gzip = false
base64_encode = true
part {
content_type = "text/x-shellscript"
content = <<EOT
#!/bin/bash
sudo mkdir -p /opt/pypi_server
resource "aws_route53_zone" "this" {
name = var.domain_name
}
module "acm" {
source = "terraform-aws-modules/acm/aws"
domain_name = var.domain_name
zone_id = aws_route53_zone.this.zone_id
data "aws_availability_zones" "available" {
state = "available"
}
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 2.48.0"
name = "example_vpc"
cidr = "10.0.0.0/16"
module "sample_app" {
source = "github.com/madagra/terraform-aws-single-task-service"
ecs_cluster = aws_ecs_cluster._.id
task_name = "sample_app"
container_image = "mongo:latest"
task_exec_role = aws_iam_role.ecs_execution.arn
vpc_id = module.vpc.vpc_id
variable "cluster_name" {
description = "The ECS cluster to start the instances in"
type = string
default = "qubec-cluster"
}
module "ecs_cluster" {
source = "github.com/jetbrains-infra/terraform-aws-ecs-cluster?ref=v0.4.8"
cluster_name = var.cluster_name
spot = true
#!/bin/bash
# Publish a container to a given repository in the AWS ECR service
# Use the --help option to see it usage
set -e
AWS_PROFILE="default"
CLUSTER_NAME="qubec-cluster"
UPDATE_SRV=0