From 39f85fe2a4fd2439040f6ac7af07642d1daf966f Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 2 Nov 2021 12:25:01 -0500 Subject: [PATCH] added terraform config for aws single node deployment --- .gitlab/.gitlab-ci.yml | 34 ++++++++++++++++++++++++ .terraform/main.tf | 58 +++++++++++++++++++++++++++++++++++++++++ .terraform/server.yml | 5 ++++ .terraform/variables.tf | 10 +++++++ 4 files changed, 107 insertions(+) create mode 100644 .terraform/main.tf create mode 100644 .terraform/server.yml create mode 100644 .terraform/variables.tf diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index bb734ca27..599a8d65a 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -2,10 +2,12 @@ include: - template: Security/SAST.gitlab-ci.yml - template: Security/License-Scanning.gitlab-ci.yml - template: Security/Dependency-Scanning.gitlab-ci.yml + stages: - test - build + - deploy install lattice: stage: test @@ -137,3 +139,35 @@ build for darwin arm64: artifacts: paths: - featurebase_darwin_arm64 + +init terraform: + stage: deploy + image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest + before_script: + - cd .terraform + script: + - gitlab-terraform init + +validate terraform: + stage: deploy + image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest + script: + - gitlab-terraform validate + needs: + - job: init terraform + +plan terraform: + stage: deploy + image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest + script: + - gitlab-terraform plan + needs: + - job: validate terraform + +apply terraform: + stage: deploy + image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest + script: + - gitlab-terraform apply + needs: + - job: plan terraform \ No newline at end of file diff --git a/.terraform/main.tf b/.terraform/main.tf new file mode 100644 index 000000000..377853714 --- /dev/null +++ b/.terraform/main.tf @@ -0,0 +1,58 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.27" + } + } + + required_version = ">= 1.0.0" +} + +provider "aws" { + region = "us-east-2" +} + +resource "aws_security_group" "server_sg" { + name = "Load Balancer Security Group" + + ingress { + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + from_port = 0 + to_port = 0 + protocol = -1 + cidr_blocks = ["0.0.0.0/0"] + } +} + +data "cloudinit_config" "server_config" { + gzip = true + base64_encode = true + part { + content_type = "text/cloud-config" + content = templatefile("${path.module}/server.yml", { + header : aws_security_group.server_sg.id + }) + } +} + +resource "aws_instance" "server_instance1" { + ami = var.ami_linux_amd + instance_type = "t2.micro" + + key_name = "souhaila-rsa" + + vpc_security_group_ids = [aws_security_group.server_sg.id] + user_data = data.cloudinit_config.server_config.rendered + associate_public_ip_address = true + + tags = { + Name = var.instance_name + } +} \ No newline at end of file diff --git a/.terraform/server.yml b/.terraform/server.yml new file mode 100644 index 000000000..5c7571b83 --- /dev/null +++ b/.terraform/server.yml @@ -0,0 +1,5 @@ +#cloud-config +runcmd: + - sudo yum update + - sudo yum install postgresql14 + - sudo yum install golang1.16 \ No newline at end of file diff --git a/.terraform/variables.tf b/.terraform/variables.tf new file mode 100644 index 000000000..2d1859c98 --- /dev/null +++ b/.terraform/variables.tf @@ -0,0 +1,10 @@ +variable "instance_name" { + description = "Value of the Name tag for the EC2 instance" + type = string + default = "single-node-deployment-1" +} + +variable "ami_linux_amd" { + type = string + default = "ami-0f19d220602031aed" +}