Skip to content

Commit

Permalink
Add agent data domain to configurable agent fields (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-y authored Mar 10, 2023
1 parent 7baa5a8 commit c3d4d67
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
41 changes: 31 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ This document contains configuration and deployment details for deploying the Su
### Install Terraform

To install Terraform on MacOS
```

```bash
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
```
Expand All @@ -24,8 +25,10 @@ Check out this https://developer.hashicorp.com/terraform/downloads for more deta
### Deploy Superblocks On-Premise-Agent

#### Create your Terraform file

To get started, you'll need a `superblocks_agent_key`. To generate an agent key, go to the [Superblocks On-Premise Agent Setup Wizard](https://app.superblocks.com/opas)
```

```terraform
module "terraform_google_superblocks" {
source = "superblocksteam/superblocks/google"
version = ">=0.1.0"
Expand All @@ -34,62 +37,80 @@ module "terraform_google_superblocks" {
region = "[GOOGLE_CLOUD_REGION]"
superblocks_agent_key = "[YOUR_AGENT_KEY]"
# Subdomain & domain in your Superblocks agent host url, for example superblocks.example.com
sudomain = "[YOUR_SUBDOMAIN]"
domain = "[YOUR_DOMAIN]"
# Google Cloud DNS Zone Name
zone_name = "[YOUR_DOMAINS_CLOUD_DNS_ZONE_NAME]"
}
```

If you are in the **[EU region](https://eu.superblocks.com)**, ensure that

```terraform
superblocks_agent_data_domain = "eu.superblocks.com"
```

is set in your configuration in the module block.

If you use Google Cloud DNS, find the `zone_name` for your `domain` by running `gcloud dns managed-zones list --filter "dns_name ~ ${domain}`. If you don't use Google Cloud DNS, see the [Custom Domain Mapping](https://cloud.google.com/run/docs/mapping-custom-domains) section for how you can manually configure the DNS for your agent.

#### Deploy
```

```bash
terraform init
terraform apply
```

### Advanced Configuration

#### Private Networking

The Terraform module configures your Cloud Run service's ingress to "Allow all traffic." You can update the ingress rules to "Only allow internal traffic" by adding the following to the Terraform module

```
```terraform
internal = true
```

#### Custom Domain Mapping

By default, this module will try to configure a **custom domain** for your Cloud Run service, for example `subdomain.example.com`. This configures both the [Cloud Run Domain Mapping](https://cloud.google.com/run/docs/mapping-custom-domains#map) and a CNAME DNS record for your `domain`.

For this to work successfully, you must verify ownership of your `domain` with Google, and have a Cloud DNS Zone configured for the domain. To verify domain ownership, use the Google CLI command `gcloud domains verify ${domain}`. Find the Cloud DNS Zone Name for your domain by running `gcloud dns managed-zones list --filter "dns_name ~ ${domain}`.

If you don't use Google Cloud DNS, or want to manually configure the Domain Mapping, just disable DNS creation by adding the following to the Terraform module

```
```terraform
create_dns = false
```

If you decide to manually set up a custom domain for your Cloud Run service, follow Google's instructions for [Mapping customer domains](https://cloud.google.com/run/docs/mapping-custom-domains#run)

#### Instance Sized

Configure the CPU & memory limits for your Cloud Run instances by adding the following variables to your Terraform module
```

```terraform
container_requests_cpu = "1"
container_requests_memory = "4Gi"
container_limits_memory = "4Gi"
```

#### Scaling

Google will automatically scale your Cloud Run instances based on traffic. To configure the minimum and maximum number of instances the agent can scale to, add these variables to your Terraform module
```

```terraform
container_min_capacity = "1"
container_max_capacity = "5"
```

#### Other Configurable Options
```

```terraform
variable "superblocks_agent_environment" {
type = string
default = "*"
Expand Down
21 changes: 11 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#################################################################

locals {
_container_memory_value = regex("^(\\d*)(.*)", var.container_limits_memory)[0]
_container_memory_unit = regex("^(\\d*)(.*)", var.container_limits_memory)[1]
_container_memory_value = regex("^(\\d*)(.*)", var.container_limits_memory)[0]
_container_memory_unit = regex("^(\\d*)(.*)", var.container_limits_memory)[1]
_container_memory_multiplier = lower(local._container_memory_unit) == "gi" ? 1000 : 1
node_heap = local._container_memory_value * 0.75 * local._container_memory_multiplier
node_heap = local._container_memory_value * 0.75 * local._container_memory_multiplier
}

module "cloud_run" {
Expand All @@ -21,15 +21,16 @@ module "cloud_run" {
container_port = var.superblocks_agent_port
container_image = var.superblocks_agent_image
container_env = {
"__SUPERBLOCKS_AGENT_SERVER_URL" = var.superblocks_server_url,
"__SUPERBLOCKS_WORKER_LOCAL_ENABLED" = "true",
"SUPERBLOCKS_WORKER_TLS_INSECURE" = "true",
"SUPERBLOCKS_AGENT_KEY" = var.superblocks_agent_key,
"SUPERBLOCKS_CONTROLLER_DISCOVERY_ENABLED" = "false",
"SUPERBLOCKS_AGENT_HOST_URL" = "https://${var.subdomain}.${var.domain}",
"SUPERBLOCKS_AGENT_ENVIRONMENT" = var.superblocks_agent_environment,
"__SUPERBLOCKS_AGENT_SERVER_URL" = var.superblocks_server_url
"__SUPERBLOCKS_WORKER_LOCAL_ENABLED" = "true"
"SUPERBLOCKS_WORKER_TLS_INSECURE" = "true"
"SUPERBLOCKS_AGENT_KEY" = var.superblocks_agent_key
"SUPERBLOCKS_CONTROLLER_DISCOVERY_ENABLED" = "false"
"SUPERBLOCKS_AGENT_HOST_URL" = "https://${var.subdomain}.${var.domain}"
"SUPERBLOCKS_AGENT_ENVIRONMENT" = var.superblocks_agent_environment
"SUPERBLOCKS_AGENT_PORT" = var.superblocks_agent_port
"NODE_OPTIONS" = "--max_old_space_size=${local.node_heap}"
"SUPERBLOCKS_AGENT_DATA_DOMAIN" = "${var.superblocks_agent_data_domain}"
}
container_cpu_throttling = var.container_cpu_throttling
container_requests_cpu = var.container_requests_cpu
Expand Down
12 changes: 11 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ variable "superblocks_agent_image" {

variable "superblocks_server_url" {
type = string
default = "https://app.superblocks.com"
default = "https://api.superblocks.com"
}

variable "name_prefix" {
Expand All @@ -58,6 +58,16 @@ variable "name_prefix" {
description = "This will be prepended to the name of each resource created by this module"
}

variable "superblocks_agent_data_domain" {
type = string
default = "app.superblocks.com"
validation {
condition = contains(["app.superblocks.com", "eu.superblocks.com"], var.superblocks_agent_data_domain)
error_message = "The data domain is invalid. Please use 'app.superblocks.com' or 'eu.superblocks.com'."
}
description = "The domain name for the specific Superblocks region that hosts your data."
}

#################################################################
# Cloud Run
#################################################################
Expand Down

0 comments on commit c3d4d67

Please sign in to comment.