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

Add external dependencies fields to helm remote #263

Merged
merged 6 commits into from
Jan 10, 2022
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
10 changes: 8 additions & 2 deletions docs/resources/artifactory_remote_helm_repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ Provides an Artifactory remote `helm` repository resource. This provides helm sp
Official documentation can be found [here](https://www.jfrog.com/confluence/display/JFROG/Package+Management),
although helm is (currently) not listed as a supported format


## Example Usage
## Example Usage
Includes only new and relevant fields, for anything else, see: [generic repo](artifactory_remote_docker_repository.md).
```hcl
Expand All @@ -14,6 +12,10 @@ resource "artifactory_remote_helm_repository" "helm-remote" {
key = "helm-remote-foo25"
url = "https://repo.chartcenter.io/"
helm_charts_base_url = "https://foo.com"
external_dependencies_enabled = true
external_dependencies_patterns = [
"**github.com**"
]
}
```

Expand All @@ -24,3 +26,7 @@ All generic repo arguments are supported, in addition to:

* `key` - (Required) The repository identifier. Must be unique system-wide
* `helm_charts_base_url` - (Optional) - No documentation is available. Hopefully you know what this means
* `external_dependencies_enabled` - (Optional) When set, external dependencies are rewritten.
* `external_dependencies_patterns` - (Optional) An Allow List of Ant-style path expressions that specify where external
dependencies may be downloaded from. By default, this is set to ** which means that dependencies may be downloaded
from any external source.
27 changes: 24 additions & 3 deletions pkg/artifactory/resource_artifactory_remote_helm_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,30 @@ var helmRemoteSchema = mergeSchema(baseRemoteSchema, map[string]*schema.Schema{
Description: "Base URL for the translation of chart source URLs in the index.yaml of virtual repos. " +
"Artifactory will only translate URLs matching the index.yamls hostname or URLs starting with this base url.",
},
"external_dependencies_enabled": {
Type: schema.TypeBool,
Default: false,
Optional: true,
Description: "When set, external dependencies are rewritten.",
},
"external_dependencies_patterns": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
RequiredWith: []string{"external_dependencies_enabled"},
Description: "An Allow List of Ant-style path expressions that specify where external dependencies may be downloaded from. " +
"By default, this is set to ** which means that dependencies may be downloaded from any external source.",
Copy link
Member

Choose a reason for hiding this comment

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

Should we be explicit about the default here with Default: "**",?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be explicit about the default here with Default: "**",?
I think so.

Copy link
Contributor Author

@tenstad tenstad Jan 10, 2022

Choose a reason for hiding this comment

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

I'm not sure how to add a default for a list, tried Default: []string{"**"},.

1 error occurred:
* resource artifactory_remote_helm_repository: external_dependencies_patterns: Default is not valid for lists or sets

hashicorp/terraform-plugin-sdk#142

Copy link
Member

@alexhung alexhung Jan 10, 2022

Choose a reason for hiding this comment

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

Thanks TF!

Artifactory schema documentation has no default value for externalDependenciesPatterns so is "**" the implicit default behavior from the API?

},
})

type HelmRemoteRepo struct {
RemoteRepositoryBaseParams
HelmChartsBaseURL string `hcl:"helm_charts_base_url" json:"chartsBaseUrl,omitempty"`
HelmChartsBaseURL string `hcl:"helm_charts_base_url" json:"chartsBaseUrl"`
ExternalDependenciesEnabled bool `hcl:"external_dependencies_enabled" json:"externalDependenciesEnabled"`
ExternalDependenciesPatterns []string `hcl:"external_dependencies_patterns" json:"externalDependenciesPatterns"`
}

func resourceArtifactoryRemoteHelmRepository() *schema.Resource {
Expand All @@ -34,8 +53,10 @@ func resourceArtifactoryRemoteHelmRepository() *schema.Resource {
func unpackhelmRemoteRepo(s *schema.ResourceData) (interface{}, string, error) {
d := &ResourceData{s}
repo := HelmRemoteRepo{
RemoteRepositoryBaseParams: unpackBaseRemoteRepo(s, "helm"),
HelmChartsBaseURL: d.getString("helm_charts_base_url", false),
RemoteRepositoryBaseParams: unpackBaseRemoteRepo(s, "helm"),
HelmChartsBaseURL: d.getString("helm_charts_base_url", false),
ExternalDependenciesEnabled: d.getBool("external_dependencies_enabled", false),
ExternalDependenciesPatterns: d.getList("external_dependencies_patterns"),
}
return repo, repo.Id(), nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ func TestAccRemoteCargoRepository(t *testing.T) {

func TestAccRemoteHelmRepository(t *testing.T) {
resource.Test(mkNewRemoteTestCase("helm", t, map[string]interface{}{
"helm_charts_base_url": "https://github.com/rust-lang/foo.index",
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
"helm_charts_base_url": "https://github.com/rust-lang/foo.index",
"missed_cache_period_seconds": 1800, // https://github.com/jfrog/terraform-provider-artifactory/issues/225
"external_dependencies_enabled": true,
"external_dependencies_patterns": []interface{}{"**github.com**"},
}))
}

Expand Down