Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update resource docs to latest version #174

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion docs/resources/share_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions docs/resources/share_repository_with_all.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion docs/resources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
94 changes: 44 additions & 50 deletions templates/guides/repositories_in_project.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,57 @@
page_title: "Adding repositories to the project"
---

The guide provides information and the example on how to add repositories to the project.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updating the template to match what is published.

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

```hcl
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" {
Expand All @@ -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.
Loading