Skip to content

Commit 50d226e

Browse files
authored
EKS Fix (#27)
* Typos in paths * Testing change in provider config * EKS split * Fixing some deps * Fix in code generation * Fixing outputs * Fixing Bitops Execution if nothing is needed
1 parent 220afea commit 50d226e

17 files changed

+445
-79
lines changed

action.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -572,5 +572,5 @@ runs:
572572
name: Storing code - Terraform
573573
retention-days: 5
574574
path: |
575-
${{ github.action_path }}/operations/generated_code
576-
!${{ github.action_path }}/operations/generated_code/**/ghs.env
575+
${{ github.action_path }}/operations/deployment
576+
!${{ github.action_path }}/operations/deployment/**/ghs.env

operations/_scripts/deploy/deploy.sh

+14-7
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export LB_LOGS_BUCKET="$(/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/gener
5656
# Generate bitops incoming repos config if any
5757
/bin/bash $GITHUB_ACTION_PATH/operations/_scripts/generate/generate_bitops_incoming.sh
5858

59+
60+
if [ ! -s "$GITHUB_ACTION_PATH/operations/deployment/bitops.config.yaml" ]; then
61+
echo "There is nothing to be created or destroyed. Exiting."
62+
exit 0
63+
fi
64+
5965
# Generate bitops incoming repos config
6066
if [ -n "$GH_ACTION_REPO" ] && [ -n "$BITOPS_EXTRA_ENV_VARS_FILE" ]; then
6167
if [ -s $GH_ACTION_REPO/$BITOPS_EXTRA_ENV_VARS_FILE ]; then
@@ -87,19 +93,20 @@ if [ -s "$GITHUB_WORKSPACE/$ENV_REPO" ] && [ -n "$ENV_REPO" ]; then
8793
cp "$GITHUB_WORKSPACE/$ENV_REPO" "${GITHUB_ACTION_PATH}/operations/deployment/env-files/repo.env"
8894
fi
8995

90-
cp -r "$GITHUB_ACTION_PATH/operations" /opt/bitops_deployment/generated_code
91-
92-
if [[ $(alpha_only "$BITOPS_SKIP_RUN") == true ]]; then
93-
echo "BitOps skip run is set to true. Reached end of the line."
94-
exit 0
95-
fi
96-
9796
# Bypass all the 'BITOPS_' ENV vars to docker
9897
BITOPS_EXTRA_ENV_VARS=""
9998
for i in $(env | grep BITOPS_); do
10099
BITOPS_EXTRA_ENV_VARS="${BITOPS_EXTRA_ENV_VARS} -e ${i}"
101100
done
102101

102+
if [[ $(alpha_only "$BITOPS_CODE_ONLY") == "true" ]]; then
103+
exit 0
104+
fi
105+
106+
if [[ $(alpha_only "$BITOPS_SKIP_RUN") == true ]]; then
107+
echo "BitOps skip run is set to true. Reached end of the line."
108+
exit 0
109+
fi
103110

104111
echo "::group::BitOps Excecution"
105112
echo "Running BitOps for env: $BITOPS_ENVIRONMENT"

operations/_scripts/generate/generate_bitops_config.sh

+33-8
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ targets="$targets
8181
targets_attribute="$targets_attribute $targets"
8282

8383
create_bitops_terraform_config aws $AWS_EC2_INSTANCE_CREATE targets
84+
create_bitops_terraform_config eks $AWS_EKS_CREATE
85+
8486

8587
#Will add the user_data file into the EC2 Terraform folder
8688
if [[ $(alpha_only "$AWS_EC2_INSTANCE_CREATE") == true ]]; then
@@ -93,7 +95,7 @@ fi
9395
if [[ $(alpha_only "$AWS_EKS_CREATE") == true ]]; then
9496
if [ -s "$GITHUB_WORKSPACE/$AWS_EKS_INSTANCE_USER_DATA_FILE" ] && [ -f "$GITHUB_WORKSPACE/$AWS_EKS_INSTANCE_USER_DATA_FILE" ]; then
9597
echo "Moving $AWS_EKS_INSTANCE_USER_DATA_FILE to be used by Terraform during EKS Nodes creation"
96-
mv "$GITHUB_WORKSPACE/$AWS_EKS_INSTANCE_USER_DATA_FILE" "$GITHUB_ACTION_PATH/operations/deployment/terraform/aws/aws_eks_incoming_user_data_script.sh"
98+
mv "$GITHUB_WORKSPACE/$AWS_EKS_INSTANCE_USER_DATA_FILE" "$GITHUB_ACTION_PATH/operations/deployment/terraform/eks/aws_eks_incoming_user_data_script.sh"
9799
fi
98100
fi
99101
# Below we will be creating the config file, one for the action itself, other to store as an artifact after.
@@ -103,17 +105,37 @@ mkdir -p "${GITHUB_ACTION_PATH}/operations/generated_code"
103105
# BitOps Deployment Config file
104106
BITOPS_DEPLOY_FILE="${GITHUB_ACTION_PATH}/operations/deployment/bitops.config.yaml"
105107
# BitOps Code Config File
106-
BITOPS_CODE_FILE="${GITHUB_ACTION_PATH}/operations/generated_code/bitops.config.yaml"
108+
##BITOPS_CODE_FILE="${GITHUB_ACTION_PATH}/operations/generated_code/bitops.config.yaml"
107109
# BitOps Temp file
108110
BITOPS_CONFIG_TEMP="/tmp/bitops.config.yaml"
109111

110112
# Global Bitops Config
111113
echo -en "
112114
bitops:
113115
deployments:
114-
" > $BITOPS_CONFIG_TEMP
115-
116-
add_terraform_module aws
116+
" > $BITOPS_DEPLOY_FILE
117+
118+
# BitOps Config Temp file
119+
# Terraform - Generate infra
120+
# Will check if there is a tf-state file to work with. If so, will create a destroy step.
121+
if [[ $(alpha_only "$TF_STACK_DESTROY") == true ]]; then
122+
if check_statefile aws aws; then
123+
add_terraform_module aws
124+
fi
125+
else
126+
if [[ $(alpha_only "$AWS_EC2_INSTANCE_CREATE") == true ]]; then
127+
add_terraform_module aws
128+
fi
129+
fi
130+
if [[ $(alpha_only "$AWS_EKS_CREATE") != true ]]; then
131+
if check_statefile aws eks; then
132+
add_terraform_module eks
133+
fi
134+
else
135+
if [[ $(alpha_only "$AWS_EKS_CREATE") == true ]]; then
136+
add_terraform_module eks
137+
fi
138+
fi
117139

118140
# Ansible Code part
119141

@@ -140,9 +162,12 @@ add_terraform_module aws
140162

141163
# Helm part
142164

143-
cp $BITOPS_CONFIG_TEMP $BITOPS_DEPLOY_FILE
144-
cp $BITOPS_CONFIG_TEMP $BITOPS_CODE_FILE
145-
rm $BITOPS_CONFIG_TEMP
165+
if [ ! -s "$BITOPS_CONFIG_TEMP" ]; then
166+
rm $BITOPS_DEPLOY_FILE
167+
else
168+
cat $BITOPS_CONFIG_TEMP >> $BITOPS_DEPLOY_FILE
169+
rm $BITOPS_CONFIG_TEMP
170+
fi
146171

147172
echo "Done with generate_bitops_config.sh"
148173
exit 0

operations/_scripts/generate/generate_provider.sh

+9-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ terraform {
1717
source = \"hashicorp/random\"
1818
version = \">= 2.2\"
1919
}
20+
kubernetes = {
21+
source = \"hashicorp/kubernetes\"
22+
version = \">= 2.22\"
23+
}
2024
}
2125
2226
backend \"s3\" {
2327
region = \"${AWS_DEFAULT_REGION}\"
2428
bucket = \"${TF_STATE_BUCKET}\"
25-
key = \"tf-state\"
29+
key = \"tf-state-$1\"
2630
encrypt = true #AES-256encryption
2731
}
2832
}
@@ -33,9 +37,11 @@ provider \"aws\" {
3337
tags = local.default_tags
3438
}
3539
}
36-
" > "${GITHUB_ACTION_PATH}/operations/deployment/terraform/aws/bitovi_provider.tf"
40+
41+
" > "${GITHUB_ACTION_PATH}/operations/deployment/terraform/$1/bitovi_provider.tf"
3742
}
3843

