Giter Site home page Giter Site logo

using-packer-to-install-s3fs's Introduction

Using Packer and Terraform To Create AMI With S3FS Installed

Using packer and terraform to install s3fs on an Amazon Image (AMI)

  • HashiCorp Packer (https://www.packer.io/) automates the creation of any type of machine image. It embraces modern configuration management by encouraging you to use automated scripts to install and configure the software within your Packer-made images. Packer brings machine images into the modern age, unlocking untapped potential and opening new opportunities.

  • HashiCorp Terraform (https://www.terraform.io/) uses Infrastructure as Code to provision and manage any cloud, infrastructure, or service.

  • s3fs (https://github.com/s3fs-fuse/s3fs-fuse) allows Linux and macOS to mount an S3 bucket via FUSE. s3fs preserves the native object format for files, allowing use of other tools like AWS CLI.

NOTE

Following this directions means that a new VPC will be created using the CIDR defined in variables.tf.

Installation

wget https://releases.hashicorp.com/packer/1.6.2/packer_1.6.2_linux_amd64.zip
unzip packer_1.6.2_linux_amd64.zip
sudo mv packer /usr/local/bin

wget https://releases.hashicorp.com/terraform/0.13.2/terraform_0.13.2_linux_amd64.zip
unzip terraform_0.13.2_linux_amd64.zip
sudo mv terraform /usr/local/bin

Setup

Create IAM Role For Packer Builder

When creating your AMI, you might want access to S3 in order to get files. In order to do this work, the builder EC2 instance needs to have an IAM role associated with it. Create a role called packer-builder that has at least the AmazonS3ReadOnlyAccess policy.

  • Create a file specifying the instance profile name.
cat <<EOF > source.me
export PACKER_BUILDER_INSTANCE_PROFILE="packer-builder"
EOF

Create a PKI Key Pair

This is the key used to SSH into the EC2 instance. This technique is useful because it is independent of AWS. However, the AWS console will not show any key name for the EC2 instance. Basically, don't forget which key goes with which instance.

  • Create a local SSH key. Don't use a passphrase. Use your own email, if desired. This command creates both tf-packer and tf-packer.pub.
EMAIL="[email protected]"
ssh-keygen -t rsa -C $EMAIL -f ./tf-packer

Pick an AWS Region

cat <<EOF > terraform.tfvars
region = "us-east-1"
EOF

Create S3 Bucket For S3FS

I like to use UUIDs in my bucket name to make them unique and opaque. The bucket name is stored in a file that is copied over to the AMI being created.

cat < s3fs-bucket.txt $(uuid)-s3fs EOF

Scripts

Build the AMI.

./01-build-image.sh

Provision the server.

./02-provision-server.sh

SSH to server.

./03-ssh-to-centos.sh

Destroy the server.

./99-destroy-server.sh

Files

Name Description
01-build-image.sh Using to build the AMI.
02-provision-server.sh Starts an EC2 instance based on the latest AMI.
03-ssh-to-centos.sh Connects to the current EC2 instance.
99-destroy-server.sh Terminates the EC2 instance.
centos.json The heart of the project. Used by packer to configure the AMI.
main.tf Used by Terraform to start and configure the EC2 instance.
remote-setup.sh Copied to the remote server during the AMI build process and executed. Runs as the centos user.
variables.tf Describes variables used by main.tf.

using-packer-to-install-s3fs's People

Contributors

medined avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.