Skip to content

Commit 1617119

Browse files
committed
Update deploy
1 parent 9ac9562 commit 1617119

4 files changed

Lines changed: 25 additions & 139 deletions

File tree

Lines changed: 7 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,23 @@
11
version: 0.2
22
env:
33
exported-variables:
4-
- VALIDATION_OVERVIEW
5-
- TF_VALIDATE_OUTPUT
6-
- TF_FORMAT_OUTPUT
7-
- TF_CHECKOV_OUTPUT
8-
- TF_TFSEC_OUTPUT
9-
- PLAN_STATUS
4+
- ALL_PHASES_STATUS
5+
- TERRAFORM_CLOUD
106

117
phases:
128
install:
13-
runtime-versions:
14-
python: "3.7"
15-
golang: "1.14"
169
commands:
17-
- "curl -s -qL -o terraform.zip https://releases.hashicorp.com/terraform/$${TF_VERSION}/terraform_$${TF_VERSION}_linux_amd64.zip"
18-
- "unzip -o terraform.zip"
19-
- mv terraform /bin
20-
- rm terraform.zip
21-
- pip3 install checkov
22-
- go get -u github.com/tfsec/tfsec/cmd/tfsec
23-
- set echo off
24-
25-
echo "INFO : Pre-Validation Successful"
26-
- # -------------- END of PRE VALIDATION Steps ----------------
27-
- set echo on
10+
echo "[Install] : $EXPORT_PROJECT_NAME"
2811
pre_build:
2912
commands:
30-
- "echo ## VALIDATION : Starting ..."
31-
- "echo ## TERRAFORM INIT : Initialize the Terraform Enviornment"
32-
- "terraform init"
33-
- |
34-
# ---------- Terraform Validate ----------
35-
if [ "$${ENABLE_TFVALIDATE}" = "Y" ]
36-
then
37-
echo "## VALIDATION : Validating Terraform code ..."
38-
terraform validate
39-
fi
40-
tfValidateOutput=$?
41-
if [ "$$tfValidateOutput" -eq 1 ]
42-
then
43-
tfValidateOutput="FAILED"
44-
else
45-
tfValidateOutput="PASSED"
46-
fi
47-
export TF_VALIDATE_OUTPUT=$tfValidateOutput
48-
# ---------- Terraform Format ----------
49-
if [ "$${ENABLE_TFFORMAT}" = "Y" ]
50-
then
51-
echo "## VALIDATION : Formatting Terraform code ..."
52-
terraform fmt -recursive
53-
fi
54-
tfFormatOutput=$?
55-
if [ "$$tfFormatOutput" -eq 1 ]
56-
then
57-
tfFormatOutput="FAILED"
58-
else
59-
tfFormatOutput="PASSED"
60-
fi
61-
export TF_FORMAT_OUTPUT=$tfFormatOutput
62-
# ---------- Terraform Checkov ----------
63-
if [ "$${ENABLE_TFCHECKOV}" = "Y" ]
64-
then
65-
echo "## VALIDATION: Running checkov ..."
66-
checkov -s -d .
67-
fi
68-
tfCheckovOutput=$?
69-
if [ "$$tfCheckovOutput" -eq 1 ]
70-
then
71-
tfCheckovOutput="FAILED"
72-
else
73-
tfCheckovOutput="PASSED"
74-
fi
75-
export TF_CHECKOV_OUTPUT=$tfCheckovOutput
76-
# ---------- Terraform TFSEC ----------
77-
if [ "$${ENABLE_TFSEC}" = "Y" ]
78-
then
79-
echo "## VALIDATION: Running tfsec ...";
80-
tfsec .
81-
fi
82-
tfTfsecOutput=$?
83-
if [ "$$tfTfsecOutput" -eq 1 ]
84-
then
85-
tfTfsecOutput="FAILED"
86-
else
87-
tfTfsecOutput="PASSED"
88-
fi
89-
export TF_TFSEC_OUTPUT=$tfTfsecOutput
90-
echo "## VALIDATION Summary ##"
91-
echo "------------------------"
92-
echo "Terraform Validate: $${tfValidateOutput}"
93-
echo "Terraform Format: $${tfFormatOutput}"
94-
echo "Terraform checkov: $${tfCheckovOutput}"
95-
echo "Terraform tfsec: $${tfTfsecOutput}"
96-
echo "------------------------"
97-
# if SKIPVALIDATIONFAILURE is set as Y, then validation failures are skipped during execution
98-
if [ "$${SKIPVALIDATIONFAILURE}" = "Y" ]
99-
then
100-
echo "## VALIDATION: Skipping validation failure checks..."
101-
validation_failure=0
102-
VALIDATION_OVERVIEW=SKIPPED
103-
elif [ "$${tfValidateOutput}" = "PASSED" -a "$${tfFormatOutput}" = "PASSED" -a "$${tfCheckovOutput}" = "PASSED" -a "$${tfTfsecOutput}" = "PASSED" ]
104-
then
105-
echo "## VALIDATION: Checks Passed!!!"
106-
validation_failure=0
107-
export VALIDATION_OVERVIEW=PASSED
108-
else
109-
echo "## ERROR: Validation Failed"
110-
export VALIDATION_OVERVIEW=FAILED
111-
validation_failure=1
112-
fi
113-
if [ "$${validation_failure}" -eq 1 -a "$${SKIPVALIDATIONFAILURE}" != "Y" ]
114-
then
115-
exit 1
116-
fi
13+
- echo "[Pre Build] : $EXPORT_PROJECT_NAME"
11714
build:
11815
commands:
119-
- "echo ## TERRAFORM PLAN : Create the plan for the Infrastructure"
120-
- "terraform plan -out tfapply"
121-
- "plan_status=$$?"
122-
- |
123-
if [ "$${plan_status}" -eq 0 ]
124-
then
125-
export PLAN_STATUS=PASSED
126-
else
127-
export PLAN_STATUS=FAILED
128-
fi
16+
- echo "[Pre Build] : $EXPORT_PROJECT_NAME"
17+
- export ALL_PHASES_STATUS=PASSED
12918
post_build:
13019
commands:
131-
- echo "Cleaning up the infrastructure created in next step"
20+
- echo "[Post Build] : $${ALL_PHASES_STATUS}"
13221
artifacts:
13322
files:
13423
- '**/*'

