Skip to content

Commit 8e3f48c

Browse files
authored
fix(jfrog-token)!: add attributes to fine control the token behaviour (coder#100)
1 parent 73ef0dc commit 8e3f48c

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

jfrog-token/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ Install the JF CLI and authenticate package managers with Artifactory using Arti
1616
module "jfrog" {
1717
source = "https://registry.coder.com/modules/jfrog-token"
1818
agent_id = coder_agent.example.id
19-
jfrog_url = "https://YYYY.jfrog.io"
20-
artifactory_access_token = var.artifactory_access_token # An admin access token
19+
jfrog_url = "https://XXXX.jfrog.io"
20+
artifactory_access_token = var.artifactory_access_token
2121
package_managers = {
2222
"npm": "npm",
2323
"go": "go",
@@ -26,7 +26,7 @@ module "jfrog" {
2626
}
2727
```
2828

29-
Get a JFrog access token from your Artifactory instance. The token must have admin permissions. It is recommended to store the token in a secret terraform variable.
29+
Get a JFrog access token from your Artifactory instance. The token must be an [admin token](https://registry.terraform.io/providers/jfrog/artifactory/latest/docs#access-token). It is recommended to store the token in a secret terraform variable.
3030

3131
```hcl
3232
variable "artifactory_access_token" {

jfrog-token/main.tf

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,28 @@ variable "artifactory_access_token" {
2323
description = "The admin-level access token to use for JFrog."
2424
}
2525

26+
variable "check_license" {
27+
type = bool
28+
description = "Toggle for pre-flight checking of Artifactory license. Default to `true`."
29+
default = true
30+
}
31+
32+
variable "refreshable" {
33+
type = bool
34+
description = "Is this token refreshable? Default is `false`."
35+
default = false
36+
}
37+
38+
variable "expires_in" {
39+
type = number
40+
description = "The amount of time, in seconds, it would take for the token to expire."
41+
default = null
42+
}
43+
2644
variable "username_field" {
2745
type = string
28-
description = "The field to use for the artifactory username. i.e. Coder username or email."
29-
default = "email"
46+
description = "The field to use for the artifactory username. Default `username`."
47+
default = "username"
3048
validation {
3149
condition = can(regex("^(email|username)$", var.username_field))
3250
error_message = "username_field must be either 'email' or 'username'"
@@ -58,16 +76,18 @@ locals {
5876

5977
# Configure the Artifactory provider
6078
provider "artifactory" {
61-
url = join("/", [var.jfrog_url, "artifactory"])
62-
access_token = var.artifactory_access_token
79+
url = join("/", [var.jfrog_url, "artifactory"])
80+
access_token = var.artifactory_access_token
81+
check_license = var.check_license
6382
}
6483

6584
resource "artifactory_scoped_token" "me" {
6685
# This is hacky, but on terraform plan the data source gives empty strings,
6786
# which fails validation.
6887
username = length(local.username) > 0 ? local.username : "dummy"
6988
scopes = ["applied-permissions/user"]
70-
refreshable = true
89+
refreshable = var.refreshable
90+
expires_in = var.expires_in
7191
}
7292

7393
data "coder_workspace" "me" {}

0 commit comments

Comments
 (0)