Skip to content

Commit acc56b0

Browse files
committed
back to curl
1 parent b2349d3 commit acc56b0

File tree

6 files changed

+264
-180
lines changed

6 files changed

+264
-180
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
data "http" "coder_healthy" {
2+
url = local.deployments.primary.url
3+
// Wait up to 5 minutes for DNS to propagate
4+
retry {
5+
attempts = 30
6+
min_delay_ms = 10000
7+
}
8+
9+
lifecycle {
10+
postcondition {
11+
condition = self.status_code == 200
12+
error_message = "${self.url} returned an unhealthy status code"
13+
}
14+
}
15+
16+
depends_on = [helm_release.coder_primary, cloudflare_record.coder["primary"]]
17+
}
18+
19+
resource "null_resource" "api_key" {
20+
provisioner "local-exec" {
21+
interpreter = ["/bin/bash", "-c"]
22+
command = <<EOF
23+
curl '${local.deployments.primary.url}/api/v2/users/first' \
24+
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}","username":"${local.coder_admin_user}","name":"${local.coder_admin_full_name}","trial":false}' \
25+
--insecure --silent --output /dev/null
26+
27+
session_token=$(curl '${local.deployments.primary.url}/api/v2/users/login' \
28+
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}"}' \
29+
--insecure --silent | jq -r .session_token)
30+
31+
api_key=$(curl '${local.deployments.primary.url}/users/me/keys/tokens' \
32+
-H "Coder-Session-Token: $${session_token}" \
33+
--data-raw '{"token_name":"terraform","scope":"all"}' \
34+
--insecure --silent | jq -r .key)
35+
36+
mkdir -p ${path.module}/.coderv2
37+
echo -n $${api_key} > ${path.module}/.coderv2/api_key
38+
EOF
39+
}
40+
41+
depends_on = [data.http.coder_healthy]
42+
}
43+
44+
data "local_file" "api_key" {
45+
filename = "${path.module}/.coderv2/api_key"
46+
depends_on = [null_resource.api_key]
47+
}
48+
49+
resource "null_resource" "license" {
50+
provisioner "local-exec" {
51+
interpreter = ["/bin/bash", "-c"]
52+
command = <<EOF
53+
curl '${local.deployments.primary.url}/api/v2/licenses' \
54+
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
55+
--data-raw '{"license":"${var.coder_license}"}' \
56+
--insecure --silent --output /dev/null
57+
EOF
58+
}
59+
}
60+
61+
resource "null_resource" "proxy_tokens" {
62+
provisioner "local-exec" {
63+
interpreter = ["/bin/bash", "-c"]
64+
command = <<EOF
65+
europe_token=$(curl '${local.deployments.primary.url}/api/v2/workspaceproxies' \
66+
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
67+
--data-raw '{"name":"europe","display_name":"Europe","icon":"/emojis/1f950.png"}' \
68+
--insecure --silent | jq -r .proxy_token)
69+
70+
asia_token=$(curl '${local.deployments.primary.url}/api/v2/workspaceproxies' \
71+
-H "Coder-Session-Token: ${trimspace(data.local_file.api_key.content)}" \
72+
--data-raw '{"name":"asia","display_name":"Asia","icon":"/emojis/1f35b.png"}' \
73+
--insecure --silent | jq -r .proxy_token)
74+
75+
echo -n $${europe_token} > ${path.module}/.coderv2/europe_proxy_token
76+
echo -n $${asia_token} > ${path.module}/.coderv2/asia_proxy_token
77+
EOF
78+
}
79+
80+
depends_on = [data.http.coder_healthy]
81+
}
82+
83+
data "local_file" "europe_proxy_token" {
84+
filename = "${path.module}/.coderv2/europe_proxy_token"
85+
depends_on = [null_resource.proxy_tokens]
86+
}
87+
88+
data "local_file" "asia_proxy_token" {
89+
filename = "${path.module}/.coderv2/asia_proxy_token"
90+
depends_on = [null_resource.proxy_tokens]
91+
}
Lines changed: 72 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,3 @@
1-
data "http" "coder_healthy" {
2-
url = local.deployments.primary.url
3-
// Wait up to 5 minutes for DNS to propagate
4-
retry {
5-
attempts = 30
6-
min_delay_ms = 10000
7-
}
8-
9-
lifecycle {
10-
postcondition {
11-
condition = self.status_code == 200
12-
error_message = "${self.url} returned an unhealthy status code"
13-
}
14-
}
15-
16-
depends_on = [helm_release.coder_primary, cloudflare_record.coder["primary"]]
17-
}
18-
19-
resource "null_resource" "api_key" {
20-
provisioner "local-exec" {
21-
interpreter = ["/bin/bash", "-c"]
22-
command = <<EOF
23-
curl '${local.deployments.primary.url}/api/v2/users/first' \
24-
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}","username":"${local.coder_admin_user}","name":"${local.coder_admin_full_name}","trial":false}' \
25-
--insecure --silent --output /dev/null
26-
27-
session_token=$(curl '${local.deployments.primary.url}/api/v2/users/login' \
28-
--data-raw $'{"email":"${local.coder_admin_email}","password":"${local.coder_admin_password}"}' \
29-
--insecure --silent | jq -r .session_token)
30-
31-
api_key=$(curl '${local.deployments.primary.url}/users/me/keys/tokens' \
32-
-H "Coder-Session-Token: $${session_token}" \
33-
--data-raw '{"token_name":"terraform","scope":"all"}' \
34-
--insecure --silent | jq -r .key)
35-
36-
mkdir -p ${path.module}/.coderv2
37-
echo -n $${api_key} > ${path.module}/.coderv2/api_key
38-
EOF
39-
}
40-
41-
depends_on = [data.http.coder_healthy]
42-
}
43-
44-
data "local_file" "api_key" {
45-
filename = "${path.module}/.coderv2/api_key"
46-
depends_on = [null_resource.api_key]
47-
}
48-
49-
resource "coderd_license" "license" {
50-
license = var.coder_license
51-
lifecycle {
52-
create_before_destroy = true
53-
}
54-
}
55-
56-
resource "coderd_workspace_proxy" "europe" {
57-
name = "europe"
58-
display_name = "Europe"
59-
icon = "/emojis/1f950.png"
60-
61-
depends_on = [coderd_license.license]
62-
}
63-
64-
resource "coderd_workspace_proxy" "asia" {
65-
name = "asia"
66-
display_name = "Asia"
67-
icon = "/emojis/1f35b.png"
68-
69-
depends_on = [coderd_license.license]
70-
}
71-
721
resource "local_file" "kubernetes_template" {
732
filename = "${path.module}/.coderv2/templates/kubernetes/main.tf"
743
content = <<EOF
@@ -128,12 +57,12 @@ resource "local_file" "kubernetes_template" {
12857
}
12958
resources {
13059
requests = {
131-
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_request}"
132-
"memory" = "${local.scenarios[var.scenario].workspace.mem_request}"
60+
"cpu" = "${local.scenarios[var.scenario].workspaces.cpu_request}"
61+
"memory" = "${local.scenarios[var.scenario].workspaces.mem_request}"
13362
}
13463
limits = {
135-
"cpu" = "${local.scenarios[var.scenario].workspace.cpu_limit}"
136-
"memory" = "${local.scenarios[var.scenario].workspace.mem_limit}"
64+
"cpu" = "${local.scenarios[var.scenario].workspaces.cpu_limit}"
65+
"memory" = "${local.scenarios[var.scenario].workspaces.mem_limit}"
13766
}
13867
}
13968
}
@@ -156,10 +85,72 @@ resource "local_file" "kubernetes_template" {
15685
EOF
15786
}
15887

