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

feat(repository): Add resource and data source for hosted gitlfs repository #297

Merged
merged 1 commit into from
Jun 24, 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
53 changes: 53 additions & 0 deletions docs/data-sources/repository_gitlfs_hosted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
page_title: "Data Source nexus_repository_gitlfs_hosted"
subcategory: "Repository"
description: |-
Use this data source to get an existing hosted yum repository.
---
# Data Source nexus_repository_gitlfs_hosted
Use this data source to get an existing hosted yum repository.
## Example Usage
```terraform
data "nexus_repository_gitlfs_hosted" "internal" {
name = "gitlfs-internal"
}
```
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) A unique identifier for this repository

### Read-Only

- `cleanup` (List of Object) Cleanup policies (see [below for nested schema](#nestedatt--cleanup))
- `component` (List of Object) Component configuration for the hosted repository (see [below for nested schema](#nestedatt--component))
- `id` (String) Used to identify data source at nexus
- `online` (Boolean) Whether this repository accepts incoming requests
- `storage` (List of Object) The storage configuration of the repository (see [below for nested schema](#nestedatt--storage))

<a id="nestedatt--cleanup"></a>
### Nested Schema for `cleanup`

Read-Only:

- `policy_names` (Set of String)


<a id="nestedatt--component"></a>
### Nested Schema for `component`

Read-Only:

- `proprietary_components` (Boolean)


<a id="nestedatt--storage"></a>
### Nested Schema for `storage`

Read-Only:

- `blob_store_name` (String)
- `strict_content_type_validation` (Boolean)
- `write_policy` (String)
72 changes: 72 additions & 0 deletions docs/resources/repository_gitlfs_hosted.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
page_title: "Resource nexus_repository_gitlfs_hosted"
subcategory: "Repository"
description: |-
Use this resource to create a hosted gitlfs repository.
---
# Resource nexus_repository_gitlfs_hosted
Use this resource to create a hosted gitlfs repository.
## Example Usage
```terraform
resource "nexus_repository_gitlfs_hosted" "internal" {
name = "gitlfs-internal"
online = true

storage {
blob_store_name = "default"
strict_content_type_validation = false
write_policy = "ALLOW"
}
}
```
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `name` (String) A unique identifier for this repository
- `storage` (Block List, Min: 1, Max: 1) The storage configuration of the repository (see [below for nested schema](#nestedblock--storage))

### Optional

- `cleanup` (Block List) Cleanup policies (see [below for nested schema](#nestedblock--cleanup))
- `component` (Block List, Max: 1) Component configuration for the hosted repository (see [below for nested schema](#nestedblock--component))
- `online` (Boolean) Whether this repository accepts incoming requests

### Read-Only

- `id` (String) Used to identify resource at nexus

<a id="nestedblock--storage"></a>
### Nested Schema for `storage`

Required:

- `blob_store_name` (String) Blob store used to store repository contents
- `strict_content_type_validation` (Boolean) Whether to validate uploaded content's MIME type appropriate for the repository format

Optional:

- `write_policy` (String) Controls if deployments of and updates to assets are allowed


<a id="nestedblock--cleanup"></a>
### Nested Schema for `cleanup`

Optional:

- `policy_names` (Set of String) List of policy names


<a id="nestedblock--component"></a>
### Nested Schema for `component`

Required:

- `proprietary_components` (Boolean) Components in this repository count as proprietary for namespace conflict attacks (requires Sonatype Nexus Firewall)
## Import
Import is supported using the following syntax:
```shell
# import using the name of repository
terraform import nexus_repository_gitlfs_hosted.internal gitlfs-internal
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data "nexus_repository_gitlfs_hosted" "internal" {
name = "gitlfs-internal"
}
2 changes: 2 additions & 0 deletions examples/resources/nexus_repository_gitlfs_hosted/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# import using the name of repository
terraform import nexus_repository_gitlfs_hosted.internal gitlfs-internal
10 changes: 10 additions & 0 deletions examples/resources/nexus_repository_gitlfs_hosted/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "nexus_repository_gitlfs_hosted" "internal" {
name = "gitlfs-internal"
online = true

storage {
blob_store_name = "default"
strict_content_type_validation = false
write_policy = "ALLOW"
}
}
7 changes: 7 additions & 0 deletions internal/acceptance/template-strings-repository-gitlfs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package acceptance

const (
TemplateStringRepositoryGitlfsHosted = `
resource "nexus_repository_gitlfs_hosted" "acceptance" {
` + TemplateStringHostedRepository
)
2 changes: 2 additions & 0 deletions internal/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Provider() *schema.Provider {
"nexus_repository_docker_group": repository.DataSourceRepositoryDockerGroup(),
"nexus_repository_docker_hosted": repository.DataSourceRepositoryDockerHosted(),
"nexus_repository_docker_proxy": repository.DataSourceRepositoryDockerProxy(),
"nexus_repository_gitlfs_hosted": repository.DataSourceRepositoryGitlfsHosted(),
"nexus_repository_list": repository.DataSourceRepositoryList(),
"nexus_repository_maven_group": repository.DataSourceRepositoryMavenGroup(),
"nexus_repository_maven_hosted": repository.DataSourceRepositoryMavenHosted(),
Expand Down Expand Up @@ -92,6 +93,7 @@ func Provider() *schema.Provider {
"nexus_repository_docker_group": repository.ResourceRepositoryDockerGroup(),
"nexus_repository_docker_hosted": repository.ResourceRepositoryDockerHosted(),
"nexus_repository_docker_proxy": repository.ResourceRepositoryDockerProxy(),
"nexus_repository_gitlfs_hosted": repository.ResourceRepositoryGitlfsHosted(),
"nexus_repository_maven_group": repository.ResourceRepositoryMavenGroup(),
"nexus_repository_maven_hosted": repository.ResourceRepositoryMavenHosted(),
"nexus_repository_maven_proxy": repository.ResourceRepositoryMavenProxy(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package repository

import (
"github.com/datadrivers/terraform-provider-nexus/internal/schema/common"
"github.com/datadrivers/terraform-provider-nexus/internal/schema/repository"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func DataSourceRepositoryGitlfsHosted() *schema.Resource {
return &schema.Resource{
Description: "Use this data source to get an existing hosted yum repository.",

Read: dataSourceRepositoryGitlfsHostedRead,
Schema: map[string]*schema.Schema{
// Common schemas
"id": common.DataSourceID,
"name": repository.DataSourceName,
"online": repository.DataSourceOnline,
// Hosted schemas
"cleanup": repository.DataSourceCleanup,
"component": repository.DataSourceComponent,
"storage": repository.DataSourceHostedStorage,
},
}
}

func dataSourceRepositoryGitlfsHostedRead(d *schema.ResourceData, m interface{}) error {
d.SetId(d.Get("name").(string))

return resourceGitlfsHostedRepositoryRead(d, m)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package repository_test

import (
"fmt"
"strconv"
"testing"

"github.com/datadrivers/go-nexus-client/nexus3/schema/repository"
"github.com/datadrivers/terraform-provider-nexus/internal/acceptance"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func testAccDataSourceRepositoryGitlfsHostedConfig() string {
return `
data "nexus_repository_gitlfs_hosted" "acceptance" {
name = nexus_repository_gitlfs_hosted.acceptance.id
}`
}

func TestAccDataSourceRepositoryGitlfsHosted(t *testing.T) {
repoUsingDefaults := repository.GitLfsHostedRepository{
Name: fmt.Sprintf("acceptance-%s", acctest.RandString(10)),
Online: true,
Storage: repository.HostedStorage{
BlobStoreName: "default",
StrictContentTypeValidation: false,
},
}
dataSourceName := "data.nexus_repository_gitlfs_hosted.acceptance"

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.AccPreCheck(t) },
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccResourceRepositoryGitlfsHostedConfig(repoUsingDefaults) + testAccDataSourceRepositoryGitlfsHostedConfig(),
Check: resource.ComposeTestCheckFunc(
resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "id", repoUsingDefaults.Name),
resource.TestCheckResourceAttr(dataSourceName, "name", repoUsingDefaults.Name),
resource.TestCheckResourceAttr(dataSourceName, "online", strconv.FormatBool(repoUsingDefaults.Online)),
resource.TestCheckResourceAttr(dataSourceName, "storage.0.blob_store_name", repoUsingDefaults.Storage.BlobStoreName),
resource.TestCheckResourceAttr(dataSourceName, "storage.0.strict_content_type_validation", strconv.FormatBool(repoUsingDefaults.Storage.StrictContentTypeValidation)),
),
),
},
},
})
}
Loading