Skip to content

Commit 24e3539

Browse files
authored
feat: updated to provide bring your own token option (#27)
* feat: updated to provide bring your own token option * fix: re-run docs
1 parent 3ffa50e commit 24e3539

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@ This file will contain any instructional information about this module.
6969
| <a name="input_cloudwatch_log_group_retention"></a> [cloudwatch\_log\_group\_retention](#input\_cloudwatch\_log\_group\_retention) | The number of days to retain logs in the CloudWatch log group. | `number` | `7` | no |
7070
| <a name="input_create_cloudwatch_log_group"></a> [create\_cloudwatch\_log\_group](#input\_create\_cloudwatch\_log\_group) | The name of the CloudWatch log group where agent logs will be sent. | `bool` | `true` | no |
7171
| <a name="input_create_ecs_cluster"></a> [create\_ecs\_cluster](#input\_create\_ecs\_cluster) | Whether to create a new ECS cluster for the agent. | `bool` | `true` | no |
72+
| <a name="input_create_tfe_agent_pool"></a> [create\_tfe\_agent\_pool](#input\_create\_tfe\_agent\_pool) | Option to omit agent pool/token creation | `bool` | `true` | no |
7273
| <a name="input_ecs_cluster_arn"></a> [ecs\_cluster\_arn](#input\_ecs\_cluster\_arn) | ARN of the ECS cluster where the agent will be deployed. | `string` | `"arn:aws:ecs:us-west-2:000000000000:cluster/ecs-basic"` | no |
7374
| <a name="input_extra_env_vars"></a> [extra\_env\_vars](#input\_extra\_env\_vars) | Extra environment variables to pass to the agent container. | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
7475
| <a name="input_hcp_terraform_address"></a> [hcp\_terraform\_address](#input\_hcp\_terraform\_address) | The HTTPS address of the HCP Terraform or HCP Terraform enterprise instance. | `string` | `"https://app.terraform.io"` | no |
7576
| <a name="input_num_agents"></a> [num\_agents](#input\_num\_agents) | The number of agent containers to run. | `number` | `1` | no |
7677
| <a name="input_task_policy_arns"></a> [task\_policy\_arns](#input\_task\_policy\_arns) | ARN(s) of IAM policies to attach to the agent task. Determines what actions the agent can take without requiring additional AWS credentials. | `list(string)` | `[]` | no |
78+
| <a name="input_tfe_agent_pool_name"></a> [tfe\_agent\_pool\_name](#input\_tfe\_agent\_pool\_name) | Terraform agent pool name to be used when agent creation is omitted | `string` | `""` | no |
79+
| <a name="input_tfe_agent_token"></a> [tfe\_agent\_token](#input\_tfe\_agent\_token) | Terraform agent token to be used when agent creation is omitted | `string` | `""` | no |
7780
| <a name="input_use_spot_instances"></a> [use\_spot\_instances](#input\_use\_spot\_instances) | Whether to use Fargate Spot instances. | `bool` | `false` | no |
7881

7982
## Outputs

main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
data "aws_region" "current" {}
22

33
resource "tfe_agent_pool" "ecs_agent_pool" {
4+
count = var.create_tfe_agent_pool ? 1 : 0
45
name = "${var.name}-agent-pool"
56
organization = var.hcp_terraform_org_name
67
}
78

89
resource "tfe_agent_token" "ecs_agent_token" {
9-
agent_pool_id = tfe_agent_pool.ecs_agent_pool.id
10+
count = var.create_tfe_agent_pool ? 1 : 0
11+
agent_pool_id = tfe_agent_pool.ecs_agent_pool[0].id
1012
description = "${var.name}-agent-token"
1113
}
1214

1315
resource "aws_ssm_parameter" "agent_token" {
1416
name = "/hcp-tf-token/${var.hcp_terraform_org_name}/${var.name}"
1517
description = "HCP Terraform agent token"
1618
type = "SecureString"
17-
value = tfe_agent_token.ecs_agent_token.token
19+
value = var.create_tfe_agent_pool ? tfe_agent_token.ecs_agent_token[0].token : var.tfe_agent_token
1820
}
1921

2022
resource "aws_cloudwatch_log_group" "cloudwatch" {

outputs.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
output "agent_pool_name" {
22
description = "Name of the HCP Terraform agent pool."
3-
value = tfe_agent_pool.ecs_agent_pool.name
3+
value = try(tfe_agent_pool.ecs_agent_pool[0].name, var.tfe_agent_pool_name)
44
}
55

66
output "agent_pool_id" {
77
description = "ID of the HCP Terraform agent pool."
8-
value = tfe_agent_pool.ecs_agent_pool.id
8+
value = try(tfe_agent_pool.ecs_agent_pool[0].id, null)
99
}
1010

1111
output "ecs_service_arn" {

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,22 @@ variable "task_policy_arns" {
162162
description = "ARN(s) of IAM policies to attach to the agent task. Determines what actions the agent can take without requiring additional AWS credentials."
163163
default = []
164164
}
165+
166+
variable "create_tfe_agent_pool" {
167+
type = bool
168+
default = true
169+
description = "Option to omit agent pool/token creation"
170+
}
171+
172+
variable "tfe_agent_token" {
173+
type = string
174+
default = ""
175+
description = "Terraform agent token to be used when agent creation is omitted"
176+
sensitive = true
177+
}
178+
179+
variable "tfe_agent_pool_name" {
180+
type = string
181+
default = ""
182+
description = "Terraform agent pool name to be used when agent creation is omitted"
183+
}

0 commit comments

Comments
 (0)