deploy/main.tf

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ terraform {
1212
}
1313

1414
module "codebuild" {
15-
source = "../"
16-
build_image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
17-
build_spec_file = var.build_spec_file
18-
compute_type = "BUILD_GENERAL1_MEDIUM"
19-
environment = var.environment
20-
git_clone_depth = "1"
21-
git_repo = var.git_repo
22-
project_name = var.project_name
23-
codebuild_env_vars = var.codebuild_env_vars
24-
tags = merge(var.tags, module.repo_label.tags)
15+
source = "../"
16+
build_image = "aws/codebuild/amazonlinux2-x86_64-standard:3.0"
17+
build_spec_file = var.build_spec_file
18+
compute_type = "BUILD_GENERAL1_MEDIUM"
19+
environment = var.environment
20+
git_clone_depth = "1"
21+
http_git_clone_url = "https://github.com/aws-ia/terraform-modules-examples"
22+
project_name = var.project_name
23+
codebuild_env_vars = var.codebuild_env_vars
24+
create_role_and_policy = true
25+
tags = merge(var.tags, module.repo_label.tags)
2526
}
2627

2728
##########
@@ -33,9 +34,9 @@ module "repo_label" {
3334
version = "0.0.2"
3435
region = var.region
3536
namespace = "aws-ia"
36-
account = "test"
37-
env = "demo"
38-
name = "aws-ia-codebuild_module"
37+
account = "t"
38+
env = "d"
39+
name = "cb"
3940
delimiter = "-"
4041
tags = tomap({ propogate_at_launch = "true", "terraform" = "true" })
4142
}

deploy/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ output "codebuild_tags_all" {
1818
value = module.codebuild.codebuild_tags_all
1919
}
2020

21-
output "codebuild_role_arn" {
22-
description = "CodeBuild Role Arn"
23-
value = module.codebuild.codebuild_role_arn
24-
}
25-
2621
output "codebuild_project_name" {
2722
description = "CodeBuild Project Name"
2823
value = module.codebuild.codebuild_project_name

deploy/variable.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ variable "project_name" {
1313
default = ""
1414
}
1515

16-
variable "git_repo" {
17-
description = "Github repo "
16+
variable "http_git_clone_url" {
17+
description = "Enter: Git Clone URL"
18+
type = string
1819
default = "https://github.com/aws-ia/terraform-modules-examples"
1920
}
2021

@@ -35,7 +36,7 @@ variable "compute_type" {
3536

3637
variable "build_spec_file" {
3738
description = " build spec file name "
38-
default = "deploy/buildspecs/terraform_env.yml"
39+
default = "/buildspecs/terraform_env.yml"
3940
}
4041

4142
variable "tags" {

0 commit comments

Comments
 (0)