Skip to content
Snippets Groups Projects
Commit 1ce0360f authored by Edouard DE BRYE's avatar Edouard DE BRYE
Browse files

Merge branch 'feature/add-ci-cd' into 'master'

Added gitlab-ci + restructured lambda files

See merge request edebrye/cloud-monitor!5
parents 99541fd6 e32ee3bb
No related branches found
No related tags found
No related merge requests found
image:
name: hashicorp/terraform:0.14.7
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
stages:
- Test and Lint
- Staging Plan
- Staging Apply
- Integration Test
- Production Plan
- Production Apply
- Destroy
Test and Lint:
stage: Test and Lint
script:
- echo "test to do"
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|production)$/ || $CI_COMMIT_BRANCH =~ /^(master|production)$/'
Validate Terraform:
stage: Test and Lint
script:
- cd deploy/
- terraform init -backend=false
- terraform validate
- terraform fmt -check
rules:
- if: '$CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^(master|production)$/ || $CI_COMMIT_BRANCH =~ /^(master|production)$/'
Staging Plan:
stage: Staging Plan
script:
- cd deploy/
- terraform init
- terraform workspace select staging || terraform workspace new staging
- terraform plan
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(master|production)$/'
Staging Apply:
stage: Staging Apply
script:
- cd deploy/
- terraform init
- terraform workspace select staging
- terraform apply -auto-approve
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(master|production)$/'
Integration Tests:
stage: Integration Test
script:
- echo "Call every Lambda via API Gateway"
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(master|production)$/'
Production Plan:
stage: Production Plan
script:
- cd deploy/
- terraform init
- terraform workspace select production || terraform workspace new production
- terraform plan
rules:
- if: '$CI_COMMIT_BRANCH == "production"'
Production Apply:
stage: Production Apply
script:
- cd deploy/
- terraform init
- terraform workspace select production
- terraform apply -auto-approve
rules:
- if: '$CI_COMMIT_BRANCH == "production"'
Staging Destroy:
stage: Destroy
script:
- cd deploy/
- terraform init
- terraform workspace select staging
- terraform destroy -auto-approve
rules:
- if: '$CI_COMMIT_BRANCH =~ /^(master|production)$/'
when: manual
Production Destroy:
stage: Destroy
script:
- cd deploy/
- terraform init
- terraform workspace select production
- terraform destroy -auto-approve
rules:
- if: '$CI_COMMIT_BRANCH == "production"'
when: manual
\ No newline at end of file
locals {
lambda_loc = "${path.module}/lambda"
files = toset([
for f in fileset("${local.lambda_loc}/src", "*.js") :
replace(f, ".js", "")
])
}
resource "aws_lambda_function" "test_lambda" {
......@@ -61,15 +65,8 @@ resource "aws_iam_role_policy_attachment" "lambda_insights" {
}
data "archive_file" "lambda_file" {
for_each = local.files
for_each = local.files
type = "zip"
output_path = "${local.lambda_loc}/${each.key}.zip"
source_file = "${local.lambda_loc}/hello/${each.key}.js"
output_path = "${local.lambda_loc}/zip/${each.key}.zip"
source_file = "${local.lambda_loc}/src/${each.key}.js"
}
locals{
files = toset([
for f in fileset("${local.lambda_loc}/hello", "*.js") :
replace(f, ".js", "")
])
}
\ No newline at end of file
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment