mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-29 01:02:16 +03:00
@@ -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"
|
||||
}
|
||||
}
|
||||
'
|
||||
@@ -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
@@ -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
|
||||
Reference in New Issue
Block a user