Giter Club home page Giter Club logo

Comments (6)

anmoel avatar anmoel commented on July 20, 2024 2

hello @fscellos , hi @XREvo,

thank you for your input. i think it would be better to implement a new data source with name "nexus_repositories" that returns a list of all repositories. Your problem can be fixed like this:

locals {
  npm_repos = [
    "test1",
    "test2",
  ]
  import_npm_repos = { for repo in data.nexus_repositories.all.list : repo.name  => repo if !contains(local.npm_repos, repo.name) }
}

data "nexus_repositories" "all" {
}

import {
  for_each = local.import_npm_repos
  id       = each.value.name
  to       = nexus_repository_npm_hosted.npm[each.key]
}
resource "nexus_repository_npm_hosted" "npm" {
  for_each = local.npm_repos
  name   = each.key
  online = true
  storage {
    blob_store_name                = upper(var.trigramme)
    strict_content_type_validation = true
    write_policy                   = "ALLOW"
  }
}

with this solution it can be implemented with all types of repositories and in the future we can add search arguments to this data resource

from terraform-provider-nexus.

XREvo avatar XREvo commented on July 20, 2024 1

I tried to implement it today. Here is the branch on my fork: https://github.com/XREvo/terraform-provider-nexus/tree/allow-404-response

I added the flag ignore_not_found on each datasource and set up a simple mechanism to detect if API response error must/can be managed:

ignore_not_found, ok := resourceData.Get("ignore_not_found").(bool)
if !ok {
  ignore_not_found = false
}

repo, err := client.Repository.Conan.Proxy.Get(resourceData.Id())
if err != nil {
  if !(ignore_not_found && strings.Contains(err.Error(), "HTTP: 404")) {
    return err
  }
}

But the unit test that i added keep failing with:

--- FAIL: TestAccDataSourceRepositoryAptHostedNotFound (0.98s)
    testing_new_config.go:58: no "id" found in attributes
    testing_new.go:63: no "id" found in attributes
FAIL

This behavior is known on the Terraform's documentation to be met when you do not write a value in the "id" attribute of your state. And as far as I understand an empty string is not considered as a value, because if I inject a random string in the "id" attribute, the test pass.

FYI, the code used to read the data source use this code if we "bypass" the 404 error as previously stated:

if repo == nil {
  resourceData.SetId("")
  return nil
}

Unfortunately @fscellos I don't think we can implement it like you asked.

Maybe another approach would be to use a dedicated data source to find if a repository exists. I'm thinking of a data source like this one :

data "nexus_repository_apt_hosted_exists" "my-repo-exists" {
	name   = 'my-repo-name"
}

It would use the value of "name" as value for "id" and output a "exists" boolean flag to check if it exists or not.

What do you think of it?

from terraform-provider-nexus.

fscellos avatar fscellos commented on July 20, 2024 1

Hello @anmoel , @XREvo

As the nexus go-client used doesn't support yet search API i think using what you suggest (filtering datasources) is a good tradeoff.

Maybe, we can just add an optional "type" filter on this data source in order to control amount of data manipulated in terraform script (even if your example is ok for our use case) (this type data is send back in RepositoryInfo structure from nexus client).

As we already plan this feature in our internal board, i think we'll be able to submit you a PR in a couple of days.

from terraform-provider-nexus.

fscellos avatar fscellos commented on July 20, 2024

Hello. Any Mainteners out there to discuss about this issue ? (i wouldn't like to begin dev on it if i'm not sure to merge it at the end)

from terraform-provider-nexus.

fscellos avatar fscellos commented on July 20, 2024

Hello,

It appears that the suggested DataSource already exist in the provider (ie. "nexus_repository_list").
I just see it as i read the code.

But in my use case i also need to have such a feature for Blob stores, for which no datasource of type "list" exist.

It's not directly link to this issue but i push a PR to introduce, instead, a "nexus_blobstore_list". : PR 442
Fabrice.

from terraform-provider-nexus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.