This project enables serving content from a private Google Cloud Storage bucket via Google Cloud CDN, optimized for performance and security. It integrates various Google Cloud services to deliver content globally using a custom domain.
- Secure storage of content in a private Google Cloud Storage bucket.
- Global caching and low-latency delivery using Google Cloud CDN.
- Http to Https redirect.
- Custom domain setup using Google Cloud Load Balancer and Google Cloud DNS.
This project is a part of test task, so it contains the self-signed certificate files unencrypted, the image of the cat from the internet and the domain name that never was purchased. This will result to the SSL issue if the certificate and the domain name will not be replaced by the proper ones.
The IAM role for the cloud bucket allows all users to read the content, so the cat picture will be available via direct link to the bucket. I tried to restrict the policy and let only CDN service to read, but the service was not created by Google during enabling CDN for unknown reason.
- Google Cloud Storage: Stores the content securely in a private bucket.
- Google Cloud CDN: Accelerates content delivery through caching at Google's edge locations.
- Google Cloud Load Balancer: Provides a public endpoint for the custom domain and routes traffic to the backend bucket.
- Google Cloud DNS: Manages DNS records for the custom domain.
- IAM Roles and Permissions: Ensures proper access control for the private bucket.
The project configuration is fully automated using Terraform (tested on version v1.9.8)
- Create a project in GCP or pick up existed one
- In
teraform.tfstate
file change the variableproject_id
according to the name of your project - In
teraform.tfstate
file change theregion
to desired region. For example,europe-central2
- (Optional) Prepare the domain name for the endpoint. Add it to the
terraform.tfstate
file as the variabledomain_name
- (Optional) Issue a certificate for mentioned domain name. Replace
cert.pem
andkey.pem
in thessl_certs
directory with the certificate file and the private key file accordingly - Activate the compute engine API for the project using the link: https://console.developers.google.com/apis/api/compute.googleapis.com/overview
- Activate the DNS API for the project using the link: https://console.developers.google.com/apis/api/dns.googleapis.com/overview
- Clone this repository or download the files and extract it
- Go to the directory with the terraform code
cd nik-test-gcp
-
In your console authenticate to the GCP account with
gcloud auth application-default login
command- Install the gcloud CLI if you need it
-
Run
terraform init
-
Run
terraform apply
, check the resources that will be created and typeyes
to proceed -
After Terraform completes it's job, wait about 10 minutes while the Backend Bucket initializes
-
Check the link from the output
https://[external-ip]/test.jpg
if you didn't create a domain (be ready to face SSL error and add it to the exception)https://[domain-name]/test.jpg
if you have a domain name purchased (*note that DNS routes could take about an hour to distribute the information about the domain)- Http requests should also redirect to https
- You can check the Load Balancer logs to see the image was cached by CDN