39-
generate_provider_aws
44+
generate_provider_aws aws
45+
generate_provider_aws eks
4046

4147
echo "Done with generate_provider.sh"

operations/_scripts/generate/generate_vars_terraform.sh

+40
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,46 @@ $app_install_root
351351
352352
" > "${GITHUB_ACTION_PATH}/operations/deployment/terraform/aws/terraform.tfvars"
353353

354+
355+
# -------------------------------------------------- #
356+
echo "
357+
#-- AWS --#
358+
$aws_resource_identifier
359+
$aws_resource_identifier_supershort
360+
$aws_additional_tags
361+
362+
#-- EKS --#
363+
$aws_eks_create
364+
$aws_eks_region
365+
$aws_eks_security_group_name_master
366+
$aws_eks_security_group_name_worker
367+
$aws_eks_environment
368+
$aws_eks_stackname
369+
$aws_eks_cidr_block
370+
$aws_eks_workstation_cidr
371+
$aws_eks_availability_zones
372+
$aws_eks_private_subnets
373+
$aws_eks_public_subnets
374+
$aws_eks_cluster_name
375+
$aws_eks_cluster_log_types
376+
$aws_eks_cluster_version
377+
$aws_eks_instance_type
378+
$aws_eks_instance_ami_id
379+
$aws_eks_instance_user_data_file
380+
$aws_eks_ec2_key_pair
381+
$aws_eks_store_keypair_sm
382+
$aws_eks_desired_capacity
383+
$aws_eks_max_size
384+
$aws_eks_min_size
385+
386+
#-- Application --#
387+
$ops_repo_environment
388+
$app_org_name
389+
$app_repo_name
390+
$app_branch_name
391+
392+
" > "${GITHUB_ACTION_PATH}/operations/deployment/terraform/eks/terraform.tfvars"
393+
354394
# We might want to pass only the variables needed and not all of them.
355395

