Comments (6)
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.
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.
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.
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.
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)
- runtime error: index out of range [0] with length 0 HOT 1
- Support for email settings HOT 2
- Allow local development on Apple M1
- Workflow fails due to expired Nexus Pro license HOT 1
- Support for Docker Subdomain Connector HOT 5
- Support for `source` when using `nexus_security_user`
- SAML : validate_response_signature no respected
- Update nexus version in tests HOT 1
- pre-commit commitizen not working anymore
- Could not unmarshal list of generic blobstores HOT 1
- bug ? nexus_security_role error when the role is modified
- Not possible to set maven configuration on a nexus_repository_maven_group HOT 5
- nexus_security_ldap resource group_type does not see the actual value HOT 1
- Repository doesn't notice changes to routing rules HOT 3
- Nexus_blobstore_file cannot apply path does not reflect in tf state HOT 1
- Error: Plugin did not respond - panic: runtime error: index out of range [0] with length | by adding Repos
- apt hosted signing info not handled by data source HOT 1
- Support for changing the admin password using terraform
- My Local development env gives invalid resource_type error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terraform-provider-nexus.