From 936fb4070328f12ee87ec4057c7e289d06464077 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 13 Nov 2024 15:09:25 -0800 Subject: [PATCH] Update resource docs to latest version --- docs/resources/group.md | 2 +- docs/resources/share_repository.md | 6 +- docs/resources/share_repository_with_all.md | 8 +- docs/resources/user.md | 2 +- templates/guides/repositories_in_project.md | 94 ++++++++++----------- 5 files changed, 57 insertions(+), 55 deletions(-) diff --git a/docs/resources/group.md b/docs/resources/group.md index 83dd7e26..b6ea8534 100644 --- a/docs/resources/group.md +++ b/docs/resources/group.md @@ -27,7 +27,7 @@ resource "project_group" "mygroup" { - `name` (String) The name of an artifactory group. - `project_key` (String) The key of the project to which the group should be assigned to. -- `roles` (Set of String) List of pre-defined Project or custom roles +- `roles` (Set of String) List of pre-defined Project or custom roles. Must have at least 1 role, e.g. 'Viewer' ### Read-Only diff --git a/docs/resources/share_repository.md b/docs/resources/share_repository.md index 5f132cbe..079d6697 100644 --- a/docs/resources/share_repository.md +++ b/docs/resources/share_repository.md @@ -3,7 +3,8 @@ page_title: "project_share_repository Resource - terraform-provider-project" subcategory: "" description: |- - Share a local or remote repository with a list of projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. Only available for Artifactory 7.90.1 or later. + Share a local or remote repository with a list of projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. + ->Only available for Artifactory 7.90.1 or later. --- # project_share_repository (Resource) @@ -28,6 +29,9 @@ resource "project_share_repository" "myprojectsharerepo" { - `repo_key` (String) The key of the repository. - `target_project_key` (String) The project key to which the repository should be shared with. + +### Optional + - `read_only` (Boolean) Share repository with a Project in Read-Only mode to avoid any changes or modifications of the shared content. ->Only available for Artifactory 7.94.0 or later. diff --git a/docs/resources/share_repository_with_all.md b/docs/resources/share_repository_with_all.md index 1847edc5..ddb09988 100644 --- a/docs/resources/share_repository_with_all.md +++ b/docs/resources/share_repository_with_all.md @@ -3,7 +3,8 @@ page_title: "project_share_repository_with_all Resource - terraform-provider-project" subcategory: "" description: |- - Share a local or remote repository with all projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. Only available for Artifactory 7.90.1 or later. + Share a local or remote repository with all projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. + ->Only available for Artifactory 7.90.1 or later. --- # project_share_repository_with_all (Resource) @@ -26,7 +27,10 @@ resource "project_share_repository_with_all" "myprojectsharerepo" { ### Required - `repo_key` (String) The key of the repository. -- `read_only` (Boolean) Share repository with a Project in Read-Only mode to avoid any changes or modifications of the shared content. + +### Optional + +- `read_only` (Boolean) Share repository with all Projects in Read-Only mode to avoid any changes or modifications of the shared content. ->Only available for Artifactory 7.94.0 or later. diff --git a/docs/resources/user.md b/docs/resources/user.md index 30245bec..bd4da033 100644 --- a/docs/resources/user.md +++ b/docs/resources/user.md @@ -27,7 +27,7 @@ resource "project_user" "myuser" { - `name` (String) The name of an artifactory user. - `project_key` (String) The key of the project to which the user should be assigned to. -- `roles` (Set of String) List of pre-defined Project or custom roles +- `roles` (Set of String) List of pre-defined Project or custom roles. Must have at least 1 role, e.g. 'Viewer' ### Optional diff --git a/templates/guides/repositories_in_project.md b/templates/guides/repositories_in_project.md index 274f16a4..8f9871aa 100644 --- a/templates/guides/repositories_in_project.md +++ b/templates/guides/repositories_in_project.md @@ -2,43 +2,34 @@ page_title: "Adding repositories to the project" --- -The guide provides information and the example on how to add repositories to the project. +The guide provides information and the example on how to add repositories to the project. -## Artifactory behavior +## Resources creation sequence -The attribute `project_environments` (`environments` in the API call) is ignored by Artifactory, if the repository is not assigned to an existing project. -That attribute can only be set to the repository if it's assigned to the project already. -The project can't be created with the list of non-existing repositories, and the repository can't be assigned to non-existing project. -Thus, if the project and the repository/repositories are created at the same time in one Terraform configuration, we have a state drift -for the `project_environments` attribute. +1. Create `project` resource +2. Create repository resource(s), the ordering of these first 2 steps doesn't matter. +3. Create `project_repository` resource, using attributes from #1 and #2 as reference values for this resource -This is happening, because the repositories need to be created first, then the project with the list of repositories gets -created. Since `project_environments` attribute is ignored in the first step, we will only have this attribute in the Terraform state, and -not in the actual repository properties. +## Artifactory repository state drift -On the next step, when the repo gets assigned to the project by the project resource, the default value `DEV` is assigned to -repositories' `project_environments` attribute. If the desired value on the first step was `DEV`, then the values match and no state -drift occurs. But if the desired value was `PROD`, we will get an error message when updating the config by `terraform plan`/`terraform apply`. +When a repository in Artifactory is assigned to a project, the API field `projectKey` is set with the project's key. While using the `project_key` attribute in the Artifactory provider to set the project key for the repository is possible, we **strongly** recommend using the `project_repository` resource instead. -``` - # artifactory_local_docker_v2_repository.docker-v2-local will be updated in-place - ~ resource "artifactory_local_docker_v2_repository" "docker-v2-local" { - id = "myproj-docker-v2-local" - ~ project_environments = [ - - "DEV", - + "PROD", - ] - } -``` - -## Workaround +However the next time `terraform plan` or `terraform apply` is run, a state drift will occur for the `project_key` attribute. To avoid this, use Terraform meta argument `lifecycle.ignore_changes`. e.g. -~> In the Project provider documentation, we strongly recommend using the `repos` attribute to manage the list of repositories. -Do not use `project_key` attribute of the repository resource. +```hcl +resource "artifactory_local_docker_v2_repository" "docker-v2-local" { + key = "myproj-docker-v2-local" + tag_retention = 3 + max_unique_tags = 5 + project_environments = ["PROD"] -Unfortunately, we can't fix the behavior described above right now. The workaround is simply to run `terraform apply` twice. -When the user applies the configuration second time, the repository is already assigned to the project, and `project_environments` -attribute won't be ignored. + lifecycle { + ignore_changes = [ + project_key + ] + } +} +``` ## Full HCL example @@ -46,31 +37,22 @@ attribute won't be ignored. terraform { required_providers { artifactory = { - source = "registry.terraform.io/jfrog/artifactory" - version = "6.21.4" + source = "jfrog/artifactory" + version = "11.5.0" } project = { - source = "registry.terraform.io/jfrog/project" - version = "1.1.1" + source = "jfrog/project" + version = "1.7.1" } } } provider "artifactory" { - // supply ARTIFACTORY_ACCESS_TOKEN / JFROG_ACCESS_TOKEN / ARTIFACTORY_API_KEY and ARTIFACTORY_URL / JFROG_URL as env vars + // supply JFROG_ACCESS_TOKEN / JFROG_URL as env vars } -resource "artifactory_local_docker_v2_repository" "docker-v2-local" { - key = "myproj-docker-v2-local" - tag_retention = 3 - max_unique_tags = 5 - project_environments = ["PROD"] - - lifecycle { - ignore_changes = [ - project_key - ] - } +provider "project" { + // supply JFROG_ACCESS_TOKEN / JFROG_URL as env vars } resource "project" "myproject" { @@ -85,11 +67,23 @@ resource "project" "myproject" { max_storage_in_gibibytes = 10 block_deployments_on_limit = false email_notification = true +} - repos = ["myproj-docker-v2-local"] +resource "artifactory_local_docker_v2_repository" "docker-v2-local" { + key = "docker-v2-local" + tag_retention = 3 + max_unique_tags = 5 + project_environments = ["PROD"] - depends_on = [ artifactory_local_docker_v2_repository.docker-v2-local ] + lifecycle { + ignore_changes = [ + project_key + ] + } } + +resource "project_repository" "myproject-docker-v2-local" { + project_key = project.myproject.key + key = artifactory_local_docker_v2_repository.docker-v2-local.key +} ``` -~> Apply `lifecycle.ignore_changes` to `project_key` attribute, otherwise it will be removed from the repository, -which means it will be unassigned from the project on the configuration update.