|
1 | | -# terraform-octue-twined-static |
2 | | -A partner terraform module to terraform-octue-twined providing static resources. |
| 1 | +# terraform-octue-twined-core |
| 2 | +A Terraform module for deploying the core storage and IAM resources for an Octue Twined services network to google cloud. |
| 3 | + |
| 4 | + |
| 5 | +# Resources |
| 6 | +These resources are automatically deployed: |
| 7 | +- An artifact registry repository for storing Octue Twined service revision docker images |
| 8 | +- A BigQuery table acting as an event store for Twined service events |
| 9 | +- IAM service accounts and roles for: |
| 10 | + - Any number of maintainers to use with Twined services |
| 11 | + - GitHub Actions to a) build and push Twined service images to the artifact registry; b) test services |
| 12 | +- A workload identity pool and provider allowing GitHub actions to authenticate with google cloud |
| 13 | +- A cloud storage bucket to store input, output, and diagnostics data for Twined services |
| 14 | + |
| 15 | + |
| 16 | +# Installation and usage |
| 17 | + |
| 18 | +> [!IMPORTANT] |
| 19 | +> Deploying this Terraform module is a prerequisite to deploying the [terraform-octue-twined-cluster](https://github.com/octue/terraform-octue-twined-cluster). |
| 20 | +> module. You must deploy both to have a cloud-based Octue Twined services network. See [a live example here](https://github.com/octue/twined-infrastructure). |
| 21 | +
|
| 22 | +> [!TIP] |
| 23 | +> Deploy this module in a separate Terraform configuration (directory/workspace) to the [terraform-octue-twined-cluster](https://github.com/octue/terraform-octue-twined-cluster) |
| 24 | +> module. This allows the option to spin down the Kubernetes cluster provided by the other module while keeping the core |
| 25 | +> resources that contain all data produced by your Twined services. Spinning the cluster down entirely can save on |
| 26 | +> running costs in periods of extended non-use while keeping all data available. |
| 27 | +
|
| 28 | +Add the below blocks to your Terraform configuration and run: |
| 29 | +```shell |
| 30 | +terraform plan |
| 31 | +``` |
| 32 | + |
| 33 | +If you're happy with the plan, run: |
| 34 | +```shell |
| 35 | +terraform apply |
| 36 | +``` |
| 37 | +and approve the run. |
| 38 | + |
| 39 | +## Minimal configuration |
| 40 | + |
| 41 | +```terraform |
| 42 | +# main.tf |
| 43 | +
|
| 44 | +terraform { |
| 45 | + required_version = ">= 1.8.0" |
| 46 | +
|
| 47 | + required_providers { |
| 48 | + google = { |
| 49 | + source = "hashicorp/google" |
| 50 | + version = "~>6.12" |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +
|
| 55 | +
|
| 56 | +provider "google" { |
| 57 | + project = var.google_cloud_project_id |
| 58 | + region = var.google_cloud_region |
| 59 | +} |
| 60 | + |
| 61 | +
|
| 62 | +module "octue_twined_core" { |
| 63 | + source = "git::github.com/octue/terraform-octue-twined-core.git?ref=0.1.0" |
| 64 | + google_cloud_project_id = var.google_cloud_project_id |
| 65 | + google_cloud_region = var.google_cloud_region |
| 66 | + github_account = var.github_account |
| 67 | + maintainer_service_account_names = var.maintainer_service_account_names |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +```terraform |
| 72 | +# variables.tf |
| 73 | +
|
| 74 | +variable "google_cloud_project_id" { |
| 75 | + type = string |
| 76 | + default = "<google-cloud-project-id>" |
| 77 | +} |
| 78 | +
|
| 79 | +variable "google_cloud_region" { |
| 80 | + type = string |
| 81 | + default = "<google-cloud-region>" |
| 82 | +} |
| 83 | +
|
| 84 | +variable "github_account" { |
| 85 | + type = string |
| 86 | + default = "<your-github-account>" |
| 87 | +} |
| 88 | +
|
| 89 | +variable "maintainer_service_account_names" { |
| 90 | + type = set(string) |
| 91 | + default = ["person1", "person2"] |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +## Dependencies |
| 96 | +- Terraform: `>= 1.8.0, <2` |
| 97 | +- Providers: |
| 98 | + - `hashicorp/google`: `~>6.12` |
| 99 | +- Google cloud APIs: |
| 100 | + - The Cloud Resource Manager API must be [enabled manually](https://console.developers.google.com/apis/api/cloudresourcemanager.googleapis.com) |
| 101 | + before using the module |
| 102 | + - All other required google cloud APIs are enabled automatically by the module |
| 103 | + |
| 104 | +## Authentication |
| 105 | +The module needs to authenticate with google cloud before it can be used: |
| 106 | + |
| 107 | +1. Create a service account for Terraform and assign it the `editor` and `owner` basic IAM permissions |
| 108 | +2. Download a JSON key file for the service account |
| 109 | +3. If using Terraform Cloud, follow [these instructions](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#using-terraform-cloud). |
| 110 | + before deleting the key file from your computer |
| 111 | +4. If not using Terraform Cloud, follow [these instructions](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication-configuration) |
| 112 | + or use another [authentication method](https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/provider_reference#authentication). |
| 113 | + |
| 114 | + |
| 115 | +## Destruction |
| 116 | +> [!WARNING] |
| 117 | +> If the `deletion_protection` input is set to `true`, it must first be set to `false` and `terraform apply` run before |
| 118 | +> running `terraform destroy` or any other operation that would result in the destruction or replacement of the cloud |
| 119 | +> storage bucket or event store BigQuery table. Not doing this can lead to a state needing targeted Terraform commands |
| 120 | +> and/or manual configuration changes to recover from. |
| 121 | +
|
| 122 | +Disable `deletion_protection` and run: |
| 123 | +```shell |
| 124 | +terraform destroy |
| 125 | +``` |
| 126 | + |
| 127 | + |
| 128 | +# Input reference |
| 129 | + |
| 130 | +| Name | Type | Required | Default | |
| 131 | +|-------------------------------------|---------------|----------|-----------| |
| 132 | +| `google_cloud_project_id` | `string` | Yes | N/A | |
| 133 | +| `google_cloud_region` | `string` | Yes | N/A | |
| 134 | +| `github_account` | `string` | Yes | N/A | |
| 135 | +| `maintainer_service_account_names` | `set(string)` | Yes | N/A | |
| 136 | +| `deletion_protection` | `bool` | No | `true` | |
| 137 | + |
| 138 | +See [`variables.tf`](/variables.tf) for descriptions. |
| 139 | + |
| 140 | + |
| 141 | +# Output reference |
| 142 | + |
| 143 | +| Name | Type | |
| 144 | +|-------------------------------------|----------| |
| 145 | +| `artifact_registry_repository_name` | `string` | |
| 146 | +| `storage_bucket_url` | `string` | |
| 147 | +| `event_store_id` | `string` | |
| 148 | + |
| 149 | +See [`outputs.tf`](/outputs.tf) for descriptions. |
0 commit comments