Description
Describe the bug
Setting the project_environments attribute when creating a repository resource with a set containing unknown values results in an error of the form:
│ Error: Value Conversion Error
│
│ with artifactory_local_docker_v2_repository.local_docker_repositories["third-party-scanned-gcr"],
│ An unexpected error was encountered trying to build a value. This is always an error in the provider. Please report the following to the provider developer:
│
│ Received unknown value, however the target type cannot handle unknown values. Use the corresponding `types` package type or a custom type that handles unknown values.
│
│ Path: [Value(<unknown>)]
│ Target Type: string
│ Suggested Type: basetypes.StringValue](url)
Reproduction Code
terraform {
required_providers {
artifactory = {
source = "registry.terraform.io/jfrog/artifactory"
version = "12.9.2"
}
project = {
source = "registry.terraform.io/jfrog/project"
version = "1.9.3"
}
}
}
provider "artifactory" {
url = var.artifactory_url
access_token = var.jfrog_access_token
}
provider "project" {
url = var.artifactory_url
access_token = var.jfrog_access_token
}
variable "artifactory_url" {
type = string
}
variable "jfrog_access_token" {
type = string
}
locals {
projects = [
{ name = "Third-Party", key = "third-party", description = "Third-Party Repositories" },
]
envs = [
{ name = "scanned", project = "Third-Party" },
]
local_docker_repos = [
{ name = "gcr", env = "scanned", project = "Third-Party" },
]
}
# Output: id == key
# Index: projects.name
resource "project" "projects" {
for_each = { for project in local.projects : project.name => project }
key = each.value.key
display_name = each.value.name # == each.key
description = each.value.description
admin_privileges {
manage_members = true
manage_resources = true
index_resources = true
}
max_storage_in_gibibytes = 10
block_deployments_on_limit = false
email_notification = true
}
# Output: id == name
# Index: envs.name-projects.name
resource "project_environment" "project_environments" {
for_each = { for env in local.envs : "${env.name}-${env.project}" => env }
name = each.value.name
# Use projects.id to establish implicit dependency
project_key = project.projects[each.value.project].id
}
# Notes:
# 1. By default repositories are placed in the global DEV environment
# 2. Even though the JFrog Artifactory Terraform provider documentation
# recommends against using the repository project_key to assign a repo
# to a given project, it appears to be the only one-pass solution as
# a repo cannot be assigned to a project environment unless it is
# already assigned to the corresponding project. See
# https://registry.terraform.io/providers/jfrog/artifactory/latest/docs/resources/local#project_key-1
# 3. It is worth pointing out that the recommeded alternative is actually
# deprecated. See
# https://registry.terraform.io/providers/jfrog/project/latest/docs/resources/project#repos-8
# 4. Perhaps the drift issues that are discussed in the above references
# has been fixed as it has not been observed in practice (when using
# proper Terraform implicit dependencies)
# Index: repos.name-envs.name-projects.name
resource "artifactory_local_docker_v2_repository" "local_docker_repositories" {
for_each = { for repo in local.local_docker_repos : "${repo.name}-${repo.env}-${repo.project}" => repo }
key = "${lower(each.value.project)}-${each.value.env}-${each.value.name}"
project_key = project.projects[each.value.project].id
# Use project_enviroments.id to establish implicit dependency
project_environments = [ project_environment.project_environments["${each.value.env}-${each.value.project}"].id ]
}
Checklist
Artifactory Version: 7.104.12 rev
Terraform Version: v1.11.4
Terraform Provider Version: 12.9.2 or 12.9.3 (when building it from latest source)
License: EnterpriseX license
Self-Hosted
Expected behavior
terraform plan should not error out and terraform apply should deploy changes successfully
Additional context
As the error message shown above suggests, this error results from the use of a Go string array rather than a Terraform types String array. With this modification, the behavior falls in line with expected Terraform behavior. I will submit a pull request with the proposed fix.