Skip to main content

Working With Terraform Modules for AWS (Part 1)

 Terraform for AWS is somewhat clearer than Terraform for Azure - easier to grasp than YAML and it's finicky formatting.

After pushing some DevOps Terraform (TF) configurations live to AWS, I wondered if I could push a static webpage.

Situation - Why Would You Use This?

To quickly spin up the front-end for a simple webpage that might take user input after attaching it to back end services that accept and hold the data. 

What Other Options Are There?

I've documented hosting static webpages through Azure before on here through various methods - The process is somewhat intensive and relies strongly on interconnected systems.

Another option would be using Netlify,  but that works best for truly single-page apps like this. It looks like it has different pages to the untrained eye, but it's only one.

Task - How Is It Done?

Here, the simple webpage is hosted from a bucket. There's an index and error page.

A curious aspect is the website sub-resource-category;

website {
    index_document = "index.html"
    error_document = "error.html"
  }

I couldn't find a CSS option in the documentation - So put your CSS inline, or have a very plain webpage!

The Part About The Modules

You don't need to have separate folders, one to actually push the files to an s3 instance, but it makes it easier. 

The module parts are the ones I had the most trouble wrapping my head around - it wants to link to a folder system, not an individual file. 

So I made a modules directory with folders for specific modules - static-site and webserver, from a tutorial listed below, to get a better grasp on things.

And, everything did work once I got the file paths idea hammered in.

Action - How Can It Be Hosted on AWS?

Several ways; Mostly using CloudFront.

I decided to use the website endpoint as the origin with public access. Some things are already in the configuration file, the acl access option under the bucket.

The CNAME and DNS resolution could be helpful if the page content changes but the URL doesn't, think the Stash Stock Parties - They require, not counting login - about 2 pages.

Let's compare this implementation plan to one of the AWS Five Pillars - 

AWS WAF Operational Excellence

Operational Checklist

  • Am I ready to run this workload? 
  • Is my account attached to my VS Code?
     
  • Do I have the appropriate keys to log into EC2 Instances?
     
  • Are my modules folders properly placed?
     
  • Do I have the 0.40$ USD to test this config?

Planning Checklist - For paid projects, it's:

  • When is this expected? 
  • What tools does the company have that I can use right now to make this more efficient? 
  • Can I get feedback in a timely (3-day turnaround) manner?

Implementation is more of the following:
"This is the closest we can get with the built in tools available, but I see from some research, in the future, X Company is creating a tool that will enable us to do Y. We can set aside some budget of both time and money to implement this in a few months."

Troubleshooting - Check Your Module Files

Situation - Why was I getting a loop when I tried to terraform init?

The 'Why' - Because I had two module codes - one in the modules/budget/main.tf, and one in the main file. It was a loop calling something that already existed.

Solution - Comment out the one in the main file with a note -  so it only pulls from one.

Thanks to - Craig Samuelson and Brian Mccall on Twitter.

Security Checklist

  • What is the intended access to this element?
     
  • Who do I want to reach it?
     
  • Are there any holes in my policies or configurations that can grant unwanted access?
     
  • How can I secure this the best way for my needs? Sometimes, in testing, a block/allow list will suffice, other times, you need more.

Result - GitHub:

https://github.com/l3112/AWS-Static-WebSite-Terraform


Resources Used:

https://www.youtube.com/watch?v=QKyNIdK1RYw

https://www.youtube.com/watch?v=7jnuTdhxjhw&

https://registry.terraform.io/modules/cloudmaniac/static-website/aws/latest

Comments

Popular posts from this blog

Connecting IoT Devices to a Registration Server (Packet Tracer, Cisco)

In Packet Tracer, a demo software made by Cisco Systems. It certainly has changed a lot since 2016. It's almost an Olympic feat to even get started with it now, but it does look snazzy. This is for the new CCNA, that integrates, among other things, IoT and Automation, which I've worked on here before. Instructions here . I don't know if this is an aspect of "Let's make sure people are paying attention and not simply following blindly", or an oversight - The instructions indicate a Meraki Server, when a regular one is the working option here. I have to enable the IoT service on this server. Also, we assign the server an IPv4 address from a DHCP pool instead of giving it a static one. For something that handles our IoT business, perhaps that's safer; Getting a new IPv4 address every week or so is a minimal step against an intruder, but it is a step. There are no devices associated with this new server; In an earlier lab (not shown), I attached them to 'H

What Do You Need? [AKA; List of Offered Services / My Next Role] (2020)

UPDATED 2021 I am a trusted outsourced remote consultant for your company.   I enjoy having the flexibility to take on temporary projects from time to time! I start at part-time, temp work for now. If we like each other, we can renegotiate. If anything sounds weird, out there, or unusual - Feel free to e-mail me , because I probably think it's awesome. 3 Services Offered Technical: Cloud Technician     Azure [ See tag ] Subcategories: Infrastructure As Code (Specifically Terraform/Azure and CloudFormation/AWS ) Azure Networking I really like the Azure space, and will continue down that path.  Support [Web: Example Job Description ] [Text : Example Description ]     I help you with adjustments in HTML, CSS, and Javascript.     When you email a business a question and they answer? That's me.   Auditing :  Something doesn't work on your page or in your app. I can find it. [ Here ] [ Example Job Description ]   I really enjoy testing apps and webpage concepts! I have an

The Webpage: Zero Grocery

 I have always liked the idea of a grocer where I can get a small amount of what I need to try a recipe. I don't need 4lbs of sugar for 12 cookies. Some places used to operate like that, buying things in "Stick it in your bag amounts and we'll weigh it." (RIP, Lucky's Market).  Zero Grocery is the next best thing, offering delivery of food, spices, and underground culinary treats to your (California only) doorstep in reusable containers.      You may be thinking that in the times of COVID, people would be hesitant about reusing glass jars strangers have stuck their fingers in. Not so ; [CEO, Zuleyka] Strasner says that customers haven’t been squeamish about reusable packaging during the pandemic. You don't need an account or subscription to browse the goodies , though you will need a zip code in their delivery range to stick them in the basket.  Come with me as I step through my first impressions of the site here - There's a lot to like. This is not a spo