Feature/packer jenkins (#31)

* packer jenkins update
This commit is contained in:
Edward Viaene
2020-03-17 21:21:40 +01:00
committed by GitHub
parent 50df73f39a
commit ef34e41349
10 changed files with 99 additions and 37 deletions
@@ -1,14 +0,0 @@
#!/bin/bash
echo "Newer terraform versions have a new way of defining a backend. Copy paste the following code in a backend.tf file, modify the region/s3 bucket, and execute 'terraform init' to initialize the backend. You'll be asked to copy the data from the local backend to the s3 backend, which you can answer yes.
"
echo 'backend.tf
==========
terraform {
backend "s3" {
bucket = "terraform-state-a3c731f"
key = "terraform.tfstate"
region = "eu-west-1"
}
}
'
+1 -9
View File
@@ -30,18 +30,10 @@ echo "deb http://pkg.jenkins.io/debian-stable binary/" >> /etc/apt/sources.list
apt-get update
# install dependencies
apt-get install -y python3 openjdk-8-jre
update-java-alternatives --set java-1.8.0-openjdk-amd64
apt-get install -y python3 openjdk-11-jdk awscli
# install jenkins
apt-get install -y jenkins=${JENKINS_VERSION} unzip
# install pip
wget -q https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
rm -f get-pip.py
# install awscli
pip install awscli
# install terraform
wget -q https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
&& unzip -o terraform_${TERRAFORM_VERSION}_linux_amd64.zip -d /usr/local/bin \
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
set -ex
AWS_REGION="eu-west-1"
cd jenkins-packer-demo
S3_BUCKET=`aws s3 ls --region $AWS_REGION |grep terraform-state |tail -n1 |cut -d ' ' -f3`
sed -i 's/terraform-state-xx70dpnh/'${S3_BUCKET}'/' backend.tf
sed -i 's/#//g' backend.tf
aws s3 cp s3://${S3_BUCKET}/amivar.tf amivar.tf --region $AWS_REGION
terraform init
terraform apply -auto-approve -var APP_INSTANCE_COUNT=1 -target aws_instance.app-instance