This is an example of how to send emails in Google Cloud via SendGrid.
A Pub/Sub triggered Cloud Function that sends emails using SendGrid.
It expects a message with the following structure:
{
"to": "recipient@example.com",
"subject": "My email subject",
"body": "<h1>The email body can be html</h1>"
}
The system is deployed using terraform
, running in Cloud Build.
- Create an API key in SendGrid.
- Set up domain authentication in SendGrid.
- Create a Google Cloud Organization.
- Install
terraform
. - Install the
gcloud
CLI.
This is the process that creates the Google Cloud Project, enables the required APIs, and grants the necessary permissions to the Service Accounts, including the ones required for the Cloud Build Service Account to deploy the system.
- Run
gcloud auth login
- Run
gcloud auth application-default login
. cd
into the deployment/google-cloud/terraform/bootstrap folder.- Comment out the entire contents of the deployment/google-cloud/terraform/bootstrap/backend.tf file.
- Create a
terraform.tfvars
file and add your variables' values. Leave thesourcerepo_name
empty for now. - Run
terraform init
. - Run
terraform apply -target=module.project
. - Uncomment the deployment/google-cloud/terraform/bootstrap/backend.tf file's contents and add the value of the
tfstate_bucket
output as the value of thebucket
attribute. - Run
terraform init
and answeryes
. - Create a Cloud Source Repository in the project your just created. Optionally, fork this repository and create a Cloud Source Repository by mirroring your forked repo. Update the
sourcerepo_name
variable with the repository name. - Run
terraform apply
.
This is a Cloud Build build that actually deploys the system.
- The pipeline can be triggered by either:
- Push a commit to your Cloud Source Repository or to your Github fork.
- Go to your project's Cloud Build Dashboard and manually run the
push-to-branch-deployment
trigger.