You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create Terraform Modules locally. This repository will guide you through creating Terraform modules locally, focused on building a reusable module to host a static website on AWS S3
Build a Terraform Module
Step-01: Introduction
Build a Terraform Module
Create a Terraform module
Use local Terraform modules in your configuration
Configure modules with variables
Use module outputs
We are going to write a local re-usable module for the following usecase.
Usecase: Hosting a static website with AWS S3 buckets
Create an S3 Bucket
Create Public Read policy for the bucket
Once above two are ready, we can deploy Static Content
For steps, 1 and 2 we are going to create a re-usable module in Terraform
How are we going to do this?
We are going to do this in 3 sections
Section-1 - Full Manual: Create Static Website on S3 using AWS Management Consoleand host static content and test
Section-2 - Terraform Resources: Automate section-1 using Terraform Resources
Section-3 - Terraform Modules: Create a re-usable module for hosting static website by referencing section-2 terraform configuration files.
Step-02: Hosting a Static Website with AWS S3 using AWS Management Console
We have used terraform init to download providers from terraform registry and at the same time to download modules present in local modules folder in terraform working directory.
Assuming we already have initialized using terraform init and later we have created module configs, we can terraform get to download the same.
Whenever you add a new module to a configuration, Terraform must install the module before it can be used.
Both the terraform get and terraform init commands will install and update modules.
The terraform init command will also initialize backends and install plugins.
# Delete modules in .terraform folder
ls -lrt .terraform/modules
rm -rf .terraform/modules
ls -lrt .terraform/modules
# Terraform Get
terraform get
ls -lrt .terraform/modules
Step-04-07: Major difference between Local and Remote Module
When installing a remote module, Terraform will download it into the .terraform directory in your configuration's root directory.
When installing a local module, Terraform will instead refer directly to the source directory.
Because of this, Terraform will automatically notice changes to local modules without having to re-run terraform init or terraform get.
Step-05: Conclusion
Created a Terraform module
Used local Terraform modules in your configuration
Configured modules with variables
Used module outputs
About
This repository will guide you through creating Terraform modules locally, focused on building a reusable module to host a static website on AWS S3.