Skip to content

Commit f26527a

Browse files
authored
feat: Add support for using an existing/external workspace (#6)
1 parent 9026e96 commit f26527a

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.73.0
3+
rev: v1.74.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ No modules.
8383
|------|-------------|------|---------|:--------:|
8484
| <a name="input_alert_manager_definition"></a> [alert\_manager\_definition](#input\_alert\_manager\_definition) | The alert manager definition that you want to be applied. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-alert-manager.html) | `string` | `"alertmanager_config: |\n route:\n receiver: 'default'\n receivers:\n - name: 'default'\n"` | no |
8585
| <a name="input_create"></a> [create](#input\_create) | Determines whether a resources will be created | `bool` | `true` | no |
86+
| <a name="input_create_workspace"></a> [create\_workspace](#input\_create\_workspace) | Determines whether a workspace will be created or to use an existing workspace | `bool` | `true` | no |
8687
| <a name="input_rule_group_namespaces"></a> [rule\_group\_namespaces](#input\_rule\_group\_namespaces) | A map of one or more rule group namespace definitions | `map(any)` | `{}` | no |
8788
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
8889
| <a name="input_workspace_alias"></a> [workspace\_alias](#input\_workspace\_alias) | The alias of the prometheus workspace. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html) | `string` | `null` | no |
90+
| <a name="input_workspace_id"></a> [workspace\_id](#input\_workspace\_id) | The ID of an existing workspace to use when `create_workspace` is `false` | `string` | `""` | no |
8991

9092
## Outputs
9193

main.tf

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
locals {
2+
workspace_id = var.create_workspace ? aws_prometheus_workspace.this[0].id : var.workspace_id
3+
}
4+
15
################################################################################
26
# Workspace
37
################################################################################
48

59
resource "aws_prometheus_workspace" "this" {
6-
count = var.create ? 1 : 0
10+
count = var.create && var.create_workspace ? 1 : 0
711

812
alias = var.workspace_alias
913
tags = var.tags
@@ -16,7 +20,7 @@ resource "aws_prometheus_workspace" "this" {
1620
resource "aws_prometheus_alert_manager_definition" "this" {
1721
count = var.create ? 1 : 0
1822

19-
workspace_id = aws_prometheus_workspace.this[0].id
23+
workspace_id = local.workspace_id
2024
definition = var.alert_manager_definition
2125
}
2226

@@ -28,6 +32,6 @@ resource "aws_prometheus_rule_group_namespace" "this" {
2832
for_each = var.create ? var.rule_group_namespaces : {}
2933

3034
name = each.value.name
31-
workspace_id = aws_prometheus_workspace.this[0].id
35+
workspace_id = local.workspace_id
3236
data = each.value.data
3337
}

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ variable "tags" {
1414
# Workspace
1515
################################################################################
1616

17+
variable "create_workspace" {
18+
description = "Determines whether a workspace will be created or to use an existing workspace"
19+
type = bool
20+
default = true
21+
}
22+
23+
variable "workspace_id" {
24+
description = "The ID of an existing workspace to use when `create_workspace` is `false`"
25+
type = string
26+
default = ""
27+
}
28+
1729
variable "workspace_alias" {
1830
description = "The alias of the prometheus workspace. See more in the [AWS Docs](https://docs.aws.amazon.com/prometheus/latest/userguide/AMP-onboard-create-workspace.html)"
1931
type = string

0 commit comments

Comments
 (0)