Skip to content

Commit

Permalink
Agent host terraform constraints (#387)
Browse files Browse the repository at this point in the history
* Fix some formatting issues in the README.md

* Add variables to build constraints to the agent-host terraform module
  • Loading branch information
plars committed Jan 7, 2025
1 parent 9631bcf commit d1f29aa
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 45 deletions.
95 changes: 52 additions & 43 deletions agent/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,71 @@ This terraform module assume that the Juju model you want to deploy
to has already been created.

1. First, create the model
```

```
$ juju add-model agent-host-1
```
```
2. Create ssh keys to use on the agent host
```
```
$ ssh-keygen -t rsa -f mykey
```
```
3. Create a git repo with the Testflinger configs
If you have more than one agent host to deploy, create a separate directory
for each of them in this repo. Then create a separate directory for each
agent in the agent host directory where they reside. For example:

```
/agent-host-1
-/agent-101
-testflinger-agent.yaml
-default.conf
-/agent-102
-testflinger-agent.yaml
-default.conf
/agent-host-2
...
```
If you have more than one agent host to deploy, create a separate directory
for each of them in this repo. Then create a separate directory for each
agent in the agent host directory where they reside. For example:
```
/agent-host-1
-/agent-101
-testflinger-agent.yaml
-default.conf
-/agent-102
-testflinger-agent.yaml
-default.conf
/agent-host-2
...
```
4. Create a main.tf which specifies the required parameters for this module
```
terraform {
required_providers {
juju = {
version = "~> 0.13.0"
source = "juju/juju"
```
terraform {
required_providers {
juju = {
version = "~> 0.13.0"
source = "juju/juju"
}
}
}
provider "juju" {}
module "lab1" {
source = "/path/to/this/module"
agent_host_name = "agent-host-1"
juju_model = "agent-host-1"
config_repo = "https://github.com/path_to/config_repo.git"
config_branch = "main"
config_dir = "agent-host-1"
ssh_public_key = filebase64("mykey.pub")
ssh_private_key = filebase64("mykey")
}
}
}
provider "juju" {}
module "lab1" {
source = "/path/to/this/module"
agent_host_name = "agent-host-1"
juju_model = "agent-host-1"
config_repo = "https://github.com/path_to/config_repo.git"
config_branch = "main"
config_dir = "agent-host-1"
ssh_public_key = filebase64("mykey.pub")
ssh_private_key = filebase64("mykey")
}
```
```
There are additional parameters you can adjust here if you want:
- **agent_host_cores**: (default: 4) Number of cpu cores to use for the agent host
- **agent_host_mem**: (default: "32768M") Amount of RAM to use for the agent host. This needs to be specified as a string with "M" at the end.
- **agent_host_storage: (default: 1048576M) Storage size for the agent host. This needs to be specified as a string with "M" at the end.
- **override_constraints**: By default, the constraints passed to Juju will use the previous parameters to build something in this format: `arch=amd64 cores=${var.agent_host_cores} mem=${var.agent_host_mem} root-disk=${var.agent_host_storage} root-disk-source=remote virt-type=virtual-machine`. If you need to override this entire line to send it something completely different, use this and the previous `agent_host_*` parameters will be ignored.
5. Initialize terraform and apply
```
```
$ terraform init
$ terraform apply
```
```
3 changes: 3 additions & 0 deletions agent/terraform/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
agent_host_constraints = try(var.override_constraints, "arch=amd64 cores=${var.agent_host_cores} mem=${var.agent_host_mem} root-disk=${var.agent_host_storage} root-disk-source=remote virt-type=virtual-machine")
}
5 changes: 3 additions & 2 deletions agent/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resource "juju_application" "testflinger-agent-host" {
name = var.agent_host_name
model = var.juju_model
name = var.agent_host_name
model = var.juju_model
constraints = local.agent_host_constraints

units = 1

Expand Down
25 changes: 25 additions & 0 deletions agent/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ variable "agent_host_name" {
description = "Name of the agent host juju application"
}

variable "agent_host_cores" {
type = number
description = "Number of cpu cores to use for the agent host"
default = 4
}

variable "agent_host_mem" {
type = string
description = "Amount of RAM to use for the agent host"
default = "32768M"
}

variable "agent_host_storage" {
type = string
description = "Storage size for the agent host"
default = "1048576M"
}

variable "override_constraints" {
type = string
description = "Use if you need to override the constraints built with the other agent_host_* vars"
default = ""
}

variable "config_repo" {
type = string
description = "Repository URL for the agent configs on this agent host"
Expand All @@ -33,3 +57,4 @@ variable "ssh_private_key" {
description = "base64 encoded ssh private key to use on the agent host"
}


0 comments on commit d1f29aa

Please sign in to comment.