@@ -41,33 +41,35 @@ terraform {
41
41
required_providers {
42
42
coder = {
43
43
source = "coder/coder"
44
- version = "~> 0.11.1"
45
44
}
46
45
docker = {
47
46
source = "kreuzwerker/docker"
48
- version = "~> 3.0.1"
49
47
}
50
48
artifactory = {
51
49
source = "registry.terraform.io/jfrog/artifactory"
52
- version = "~> 8.4.0"
53
50
}
54
51
}
55
52
}
56
53
57
- variable "jfrog_host " {
54
+ variable "jfrog_url " {
58
55
type = string
59
- description = "JFrog instance hostname. e.g. YYY.jfrog.io"
56
+ description = "JFrog instance URL. e.g. https://jfrog.example.com"
57
+ # validate the URL to ensure it starts with https:// or http://
58
+ validation {
59
+ condition = can(regex("^https?://", var.jfrog_url))
60
+ error_message = "JFrog URL must start with https:// or http://"
61
+ }
60
62
}
61
63
62
- variable "artifactory_access_token " {
64
+ variable "artifactory_admin_access_token " {
63
65
type = string
64
- description = "The admin-level access token to use for JFrog. "
66
+ description = "The admin-level access token to use for JFrog with scope applied-permissions/admin "
65
67
}
66
68
67
69
# Configure the Artifactory provider
68
70
provider "artifactory" {
69
- url = "https:// ${var.jfrog_host }/artifactory"
70
- access_token = "${var.artifactory_access_token }"
71
+ url = "${var.jfrog_url }/artifactory"
72
+ access_token = "${var.artifactory_admin_access_token }"
71
73
}
72
74
73
75
resource "artifactory_scoped_token" "me" {
@@ -80,7 +82,7 @@ resource "artifactory_scoped_token" "me" {
80
82
When pushing the template, you can pass in the variables using the` --var ` flag:
81
83
82
84
``` shell
83
- coder templates push --var' jfrog_host= YYY.jfrog.io' --var' artifactory_access_token =XXX'
85
+ coder templates push --var' jfrog_url=https:// YYY.jfrog.io' --var' artifactory_admin_access_token =XXX'
84
86
```
85
87
86
88
##Installing JFrog CLI
@@ -118,6 +120,10 @@ locals {
118
120
python = "pypi"
119
121
go = "go"
120
122
}
123
+ # Make sure to use the same field as the username field in the Artifactory
124
+ # It can be either the username or the email address.
125
+ artifactory_username = data.coder_workspace.me.owner_email
126
+ jfrog_host = replace(var.jfrog_url, "^https://", "")
121
127
}
122
128
```
123
129
@@ -133,7 +139,7 @@ resource "coder_agent" "main" {
133
139
set -e
134
140
135
141
# install and start code-server
136
- curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.11.0
142
+ curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server
137
143
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
138
144
139
145
# The jf CLI checks $CI when determining whether to use interactive
@@ -142,26 +148,26 @@ resource "coder_agent" "main" {
142
148
143
149
jf c rm 0 || true
144
150
echo ${artifactory_scoped_token.me.access_token} | \
145
- jf c add --access-token-stdin --urlhttps:// ${var.jfrog_host } 0
151
+ jf c add --access-token-stdin --url ${var.jfrog_url } 0
146
152
147
153
# Configure the `npm` CLI to use the Artifactory "npm" repository.
148
154
cat << EOF > ~/.npmrc
149
155
email = ${data.coder_workspace.me.owner_email}
150
- registry =https:// ${var.jfrog_host }/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
156
+ registry = ${var.jfrog_url }/artifactory/api/npm/${local.artifactory_repository_keys["npm"]}
151
157
EOF
152
158
jf rt curl /api/npm/auth >> .npmrc
153
159
154
160
# Configure the `pip` to use the Artifactory "python" repository.
155
161
mkdir -p ~/.pip
156
162
cat << EOF > ~/.pip/pip.conf
157
163
[global]
158
- index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var .jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
164
+ index-url = https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local .jfrog_host}/artifactory/api/pypi/${local.artifactory_repository_keys["python"]}/simple
159
165
EOF
160
166
161
167
EOT
162
168
# Set GOPROXY to use the Artifactory "go" repository.
163
169
env = {
164
- GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${var .jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
170
+ GOPROXY : "https://${local.artifactory_username}:${artifactory_scoped_token.me.access_token}@${local. .jfrog_host}/artifactory/api/go/${local.artifactory_repository_keys["go"]}"
165
171
}
166
172
}
167
173
```
@@ -192,9 +198,7 @@ following lines into your `startup_script`:
192
198
# Install the JFrog VS Code extension.
193
199
# Find the latest version number at
194
200
# https://open-vsx.org/extension/JFrog/jfrog-vscode-extension.
195
- JFROG_EXT_VERSION=2.4.1
196
- curl -o /tmp/jfrog.vsix -L" https://open-vsx.org/api/JFrog/jfrog-vscode-extension/$JFROG_EXT_VERSION /file/JFrog.jfrog-vscode-extension-$JFROG_EXT_VERSION .vsix"
197
- /tmp/code-server/bin/code-server --install-extension /tmp/jfrog.vsix
201
+ /tmp/code-server/bin/code-server --install-extension jfrog.jfrog-vscode-extension
198
202
```
199
203
200
204
Note that this method will only work if your developers use code-server.
@@ -208,7 +212,7 @@ Artifactory:
208
212
# Configure the `npm` CLI to use the Artifactory "npm" registry.
209
213
cat<< EOF > ~/.npmrc
210
214
email =${data.coder_workspace.me.owner_email}
211
- registry =https:// ${var.jfrog_host } /artifactory/api/npm/npm/
215
+ registry =${var.jfrog_url } /artifactory/api/npm/npm/
212
216
EOF
213
217
jf rt curl /api/npm/auth >> .npmrc
214
218
` ` `
@@ -227,7 +231,7 @@ Artifactory:
227
231
mkdir -p ~/.pip
228
232
cat << EOF > ~/.pip/pip.conf
229
233
[global]
230
- index-url = https://${data.coder_workspace.me.owner} :${artifactory_scoped_token.me.access_token} @${var .jfrog_host} /artifactory/api/pypi/pypi/simple
234
+ index-url = https://${data.coder_workspace.me.owner} :${artifactory_scoped_token.me.access_token} @${local .jfrog_host} /artifactory/api/pypi/pypi/simple
231
235
EOF
232
236
` ` `
233
237
@@ -243,7 +247,7 @@ Add the following environment variable to your `coder_agent` block to configure
243
247
244
248
` ` ` hcl
245
249
env = {
246
- GOPROXY : "https://${data.coder_workspace.me.owner} :${artifactory_scoped_token.me.access_token} @${var .jfrog_host} /artifactory/api/go/go"
250
+ GOPROXY : "https://${data.coder_workspace.me.owner} :${artifactory_scoped_token.me.access_token} @${local .jfrog_host} /artifactory/api/go/go"
247
251
}
248
252
` ` `
249
253