cscashby / deploystack-wordpress-sites

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GC Start

Host a Serverless Wordpress Site with Cloud Run

Introduction

This architecture uses click-to-deploy so you can spin up infrastructure in minutes using terraform!

43% of the Web is built on Wordpress. Because of its simplicity and versatility, Wordpress can be used for internal websites and customer facing e-commerce platforms in small to large businesses, while still offering security. Cloud Run automatically scales your WordPress application to handle any amount of traffic, without requiring manual intervention. This means that your website can handle large traffic spikes, without worrying about capacity.

Cloud Run allows you to deploy your WordPress application quickly and easily, with a few clicks or commands. You can deploy your application from a container image stored in a container registry or directly from a Git repository. This click-to-deploy architecture leverages the serverless and scalability benefits of using Cloud Run to host a Wordpress Application connected to a PostgreSQL instance.

This repo is based on the Cloud Foundation Fabric blueprint available here.

Use cases

These are some of the use cases you can build on top of this infrastructure:

  • Business websites
  • E-commerce websites
  • Portfolios
  • Non-profit websites
  • Educational Websites

Architecture

Wordpress on Cloud Run

The main components that are deployed in this architecture are the following (you can learn about them by following the hyperlinks):

  • Cloud Run: serverless PaaS offering to host containers for web-oriented applications, while offering security, scalability and easy versioning
  • Cloud SQL: Managed solution for SQL databases
  • VPC Serverless Connector: Solution to access the CloudSQL VPC from Cloud Run, using only internal IP addresses

Costs

Pricing Estimates - We have created a sample estimate based on some usage we see from new startups looking to scale. This estimate would give you an idea of how much this deployment would essentially cost per month at this scale and you extend it to the scale you further prefer. Here's the link.

Setting up the project for the deployment

This example will deploy all its resources into the project defined by the project_id variable. Please note that we assume this project already exists. However, if you provide the appropriate values to the project_create variable, the project will be created as part of the deployment.

If project_create is left to null, the identity performing the deployment needs the owner role on the project defined by the project_id variable. Otherwise, the identity performing the deployment needs resourcemanager.projectCreator on the resource hierarchy node specified by project_create.parent and billing.user on the billing account specified by project_create.billing_account_id.

Spinning up the architecture

Before we deploy the architecture, you will need the following information:

  • The service project ID.
  • A unique prefix that you want all the deployed resources to have (for example: awesomestartup). This must be a string with no spaces or tabs.
  • A Wordpress image if you want to use your own, otherwise you can use the provided standard image.
  • A list of Groups or Users with Service Account Token creator role on Service Accounts in IAM format, eg 'group:group@domain.com'.

Notes:

  1. If you want to change your admin password later on, please note that you can only do so via the Wordpress user interface.
  2. If you have the domain restriction org. policy on your organization, you have to edit the cloud_run_invoker variable and give it a value that will be accepted in accordance to your policy.

Click on the button below, sign in if required and when the prompt appears, click on β€œconfirm”. It will walk you through setting up your architecture.

Open Cloud Shell

This is the startup screen that appears after clicking the button and confirming:

cloud_shell

During the process, you will be asked for some user input. All necessary variables are explained at the bottom of this ReadMe file. In case of failure, you can simply click the button again.

πŸŽ‰ Congratulations! πŸŽ‰
You have successfully deployed the foundation for running Wordpress using CloudRun on Google Cloud.

Note: You might get the following error (or a similar one):

β”‚ Error: resource is in failed state "Ready:False", message: Revision '...' is not ready and cannot serve traffic.β”‚

In case this happens, manually run

    deploystack install

to run the installation again.

Using the Wordpress Installation

Upon completion, you will see the output with the values for the Cloud Run service and the user and password to access the /admin part of the website. You can also view it later with:

terraform output
# or for the concrete variable:
terraform output cloud_run_service

When clicking on the Wordpress link, it will immediately prompt you to register as an administrator. The password will be pre-filled and can be changed after registration.

Cleaning Up Your Environment

The easiest way to remove all deployed resources is to run the following command in Cloud Shell:

deploystack uninstall

The above command will delete the associated resources so there will be no billable charges made afterwards.

Special Thanks

A special thank you goes out to Natalia Strelkova (skalolazka) and Grigory Movsesyan, the original developers of this example architecture.

Variables

name description type default
project_id Project id, references existing project if project_create is null. string
wordpress_image Image to run with Cloud Run, starts with "gcr.io" string mirror.gcr.io/library/wordpress
cloud_run_invoker IAM member authorized to access the end-point (for example, 'user:YOUR_IAM_USER' for only you or 'allUsers' for everyone) string "allUsers"
cloudsql_password CloudSQL password (will be randomly generated by default) string null
connector Existing VPC serverless connector to use if not creating a new one string null
create_connector Should a VPC serverless connector be created or not bool true
ip_ranges CIDR blocks: VPC serverless connector, Private Service Access(PSA) for CloudSQL, CloudSQL VPC object({…}) {…}
prefix Unique prefix used for resource names. Not used for project if 'project_create' is null. string ""
principals List of users to give rights to (CloudSQL admin, client and instanceUser, Logging admin, Service Account User and TokenCreator), eg 'user@domain.com'. list(string) []
project_create Provide values if project creation is needed, uses existing project if null. Parent is in 'folders/nnn' or 'organizations/nnn' format. object({…}) null
region Region for the created resources string
wordpress_password Password for the Wordpress user (will be randomly generated by default) string null
wordpress_port Port for the Wordpress image number 8080

Outputs

name description sensitive
cloud_run_service CloudRun service URL βœ“
cloudsql_password CloudSQL password βœ“
wp_password Wordpress user password βœ“
wp_user Wordpress username

About

License:Apache License 2.0


Languages

Language:HCL 100.0%