From c29dcddca6846e205b15d59c78afe8bdf5f7c0f5 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Thu, 4 Nov 2021 08:57:10 -0500 Subject: [PATCH] replace terraform with awscli for integration test --- .gitlab/.gitlab-ci.yml | 70 +++++++-------------- {molecular-terraform => .gitlab}/server.yml | 0 molecular-terraform/main.tf | 58 ----------------- molecular-terraform/variables.tf | 10 --- 4 files changed, 21 insertions(+), 117 deletions(-) rename {molecular-terraform => .gitlab}/server.yml (100%) mode change 100644 => 100755 delete mode 100644 molecular-terraform/main.tf delete mode 100644 molecular-terraform/variables.tf diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 68be7fb55..f12c60249 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -6,7 +6,7 @@ include: stages: - test - build - - deploy + - integration install lattice: stage: test @@ -139,56 +139,28 @@ build for darwin arm64: paths: - featurebase_darwin_arm64 -init terraform: - stage: deploy - image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest +deploy ec2 instance: + stage: integration + image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest + variables: + AMI: "" + INSTANCE: "t2_micro" + SECURITY_GROUP: "" + SUBNET_ID: "" + SSH_KEY: "" + PUBLIC_IP: "" before_script: - - rm -rf .terraform - - cd molecular-terraform + - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID + - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY + - aws configure set region "us-east-2" + - export AWS_PROFILE=gitlab-cicd script: - - gitlab-terraform init - cache: - paths: - - .terraform + - AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile gitlab-cicd) -validate terraform: - stage: deploy - image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest - before_script: - - cd molecular-terraform - script: - - gitlab-terraform validate - needs: - - job: init terraform - cache: - paths: - - .terraform + - SECURITY_GROUP=$(aws ec2 describe-security-groups --filter Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 --query 'SecurityGroups[*].[GroupId]' --output text --profile gitlab-cicd) -plan terraform: - stage: deploy - image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest - before_script: - - cd molecular-terraform - script: - - gitlab-terraform plan -out=plan.tfplan - needs: - - job: validate terraform - cache: - paths: - - .terraform - artifacts: - paths: - - plan.tfplan + - SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile gitlab-cicd) -apply terraform: - stage: deploy - image: registry.gitlab.com/gitlab-org/terraform-images/stable:latest - before_script: - - cd molecular-terraform - script: - - gitlab-terraform apply - needs: - - job: plan terraform - cache: - paths: - - .terraform \ No newline at end of file + - aws ec2 run-instances --image-id $AMI --count 1 --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID —user-data file://.gitlab/server.yml + + - PUBLIC_IP=$(aws ec2 describe-instances --filters 'Name=tag:Name, Values=Single_Node_Deployment' 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile gitlab-cicd) \ No newline at end of file diff --git a/molecular-terraform/server.yml b/.gitlab/server.yml old mode 100644 new mode 100755 similarity index 100% rename from molecular-terraform/server.yml rename to .gitlab/server.yml diff --git a/molecular-terraform/main.tf b/molecular-terraform/main.tf deleted file mode 100644 index 377853714..000000000 --- a/molecular-terraform/main.tf +++ /dev/null @@ -1,58 +0,0 @@ -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/molecular-terraform/variables.tf b/molecular-terraform/variables.tf deleted file mode 100644 index 2d1859c98..000000000 --- a/molecular-terraform/variables.tf +++ /dev/null @@ -1,10 +0,0 @@ -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" -}