Skip to content

Commit 41ee1ea

Browse files
authored
server-1704 | Terraform format (#139)
* server-1704 - applied terraform format * server-1713 | added new example in ReadMe file * server-1713 | add k8s_namespace in example * added k8s_namespace in readme file Co-authored-by: Atul Singh <[email protected]>
1 parent f49d116 commit 41ee1ea

File tree

7 files changed

+58
-29
lines changed

7 files changed

+58
-29
lines changed

nomad-aws/nomad-autoscaler.tf

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ resource "aws_iam_access_key" "nomad_asg_user" {
1313
resource "aws_iam_user_policy" "nomad_asg_user" {
1414
count = local.autoscaler_type == "user" ? 1 : 0
1515

16-
name = "${var.basename}-nomad-asg-user-policy"
17-
user = aws_iam_user.nomad_asg_user[0].name
16+
name = "${var.basename}-nomad-asg-user-policy"
17+
user = aws_iam_user.nomad_asg_user[0].name
1818
policy = templatefile("${path.module}/template/nomad_asg_policy.tpl", {
1919
"ASG_ARN" = aws_autoscaling_group.clients_asg.arn
2020
})
@@ -24,18 +24,18 @@ resource "aws_iam_user_policy" "nomad_asg_user" {
2424
resource "aws_iam_role" "nomad_role" {
2525
count = local.autoscaler_type == "role" ? 1 : 0
2626

27-
name = "${var.basename}-circleci-nomad-autoscaler-irsa-role"
28-
assume_role_policy = templatefile("${path.module}/template/nomad_irsa_trust_policy.tpl", {
29-
OIDC_PRINCIPAL_ID = lookup(var.enable_irsa, "oidc_principal_id", "")
30-
OIDC_EKS_VARIABLE = lookup(var.enable_irsa, "oidc_eks_variable", "")
31-
K8S_SERVICE_ACCOUNT = lookup(var.enable_irsa, "k8s_service_account", "")
32-
})
27+
name = "${var.basename}-circleci-nomad-autoscaler-irsa-role"
28+
assume_role_policy = templatefile("${path.module}/template/nomad_irsa_trust_policy.tpl", {
29+
OIDC_PRINCIPAL_ID = lookup(var.enable_irsa, "oidc_principal_id", "")
30+
OIDC_EKS_VARIABLE = lookup(var.enable_irsa, "oidc_eks_variable", "")
31+
K8S_SERVICE_ACCOUNT = lookup(var.enable_irsa, "k8s_service_account", "")
32+
})
3333

3434
inline_policy {
35-
name = "${var.basename}-circleci-nomad-autoscaler-role-policy"
36-
policy = templatefile("${path.module}/template/nomad_asg_policy.tpl", {
37-
"ASG_ARN" = aws_autoscaling_group.clients_asg.arn
38-
})
35+
name = "${var.basename}-circleci-nomad-autoscaler-role-policy"
36+
policy = templatefile("${path.module}/template/nomad_asg_policy.tpl", {
37+
"ASG_ARN" = aws_autoscaling_group.clients_asg.arn
38+
})
3939
}
40-
tags = local.tags
40+
tags = local.tags
4141
}

nomad-aws/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ variable "enable_irsa" {
117117

118118

119119
locals {
120-
tags = merge ({ "environment" = var.basename}, var.instance_tags)
120+
tags = merge({ "environment" = var.basename }, var.instance_tags)
121121

122122
# If nomad_auto_scaler is true and enable_irsa is empty - set autoscaler_type=user
123123
# If nomad_auto_scaler is true and enable_irsa is not empty - set autoscaler_type=role

nomad-gcp/README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,38 @@ output "module" {
2929
}
3030
```
3131

32-
There are more examples in the `examples` directory.
32+
Use latest codebase:
33+
34+
```Terraform
35+
provider "google-beta" {
36+
project = "my-project"
37+
region = "us-east1"
38+
zone = "us-east1-a"
39+
}
40+
41+
module "nomad" {
42+
# we are using latest code for gcp nomad client here, but We strongly recommend pinning the version using ref=<<release tag>> as in above example
43+
source = ""git::https://github.com/CircleCI-Public/server-terraform.git//nomad-gcp"
44+
45+
name = "test"
46+
zone = "us-east1-a"
47+
region = "us-east1"
48+
network = "default"
49+
subnetwork = "default"
50+
server_endpoint = "nomad.example.com:4647"
51+
52+
# Autoscaling for Managed Instance Group
53+
nomad_auto_scaler = true # If true, will generate a service account to be used by nomad-autoscaler. The is output in the file nomad-as-key.json if enable_workload_identity is false
54+
enable_workload_identity = false # If using GCP work identities rather than static keys in CircleCI Server
55+
k8s_namespace = "circleci-server" # If enable_workload_identity is true, provide k8s_namespace else leave as is
56+
}
57+
58+
output "module" {
59+
value = module.nomad
60+
}
61+
```
62+
63+
There are more examples in the [examples](./examples/) directory.
3364

3465
## Requirements
3566

@@ -86,7 +117,6 @@ There are more examples in the `examples` directory.
86117
| unsafe\_disable\_mtls | Disables mTLS between nomad client and servers. Compromises the authenticity and confidentiality of client-server communication. Should not be set to true in any production setting | `bool` | `false` | no |
87118
| zone | GCP compute zone to deploy nomad clients into (e.g us-east1-a) | `string` | n/a | yes |
88119
| enable_workload_identity | Enable nomad service account as gcp workload identity | `bool` | `false` | no |
89-
| project | GCP Project ID | `string` | n/a | Yes, if enable_workload_identity is true |
90120
| k8s_namespace | k8s namespace where application is installed | `string` | `circleci-server` | Yes, if enable_workload_identity is true |
91121

92122
## Outputs

nomad-gcp/examples/basic/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,17 @@ variable "enable_workload_identity" {
6363
description = "If true, Workload Identity will be used rather than static credentials'"
6464
}
6565

66+
variable "k8s_namespace" {
67+
type = string
68+
default = "circleci-server"
69+
description = "If enable_workload_identity is true, provide application k8s namespace"
70+
}
71+
6672
variable "machine_type" {
6773
type = string
6874
default = "n2-standard-8"
6975
}
7076

71-
7277
provider "google-beta" {
7378
project = var.project
7479
region = var.region
@@ -98,7 +103,7 @@ module "nomad" {
98103
max_replicas = var.max_replicas # Max and Min replica values should match the values intended to be used by nomad autoscaler in CircleCI Server
99104
min_replicas = var.min_replicas
100105
enable_workload_identity = var.enable_workload_identity # If using GCP work identities rather than static keys in CircleCI Server
101-
106+
k8s_namespace = var.k8s_namespace # If enable_workload_identity is true, provide k8s_namespace else leave as is
102107
}
103108

104109
output "module" {

nomad-gcp/examples/basic/terraform.tfvars_template

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ subnetwork = "default"
77
min_replicas = 1
88
nomad_auto_scaler = true
99
server_endpoint = "nomad.exmaple.com:4647"
10-
enable_workload_identity = true
11-
machine_type = "n2-standard-8"
12-
k8s_namespace = "circleci-server" # Yes, if enable_workload_identity is true
10+
machine_type = "n2-sqtandard-8"
11+
enable_workload_identity = false
12+
k8s_namespace = "circleci-server" # You must set k8s_namespace if enable_workload_identity is true

nomad-gcp/nomad-autoscaler.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "google_service_account_iam_binding" "nomad_as_work_identity_k8s" {
2828
service_account_id = google_service_account.nomad_as_service_account[0].name
2929
role = "roles/iam.workloadIdentityUser"
3030
members = [
31-
"serviceAccount:${var.project}.svc.id.goog[${var.k8s_namespace}/nomad-autoscaler]",
31+
"serviceAccount:${data.google_project.project.project_id}.svc.id.goog[${var.k8s_namespace}/nomad-autoscaler]",
3232
]
3333
}
3434

nomad-gcp/variables.tf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,4 @@ variable "k8s_namespace" {
149149
type = string
150150
default = "circleci-server"
151151
description = "If enable_workload_identity is true, provide application k8s namespace"
152-
}
153-
154-
variable "project" {
155-
type = string
156-
default = "project-id"
157-
description = "GCP Project ID"
158-
}
152+
}

0 commit comments

Comments
 (0)