Skip to content

Commit 6d2a78f

Browse files
feat: Add support for service account and service account token resources (#36)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent 8bc9d78 commit 6d2a78f

File tree

10 files changed

+115
-9
lines changed

10 files changed

+115
-9
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
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.88.0
3+
rev: v1.92.1
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
@@ -24,7 +24,7 @@ repos:
2424
- '--args=--only=terraform_unused_required_providers'
2525
- id: terraform_validate
2626
- repo: https://github.com/pre-commit/pre-commit-hooks
27-
rev: v4.5.0
27+
rev: v4.6.0
2828
hooks:
2929
- id: check-merge-conflict
3030
- id: end-of-file-fixer

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
8080
| Name | Version |
8181
|------|---------|
8282
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
83-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
83+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
8484

8585
## Providers
8686

8787
| Name | Version |
8888
|------|---------|
89-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
89+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
9090

9191
## Modules
9292

@@ -101,6 +101,8 @@ No modules.
101101
| [aws_grafana_workspace.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace) | resource |
102102
| [aws_grafana_workspace_api_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace_api_key) | resource |
103103
| [aws_grafana_workspace_saml_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace_saml_configuration) | resource |
104+
| [aws_grafana_workspace_service_account.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace_service_account) | resource |
105+
| [aws_grafana_workspace_service_account_token.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/grafana_workspace_service_account_token) | resource |
104106
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
105107
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
106108
| [aws_iam_role_policy_attachment.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
@@ -170,6 +172,8 @@ No modules.
170172
| <a name="input_vpc_configuration"></a> [vpc\_configuration](#input\_vpc\_configuration) | The configuration settings for an Amazon VPC that contains data sources for your Grafana workspace to connect to | `any` | `{}` | no |
171173
| <a name="input_workspace_api_keys"></a> [workspace\_api\_keys](#input\_workspace\_api\_keys) | Map of workspace API key definitions to create | `any` | `{}` | no |
172174
| <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 |
175+
| <a name="input_workspace_service_account_tokens"></a> [workspace\_service\_account\_tokens](#input\_workspace\_service\_account\_tokens) | Map of workspace service account tokens to create | `any` | `{}` | no |
176+
| <a name="input_workspace_service_accounts"></a> [workspace\_service\_accounts](#input\_workspace\_service\_accounts) | Map of workspace service account definitions to create | `any` | `{}` | no |
173177

174178
## Outputs
175179

@@ -191,6 +195,8 @@ No modules.
191195
| <a name="output_workspace_iam_role_policy_name"></a> [workspace\_iam\_role\_policy\_name](#output\_workspace\_iam\_role\_policy\_name) | IAM Policy name of the Grafana workspace IAM role |
192196
| <a name="output_workspace_iam_role_unique_id"></a> [workspace\_iam\_role\_unique\_id](#output\_workspace\_iam\_role\_unique\_id) | Stable and unique string identifying the IAM role |
193197
| <a name="output_workspace_id"></a> [workspace\_id](#output\_workspace\_id) | The ID of the Grafana workspace |
198+
| <a name="output_workspace_service_account_tokens"></a> [workspace\_service\_account\_tokens](#output\_workspace\_service\_account\_tokens) | The workspace service account tokens created including their attributes |
199+
| <a name="output_workspace_service_accounts"></a> [workspace\_service\_accounts](#output\_workspace\_service\_accounts) | The workspace service accounts created including their attributes |
194200
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
195201

196202
## License

examples/complete/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ Note that this example may create resources which will incur monetary charges on
2424
| Name | Version |
2525
|------|---------|
2626
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
27-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
27+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.59 |
2828

2929
## Providers
3030

3131
| Name | Version |
3232
|------|---------|
33-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
33+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.59 |
3434

3535
## Modules
3636

@@ -69,6 +69,8 @@ No inputs.
6969
| <a name="output_workspace_iam_role_policy_name"></a> [workspace\_iam\_role\_policy\_name](#output\_workspace\_iam\_role\_policy\_name) | IAM Policy name of the Grafana workspace IAM role |
7070
| <a name="output_workspace_iam_role_unique_id"></a> [workspace\_iam\_role\_unique\_id](#output\_workspace\_iam\_role\_unique\_id) | Stable and unique string identifying the IAM role |
7171
| <a name="output_workspace_id"></a> [workspace\_id](#output\_workspace\_id) | The ID of the Grafana workspace |
72+
| <a name="output_workspace_service_account_tokens"></a> [workspace\_service\_account\_tokens](#output\_workspace\_service\_account\_tokens) | The workspace service account tokens created including their attributes |
73+
| <a name="output_workspace_service_accounts"></a> [workspace\_service\_accounts](#output\_workspace\_service\_accounts) | The workspace service accounts created including their attributes |
7274
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
7375

7476
Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-managed-service-grafana/blob/main/LICENSE).

examples/complete/main.tf

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module "managed_grafana" {
3636
data_sources = ["CLOUDWATCH", "PROMETHEUS", "XRAY"]
3737
notification_destinations = ["SNS"]
3838
stack_set_name = local.name
39-
grafana_version = "9.4"
39+
grafana_version = "10.4"
4040

4141
configuration = jsonencode({
4242
unifiedAlerting = {
@@ -80,6 +80,36 @@ module "managed_grafana" {
8080
}
8181
}
8282

83+
# Workspace service accounts
84+
workspace_service_accounts = {
85+
viewer = {
86+
grafana_role = "VIEWER"
87+
}
88+
editor = {
89+
name = "editor-example"
90+
grafana_role = "EDITOR"
91+
}
92+
admin = {
93+
grafana_role = "ADMIN"
94+
}
95+
}
96+
97+
workspace_service_account_tokens = {
98+
viewer = {
99+
service_account_key = "viewer"
100+
seconds_to_live = 3600
101+
}
102+
editor = {
103+
name = "editor-example"
104+
service_account_key = "editor"
105+
seconds_to_live = 3600
106+
}
107+
admin = {
108+
service_account_key = "admin"
109+
seconds_to_live = 3600
110+
}
111+
}
112+
83113
# Workspace IAM role
84114
create_iam_role = true
85115
iam_role_name = local.name

examples/complete/outputs.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ output "workspace_grafana_version" {
2929
output "workspace_api_keys" {
3030
description = "The workspace API keys created including their attributes"
3131
value = module.managed_grafana.workspace_api_keys
32+
sensitive = true
33+
}
34+
35+
################################################################################
36+
# Workspace Service Account
37+
################################################################################
38+
39+
output "workspace_service_accounts" {
40+
description = "The workspace service accounts created including their attributes"
41+
value = module.managed_grafana.workspace_service_accounts
42+
sensitive = true
43+
}
44+
45+
output "workspace_service_account_tokens" {
46+
description = "The workspace service account tokens created including their attributes"
47+
value = module.managed_grafana.workspace_service_account_tokens
48+
sensitive = true
3249
}
3350

3451
################################################################################

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.59"
88
}
99
}
1010
}

main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ resource "aws_grafana_workspace_api_key" "this" {
110110
workspace_id = local.workspace_id
111111
}
112112

113+
################################################################################
114+
# Workspace Service Account
115+
################################################################################
116+
117+
resource "aws_grafana_workspace_service_account" "this" {
118+
for_each = { for k, v in var.workspace_service_accounts : k => v if var.create }
119+
120+
name = try(each.value.name, each.key)
121+
grafana_role = each.value.grafana_role
122+
workspace_id = local.workspace_id
123+
}
124+
125+
resource "aws_grafana_workspace_service_account_token" "this" {
126+
for_each = { for k, v in var.workspace_service_account_tokens : k => v if var.create }
127+
128+
name = try(each.value.name, each.key)
129+
service_account_id = try(aws_grafana_workspace_service_account.this[each.value.service_account_key].service_account_id, each.value.service_account_id)
130+
seconds_to_live = each.value.seconds_to_live
131+
workspace_id = local.workspace_id
132+
}
133+
113134
################################################################################
114135
# Workspace IAM Role
115136
################################################################################

outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@ output "workspace_api_keys" {
3131
value = aws_grafana_workspace_api_key.this
3232
}
3333

34+
################################################################################
35+
# Workspace Service Account
36+
################################################################################
37+
38+
output "workspace_service_accounts" {
39+
description = "The workspace service accounts created including their attributes"
40+
value = aws_grafana_workspace_service_account_token.this
41+
}
42+
43+
output "workspace_service_account_tokens" {
44+
description = "The workspace service account tokens created including their attributes"
45+
value = aws_grafana_workspace_service_account_token.this
46+
}
47+
3448
################################################################################
3549
# Workspace IAM Role
3650
################################################################################

variables.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,22 @@ variable "workspace_api_keys" {
196196
default = {}
197197
}
198198

199+
################################################################################
200+
# Workspace Service Account
201+
################################################################################
202+
203+
variable "workspace_service_accounts" {
204+
description = "Map of workspace service account definitions to create"
205+
type = any
206+
default = {}
207+
}
208+
209+
variable "workspace_service_account_tokens" {
210+
description = "Map of workspace service account tokens to create"
211+
type = any
212+
default = {}
213+
}
214+
199215
################################################################################
200216
# Workspace SAML Configuration
201217
################################################################################

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.0"
7+
version = ">= 5.59"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)