356396
echo "Done with generate_vars_terraform.sh"

operations/deployment/terraform/aws/bitops.after-deploy.d/delete-tf-state-bucket.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
echo ""
66

7-
tf_state_file="tf-state-ec2"
7+
tf_state_file="tf-state-aws"
88
bucket="$TF_STATE_BUCKET"
99

1010
function check_aws_bucket_for_file() {

operations/deployment/terraform/aws/bitops.after-deploy.d/generate-outputs.sh

+5
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,15 @@ if [ "$BITOPS_TERRAFORM_COMMAND" != "destroy" ]; then
2020
# Generating ec2 terraform .env
2121
export BITOPS_EC2_PUBLIC_IP="$(cat $TARGET_FILE | grep instance_public_ip | awk -F"=" '{print $2}')"
2222
export BITOPS_EC2_PUBLIC_URL="$(cat $TARGET_FILE | grep instance_public_dns | awk -F"=" '{print $2}')"
23+
export BITOPS_EC2_ELB_DNS="$(cat $TARGET_FILE | grep lb_public_dns | awk -F"=" '{print $2}')"
24+
export BITOPS_EC2_PUBLIC_DNS="$(cat $TARGET_FILE | grep application_public_dns | awk -F"=" '{print $2}')"
2325
if [ -n "$BITOPS_EC2_PUBLIC_URL" ]; then
2426
echo -en "
2527
#### EC2 values deployments:
28+
AWS_INSTANCE_IP="$BITOPS_EC2_PUBLIC_IP"
2629
AWS_INSTANCE_URL="$BITOPS_EC2_PUBLIC_URL"
30+
AWS_INSTANCE_ELB="$BITOPS_EC2_ELB_DNS"
31+
AWS_INSTANCE_DNS="$BITOPS_EC2_PUBLIC_DNS"
2732
2833
" > $BITOPS_ENVROOT/terraform/aws/ec2.env
2934
fi

operations/deployment/terraform/aws/bitovi_main.tf

+40-39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "ec2" {
2-
source = "..//modules/aws/ec2"
2+
source = "../modules/aws/ec2"
33
count = var.aws_ec2_instance_create ? 1 : 0
44
# EC2
55
aws_ec2_ami_filter = var.aws_ec2_ami_filter
@@ -25,7 +25,7 @@ module "ec2" {
2525
}
2626

2727
module "aws_certificates" {
28-
source = "..//modules/aws/certificates"
28+
source = "../modules/aws/certificates"
2929
count = var.aws_r53_enable_cert && var.aws_r53_domain_name != "" ? 1 : 0
3030
# Cert
3131
aws_r53_cert_arn = var.aws_r53_cert_arn
@@ -40,7 +40,7 @@ module "aws_certificates" {
4040
}
4141

4242
module "aws_route53" {
43-
source = "..//modules/aws/route53"
43+
source = "../modules/aws/route53"
4444
count = var.aws_r53_enable && var.aws_r53_domain_name != "" ? 1 : 0
4545
# R53 values
4646
aws_r53_domain_name = var.aws_r53_domain_name
@@ -59,7 +59,7 @@ module "aws_route53" {
5959
}
6060

6161
module "aws_elb" {
62-
source = "..//modules/aws/elb"
62+
source = "../modules/aws/elb"
6363
# We should have a count here, right?
6464
aws_elb_security_group_name = var.aws_elb_security_group_name
6565
aws_elb_app_port = var.aws_elb_app_port
@@ -81,7 +81,7 @@ module "aws_elb" {
8181
}
8282

8383
module "efs" {
84-
source = "..//modules/aws/efs"
84+
source = "../modules/aws/efs"
8585
count = local.create_efs ? 1 : 0
8686
# EFS
8787
aws_efs_replication_destination = var.aws_efs_replication_destination
@@ -101,7 +101,7 @@ module "efs" {
101101
}
102102

103103
module "ec2_efs" {
104-
source = "..//modules/aws/ec2_efs"
104+
source = "../modules/aws/ec2_efs"
105105
count = local.create_efs ? var.aws_efs_mount_id != "" ? 1 : 0 : 0
106106
# EFS
107107
aws_efs_create = var.aws_efs_create
@@ -129,7 +129,7 @@ module "ec2_efs" {
129129

130130

131131
module "aurora_rds" {
132-
source = "..//modules/aws/aurora"
132+
source = "../modules/aws/aurora"
133133
count = var.aws_postgres_enable ? 1 : 0
134134
# RDS
135135
aws_postgres_engine = var.aws_postgres_engine
@@ -158,40 +158,41 @@ module "aurora_rds" {
158158
depends_on = [data.aws_subnets.vpc_subnets]
159159
}
160160

161-
module "eks" {
162-
source = "..//modules/aws/eks"
163-
count = var.aws_eks_create ? 1 : 0
164-
# EKS
165-
aws_eks_region = var.aws_eks_region
166-
aws_eks_security_group_name_master = var.aws_eks_security_group_name_master
167-
aws_eks_security_group_name_worker = var.aws_eks_security_group_name_worker
168-
aws_eks_environment = var.aws_eks_environment
169-
aws_eks_stackname = var.aws_eks_stackname
170-
aws_eks_cidr_block = var.aws_eks_cidr_block
171-
aws_eks_workstation_cidr = var.aws_eks_workstation_cidr
172-
aws_eks_availability_zones = var.aws_eks_availability_zones
173-
aws_eks_private_subnets = var.aws_eks_private_subnets
174-
aws_eks_public_subnets = var.aws_eks_public_subnets
175-
aws_eks_cluster_name = var.aws_eks_cluster_name
176-
aws_eks_cluster_log_types = var.aws_eks_cluster_log_types
177-
aws_eks_cluster_version = var.aws_eks_cluster_version
178-
aws_eks_instance_type = var.aws_eks_instance_type
179-
aws_eks_instance_ami_id = var.aws_eks_instance_ami_id
180-
aws_eks_instance_user_data_file = var.aws_eks_instance_user_data_file
181-
aws_eks_ec2_key_pair = var.aws_eks_ec2_key_pair
182-
aws_eks_store_keypair_sm = var.aws_eks_store_keypair_sm
183-
aws_eks_desired_capacity = var.aws_eks_desired_capacity
184-
aws_eks_max_size = var.aws_eks_max_size
185-
aws_eks_min_size = var.aws_eks_min_size
186-
# Hidden
187-
aws_eks_vpc_name = var.aws_eks_vpc_name
188-
# Others
189-
aws_resource_identifier = var.aws_resource_identifier
190-
common_tags = local.default_tags
191-
}
161+
#module "eks" {
162+
# source = "../modules/aws/eks"
163+
# count = var.aws_eks_create ? 1 : 0
164+
# # EKS
165+
# #aws_eks_create = var.aws_eks_create
166+
# aws_eks_region = var.aws_eks_region
167+
# aws_eks_security_group_name_master = var.aws_eks_security_group_name_master
168+
# aws_eks_security_group_name_worker = var.aws_eks_security_group_name_worker
169+
# aws_eks_environment = var.aws_eks_environment
170+
# aws_eks_stackname = var.aws_eks_stackname
171+
# aws_eks_cidr_block = var.aws_eks_cidr_block
172+
# aws_eks_workstation_cidr = var.aws_eks_workstation_cidr
173+
# aws_eks_availability_zones = var.aws_eks_availability_zones
174+
# aws_eks_private_subnets = var.aws_eks_private_subnets
175+
# aws_eks_public_subnets = var.aws_eks_public_subnets
176+
# aws_eks_cluster_name = var.aws_eks_cluster_name
177+
# aws_eks_cluster_log_types = var.aws_eks_cluster_log_types
178+
# aws_eks_cluster_version = var.aws_eks_cluster_version
179+
# aws_eks_instance_type = var.aws_eks_instance_type
180+
# aws_eks_instance_ami_id = var.aws_eks_instance_ami_id
181+
# aws_eks_instance_user_data_file = var.aws_eks_instance_user_data_file
182+
# aws_eks_ec2_key_pair = var.aws_eks_ec2_key_pair
183+
# aws_eks_store_keypair_sm = var.aws_eks_store_keypair_sm
184+
# aws_eks_desired_capacity = var.aws_eks_desired_capacity
185+
# aws_eks_max_size = var.aws_eks_max_size
186+
# aws_eks_min_size = var.aws_eks_min_size
187+
# # Hidden
188+
# aws_eks_vpc_name = var.aws_eks_vpc_name
189+
# # Others
190+
# aws_resource_identifier = var.aws_resource_identifier
191+
# common_tags = local.default_tags
192+
#}
192193

193194
module "ansible" {
194-
source = "..//modules/aws/ansible"
195+
source = "../modules/aws/ansible"
195196
count = var.aws_ec2_instance_create ? 1 : 0
196197
aws_efs_enable = var.aws_efs_enable
197198
app_repo_name = var.app_repo_name

0 commit comments

Comments
 (0)