rename module

pull/97/head
Muhammad Atif Ali 2 years ago
parent d7d92b77ea
commit 89d50ceb7f

@ -6,10 +6,6 @@ terraform {
source = "coder/coder"
version = ">= 0.12"
}
artifactory = {
source = "registry.terraform.io/jfrog/artifactory"
version = "~> 9.8.0"
}
}
}
@ -18,65 +14,22 @@ variable "jfrog_url" {
description = "JFrog instance URL. e.g. https://YYY.jfrog.io"
}
variable "artifactory_access_token" {
type = string
description = "The admin-level access token to use for JFrog."
default = ""
}
variable "username_field" {
type = string
description = "The field to use for the artifactory username. i.e. Coder username or email."
default = "email"
default = "username"
validation {
condition = can(regex("^(email|username)$", var.username_field))
error_message = "username_field must be either 'email' or 'username'"
}
}
variable "auth_method" {
type = string
description = "The authentication method to use for JFrog."
default = "access_token"
validation {
condition = can(regex("^(access_token|oauth)$", var.auth_method))
error_message = "auth_method must be either 'access_token' or 'oauth'"
}
}
variable "external_auth_id" {
type = string
description = "JFrog external auth ID. Default: 'jfrog'"
default = "jfrog"
}
locals {
# The username field to use for artifactory
username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner
artifactory_access_token = var.auth_method == "access_token" ? artifactory_scoped_token.me[0].access_token : data.coder_external_auth.jfrog.access_token
}
# Configure the Artifactory provider
provider "artifactory" {
url = join("/", [var.jfrog_url, "artifactory"])
# Use the OAuth token if auth_method is 'oauth', else use the admin-level token
access_token = var.auth_method == "oauth" ? "dummy" : var.artifactory_access_token
check_license = false
}
resource "artifactory_scoped_token" "me" {
# This is hacky, but on terraform plan the data source gives empty strings,
# which fails validation.
count = var.artifactory_access_token == "" ? 0 : 1
username = length(local.username) > 0 ? local.username : "plan"
scopes = ["applied-permissions/user"]
refreshable = true
}
data "coder_external_auth" "jfrog" {
id = var.external_auth_id
}
variable "agent_id" {
type = string
description = "The ID of a Coder agent."
@ -95,8 +48,17 @@ For example:
EOF
}
locals {
# The username field to use for artifactory
username = var.username_field == "email" ? data.coder_workspace.me.owner_email : data.coder_workspace.me.owner
}
data "coder_workspace" "me" {}
data "coder_external_auth" "jfrog" {
id = var.external_auth_id
}
resource "coder_script" "jfrog" {
agent_id = var.agent_id
display_name = "jfrog"
@ -105,7 +67,7 @@ resource "coder_script" "jfrog" {
JFROG_URL : var.jfrog_url,
JFROG_HOST : replace(var.jfrog_url, "https://", ""),
ARTIFACTORY_USERNAME : local.username,
ARTIFACTORY_ACCESS_TOKEN : local.artifactory_access_token,
ARTIFACTORY_ACCESS_TOKEN : data.coder_external_auth.jfrog.access_token,
REPOSITORY_NPM : lookup(var.package_managers, "npm", ""),
REPOSITORY_GO : lookup(var.package_managers, "go", ""),
REPOSITORY_PYPI : lookup(var.package_managers, "pypi", ""),
Loading…
Cancel
Save