replace terraform with awscli for integration test

This commit is contained in:
Souhaila Noor 2021-11-04 08:57:10 -05:00
parent a8d3d1c4d4
commit c29dcddca6
4 changed files with 21 additions and 117 deletions

View file

@ -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
- 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)

0
molecular-terraform/server.yml → .gitlab/server.yml Normal file → Executable file
View file

View file

@ -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
}
}

View file

@ -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"
}