159-
resource "coderd_template" "kubernetes" {
160-
name = "kubernetes"
161-
versions = [{
162-
directory = "${path.module}/.coderv2/templates/kubernetes"
163-
active = true
164-
}]
88+
resource "kubernetes_config_map" "template" {
89+
provider = kubernetes.primary
90+
91+
metadata {
92+
name = "coder-template"
93+
namespace = kubernetes_namespace.coder_primary.metadata.0.name
94+
}
95+
96+
data = {
97+
"main.tf" = local_file.kubernetes_template.content
98+
}
99+
}
100+
101+
resource "kubernetes_pod" "push_template" {
102+
provider = kubernetes.primary
103+
104+
metadata {
105+
name = "${var.name}-push-template"
106+
namespace = kubernetes_namespace.coder_primary.metadata.0.name
107+
labels = {
108+
"app.kubernetes.io/name" = "${var.name}-push-template"
109+
}
110+
}
111+
spec {
112+
affinity {
113+
node_affinity {
114+
required_during_scheduling_ignored_during_execution {
115+
node_selector_term {
116+
match_expressions {
117+
key = "cloud.google.com/gke-nodepool"
118+
operator = "In"
119+
values = ["${google_container_node_pool.node_pool["primary_misc"].name}"]
120+
}
121+
}
122+
}
123+
}
124+
}
125+
container {
126+
name = "cli"
127+
image = "${var.coder_image_repo}:${var.coder_image_tag}"
128+
command = [
129+
"/opt/coder",
130+
"--verbose",
131+
"--url=${local.deployments.primary.url}",
132+
"--token=${trimspace(data.local_file.api_key.content)}",
133+
"templates",
134+
"push",
135+
"--directory=/template",
136+
"--yes",
137+
"kubernetes"
138+
]
139+
volume_mount {
140+
name = "coder-template"
141+
mount_path = "/template"
142+
}
143+
}
144+
volume {
145+
name = "coder-template"
146+
config_map {
147+
name = kubernetes_config_map.template.metadata.0.name
148+
items {
149+
key = "main.tf"
150+
path = "main.tf"
151+
}
152+
}
153+
}
154+
restart_policy = "Never"
155+
}
165156
}

scaletest/terraform/action/k8s_coder_asia.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "kubernetes_secret" "proxy_token_asia" {
3636
namespace = kubernetes_namespace.coder_asia.metadata.0.name
3737
}
3838
data = {
39-
token = coderd_workspace_proxy.asia.session_token
39+
token = trimspace(data.local_file.asia_proxy_token.content)
4040
}
4141
lifecycle {
4242
ignore_changes = [timeouts, wait_for_service_account_token]

scaletest/terraform/action/k8s_coder_europe.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "kubernetes_secret" "proxy_token_europe" {
3636
namespace = kubernetes_namespace.coder_europe.metadata.0.name
3737
}
3838
data = {
39-
token = coderd_workspace_proxy.europe.session_token
39+
token = trimspace(data.local_file.europe_proxy_token.content)
4040
}
4141
lifecycle {
4242
ignore_changes = [timeouts, wait_for_service_account_token]

scaletest/terraform/action/vars.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ variable "provisionerd_image_tag" {
8787
}
8888

8989
// Traffic
90-
variable "traffic_bytes_per_tick" {
91-
description = "Number of bytes to send per tick."
92-
default = 1024
93-
}
90+
# variable "traffic_bytes_per_tick" {
91+
# description = "Number of bytes to send per tick."
92+
# default = 1024
93+
# }
9494

95-
variable "traffic_tick_interval" {
96-
description = "Interval between ticks."
97-
default = "1s"
98-
}
95+
# variable "traffic_tick_interval" {
96+
# description = "Interval between ticks."
97+
# default = "10s"
98+
# }
9999

100100
variable "workspace_count" {
101101
description = "Number of workspaces to create."
@@ -104,5 +104,5 @@ variable "workspace_count" {
104104

105105
variable "workspace_create_concurrency" {
106106
description = "Number of workspaces to create concurrently."
107-
default = 1
107+
default = 10
108108
}

0 commit comments

Comments
 (0)