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

Cyclic dependency when creating terraform code that creates a project and some related repositories. #58

Closed
ricardf opened this issue Oct 28, 2022 · 4 comments · Fixed by #60
Assignees
Labels
bug Something isn't working

Comments

@ricardf
Copy link

ricardf commented Oct 28, 2022

Describe the bug
Using both providers, terraform-provider-project and terraform-provider-artifactory, I create the project, with all the information needed with the attribute "repos" empty. Then, the repositories are created with reference to that project. Repositories are created inside the project.

After a second update, "repos" field will update from having some repositories to having none, as repos are empty. To solve this I need to add the list of repositories created... but I only can add them afterward as there is a dependency between the project and the repositories and the other way around.

Expected behavior
If repos field is not set, it should not be forced to be empty, or in some way, I need to be able to retrieve the repositories associated with the project to add them to that list.

@ricardf ricardf added the bug Something isn't working label Oct 28, 2022
@OSapozhnikov
Copy link

Hello @ricardf !
Like a workaround for this I use lifecycle condition:

lifecycle {
    ignore_changes = [
      repos
    ]
  }

In any case linking repos with project not trivially issue

@alexhung
Copy link
Member

@ricardf The use of lifecycle.ignore_changes suggested by @OSapozhnikov is one workaround.

The way the provider is implemented currently (and the way Terraform state works) means you have to choose which provider you define the project-repo relationship. The simplest and recommended way is to define the list of repo keys in the project provider's repos attribute.

I understand that using the project_key attribute in the Artifactory provider is convenient as well as intuitive. However, the project_key support in the Artifactory API is incomplete. It only supports during repo creation time, and does not support modification so you can't update the project_key on an existing repo (either assign it to or unassign it from a project).

We will update the documentation and include more explanation and recommendation.

alexhung added a commit that referenced this issue Nov 18, 2022
Add recommendation note to repos attribute
@oallauddin
Copy link

@alexhung
I currently use the approach of creating the repositories in one module and then assigning them to the project in a different module. The project module depends on the repositories module. When I assign the repositories to the project it modifies the project environment and project key of the repositories behind the scenes. I ignore these changes so I don't see the state changes. Not sure if you want to mention/document this somewhere.

resource "artifactory_local_maven_repository" "ext_maven_snapshots" {
  key                  = "ext-maven-snapshots"
  max_unique_snapshots = 10
  handle_releases      = false
  handle_snapshots     = true
  description          = "EXT Local Repository for Maven Snapshots"
  xray_index           = true

  lifecycle {
    prevent_destroy = true
    ignore_changes = [
      project_environments,
      project_key
    ]
  }
}

resource "artifactory_local_maven_repository" "ext_maven_releases" {
  key              = "ext-maven-releases"
  handle_releases  = true
  handle_snapshots = false
  description      = "EXT Local Repository for Maven Releases"
  xray_index       = true

  lifecycle {
    prevent_destroy = true
    ignore_changes = [
      project_environments,
      project_key
    ]
  }
}

@alexhung
Copy link
Member

@oallauddin Great suggestion. I'll schedule this addition.

alexhung added a commit that referenced this issue Nov 18, 2022
Add more details on repository configuration to documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants