Skip to content

gmccormick8/simple-gcp-static-website

Repository files navigation

GCP Static Website Terraform Project

Run Super Linter

This project provides Infrastructure as Code (IaC) for deploying a static website on Google Cloud Platform using Cloud Storage and Cloud Load Balancing. The implementation is based on Google's Host a Static Website guide. This project is designed to run from the Google Cloud Shell using a user-friendly startup script. Simply clone this repository, run the script (following the prompts), and let Terraform do the rest!

Architecture

The project creates the following resources:

  • Google Cloud Storage bucket for hosting static content
  • Global HTTP External Application Load Balancer
  • Static IP address

Prerequisites

  • Google Cloud Platform Account
  • Google Cloud SDK - Preinstalled in Google Cloud Shell
  • Terraform (version ~> 1.11) - Terraform is preinstalled in Google Cloud Shell
  • Active Google Cloud Project with billing enabled
  • Required APIs enabled:
    • compute.googleapis.com
    • storage-api.googleapis.com

The tilde (~>) operator allows only the rightmost version component to increment. For example, ~> 1.11 allows installing versions 1.11.0 up to but not including 1.12.0.

Quick Start (Google Cloud Shell)

  1. Clone this repository:
git clone https://github.com/gmccormick8/simple-gcp-static-website.git && cd simple-gcp-static-website
  1. Run setup script to initialize the project (enter "y" when prompted):
bash setup.sh

The setup script will:

  • Verify and update Terraform if needed
  • Enable required Google Cloud APIs
  • Initialize Terraform
  • Create and apply the Terraform configuration
  • Display a link to the newly created website at the end of the output. Please note that it may take several minutes for the website to go live.

Manual Deployment

If you prefer to deploy manually:

  1. Set your Google Cloud project ID:
echo 'project_id = "YOUR_PROJECT_ID"' > terraform.tfvars
  1. Initialize Terraform:
terraform init
  1. Review the deployment plan:
terraform plan
  1. Apply the configuration (enter "yes" when prompted):
terraform apply

Customization

  • The default index page and 404 error page can be modified in main.tf
  • Storage bucket configuration can be adjusted in modules/storage/main.tf
  • Load balancer settings can be modified in modules/load-balancer/main.tf

Cleanup

To remove all created resources (enter "yes" when prompted):

terraform destroy

Security Notes

This implementation:

  • Makes the storage bucket public
  • Uses HTTP (not HTTPS)
  • Is intended for development/testing purposes
  • Is not suitable for production use

Contributing

Contributions are welcome! Please read our contributing guidelines before submitting pull requests.

License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.

Releases

No releases published

Packages

No packages published