Skip to content

Deploy an externally trained machine learning model to Google Cloud Platform (GCP) as a cloud function.

Notifications You must be signed in to change notification settings

kwame-mintah/terraform-gcp-model-serving

Repository files navigation

Terraform Google Cloud Platform (GCP) Model Serving

The main purpose of this repository is to create resources needed for model serving using Google Cloud Platform (GCP) cloud functions. Notes can be found in my notes-md repository. Model inference code can be found in gcp-cloud-run-function-model-inference.

Development

Dependencies

Prerequisites

  1. Have a Google Cloud account account and associated credentials.

Usage

  1. Navigate to the environment you would like to deploy,

  2. Initialize the configuration with:

    terragrunt init
  3. Plan your changes with:

    terragrunt plan
  4. If you're happy with the changes

    terragrunt apply

Note

Please note that terragrunt will create a bucket for storing the remote state. Ensure the account deploying the resources has the appropriate permissions to create or connect to these resources.

Pre-Commit hooks

Git hook scripts are very helpful for identifying simple issues before pushing any changes. Hooks will run on every commit automatically pointing out issues in the code e.g. trailing whitespace.

To help with the maintenance of these hooks, pre-commit is used, along with pre-commit-hooks.

Please following these instructions to install pre-commit locally and ensure that you have run pre-commit install to install the hooks for this project.

Additionally, once installed, the hooks can be updated to the latest available version with pre-commit autoupdate.

Documentation Generation

Code formatting and documentation for variables and outputs is generated using pre-commit-terraform hooks that in turn uses terraform-docs that will insert/update documentation. The following markers have been added to the README.md:

<!-- {BEGINNING|END} OF PRE-COMMIT-TERRAFORM DOCS HOOK --->

Retrieving service account secrets for GitHub Action(s) and Model Inference Service

Two service accounts are created and need to be referenced within the gcp-cloud-run-function-model-inference repository. In order to retrieve these secrets to be used elsewhere, the following command can be used:

terragrunt output -raw prediction_service_account_key > prediction_service_account.json \
terragrunt output -raw github_action_service_account_key > github_action_service_account.json

Requirements

Name Version
terraform >= 1.5.7, <= 1.9.0
google ~> 6.6.0

Providers

Name Version
google 6.6.0

Modules

No modules.

Resources

Name Type
google_artifact_registry_repository.prediction_service_registry resource
google_project_iam_binding.github_actions_registry_role resource
google_project_iam_binding.prediction_service_account_role resource
google_service_account.github_actions_service_account resource
google_service_account.prediction_service_account resource
google_service_account_key.github_actions_service_account_key resource
google_service_account_key.prediction_service_account_key resource
google_storage_bucket.mlflow_bucket resource
google_project.project data source

Inputs

Name Description Type Default Required
env_prefix The prefix added to resources in the environment. string n/a yes
gcp_default_labels Labels that will be applied to all resources with a top level labels field or a labels
field nested inside a top level metadata field.
map(string) {} no
gcp_project The default project to manage resources in. string n/a yes
gcp_region The default region to manage resources in. string n/a yes
gcp_zone The default zone to manage resources in. Generally,
this zone should be within the default region you specified.
string n/a yes
project_name The name of the project. string n/a yes

Outputs

Name Description
gcp_project_number The numeric identifier of the project.
github_action_service_account_key The GitHub service account private key in JSON format, base64 encoded.
prediction_service_account_key The prediction service private key in JSON format, base64 encoded.
prediction_service_docker_registry_id The prediction service docker registry ID.
prediction_service_docker_registry_name The prediction service docker registry name.

About

Deploy an externally trained machine learning model to Google Cloud Platform (GCP) as a cloud function.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages