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!
The project creates the following resources:
- Google Cloud Storage bucket for hosting static content
- Global HTTP External Application Load Balancer
- Static IP address
- 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.
- Clone this repository:
git clone https://github.com/gmccormick8/simple-gcp-static-website.git && cd simple-gcp-static-website
- 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.
If you prefer to deploy manually:
- Set your Google Cloud project ID:
echo 'project_id = "YOUR_PROJECT_ID"' > terraform.tfvars
- Initialize Terraform:
terraform init
- Review the deployment plan:
terraform plan
- Apply the configuration (enter "yes" when prompted):
terraform apply
- 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
To remove all created resources (enter "yes" when prompted):
terraform destroy
This implementation:
- Makes the storage bucket public
- Uses HTTP (not HTTPS)
- Is intended for development/testing purposes
- Is not suitable for production use
Contributions are welcome! Please read our contributing guidelines before submitting pull requests.
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.