Skip to content

Commit

Permalink
Merge pull request #147 from jfrog/GH-80-add-resource-for-sharing-repos
Browse files Browse the repository at this point in the history
Add resources for sharing repos with projects
  • Loading branch information
alexhung authored Jul 24, 2024
2 parents 7f79fc2 + 0bb3ac3 commit 2a293cd
Show file tree
Hide file tree
Showing 29 changed files with 927 additions and 92 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ jobs:
steps:
-
name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
-
name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: 1.21
go-version: 1.22
-
name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v5.0.0
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
uses: goreleaser/goreleaser-action@v6
with:
version: ${{ github.event.inputs.tag }}
args: release --clean
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
version: 2

# Visit https://goreleaser.com for documentation on how to customize this
# behavior.
before:
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
## 1.7.0 (July 24, 2024). Tested on Artifactory 7.84.17 with Terraform 1.9.2 and OpenTofu 1.7.3

NOTES:

* provider: `check_license` attribute is deprecated and provider no longer checks Artifactory license during initialization. It will be removed in the next major version release.

FEATURES:

* **New Resource:** `project_share_repository` - New resource to share repository with a project.
* **New Resource:** `project_share_repository_with_all` - New resource to share repository with all projects.

Issue: [#80](https://github.com/jfrog/terraform-provider-project/issues/80)
PR: [#147](https://github.com/jfrog/terraform-provider-project/pull/147)

## 1.6.2 (June 4, 2024). Tested on Artifactory 7.84.14 with Terraform and OpenTofu 1.7.2

IMPROVEMENTS:
Expand Down
7 changes: 2 additions & 5 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,9 @@ provider "project" {
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `url` (String) URL of Artifactory. This can also be sourced from the `PROJECT_URL` or `JFROG_URL` environment variable. Default to 'http://localhost:8081' if not set.

### Optional

- `access_token` (String, Sensitive) This is a Bearer token that can be given to you by your admin under `Identity and Access`. This can also be sourced from the `PROJECT_ACCESS_TOKEN` or `JFROG_ACCESS_TOKEN` environment variable. Defauult to empty string if not set.
- `check_license` (Boolean) Toggle for pre-flight checking of Artifactory Enterprise license. Default to `true`.
- `check_license` (Boolean, Deprecated) Toggle for pre-flight checking of Artifactory Enterprise license. Default to `true`.
- `oidc_provider_name` (String) OIDC provider name. See [Configure an OIDC Integration](https://jfrog.com/help/r/jfrog-platform-administration-documentation/configure-an-oidc-integration) for more details.
- `url` (String) URL of Artifactory. This can also be sourced from the `PROJECT_URL` or `JFROG_URL` environment variable. Default to 'http://localhost:8081' if not set.
38 changes: 38 additions & 0 deletions docs/resources/share_repository.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "project_share_repository Resource - terraform-provider-project"
subcategory: ""
description: |-
Share a local or remote repository with a list of projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. Only available for Artifactory 7.90.1 or later.
---

# project_share_repository (Resource)

Share a local or remote repository with a list of projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role.

->Only available for Artifactory 7.90.1 or later.

## Example Usage

```terraform
resource "project_share_repository" "myprojectsharerepo" {
repo_key = "myrepo-generic-local"
target_project_key = "myproj"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `repo_key` (String) The key of the repository.
- `target_project_key` (String) The project key to which the repository should be shared with.

## Import

Import is supported using the following syntax:

```shell
terraform import project_share_repository.myprojectsharerepo repo_key:project_key
```
36 changes: 36 additions & 0 deletions docs/resources/share_repository_with_all.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "project_share_repository_with_all Resource - terraform-provider-project"
subcategory: ""
description: |-
Share a local or remote repository with all projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role. Only available for Artifactory 7.90.1 or later.
---

# project_share_repository_with_all (Resource)

Share a local or remote repository with all projects. Project Members of the target project are granted actions to the shared repository according to their Roles and Role actions assigned in the target Project. Requires a user assigned with the 'Administer the Platform' role.

->Only available for Artifactory 7.90.1 or later.

## Example Usage

```terraform
resource "project_share_repository_with_all" "myprojectsharerepo" {
repo_key = "myrepo-generic-local"
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `repo_key` (String) The key of the repository.

## Import

Import is supported using the following syntax:

```shell
terraform import project_share_repository_with_all.myprojectsharerepo repo_key
```
1 change: 1 addition & 0 deletions examples/resources/project_share_repository/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import project_share_repository.myprojectsharerepo repo_key:project_key
4 changes: 4 additions & 0 deletions examples/resources/project_share_repository/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "project_share_repository" "myprojectsharerepo" {
repo_key = "myrepo-generic-local"
target_project_key = "myproj"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terraform import project_share_repository_with_all.myprojectsharerepo repo_key
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
resource "project_share_repository_with_all" "myprojectsharerepo" {
repo_key = "myrepo-generic-local"
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/jfrog/terraform-provider-project
// if you need to do local dev, literally just uncomment the line below
// replace github.com/jfrog/terraform-provider-shared => ../terraform-provider-shared

go 1.21.5
go 1.22.5

require (
github.com/go-resty/resty/v2 v2.13.1
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
provider "github.com/jfrog/terraform-provider-project/pkg/project/provider"
"github.com/jfrog/terraform-provider-project/pkg/project"
)

// Run the docs generation tool, check its repository for more information on how it works and how docs
Expand All @@ -24,7 +24,7 @@ func main() {
Address: "registry.terraform.io/jfrog/project",
Debug: debug,
}
err := providerserver.Serve(context.Background(), provider.Framework(), opts)
err := providerserver.Serve(context.Background(), project.NewProvider(), opts)
if err != nil {
log.Fatal(err.Error())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/project/acctest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-testing/terraform"
project "github.com/jfrog/terraform-provider-project/pkg/project/provider"
"github.com/jfrog/terraform-provider-project/pkg/project"
"github.com/jfrog/terraform-provider-shared/client"
"github.com/jfrog/terraform-provider-shared/testutil"
)
Expand All @@ -31,7 +31,7 @@ var Provider provider.Provider
var ProtoV6ProviderFactories map[string]func() (tfprotov6.ProviderServer, error)

func init() {
Provider = project.Framework()()
Provider = project.NewProvider()()

ProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServer, error){
"project": providerserver.NewProtocol6WithError(Provider),
Expand Down
26 changes: 12 additions & 14 deletions pkg/project/provider/framework.go → pkg/project/provider.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package provider
package project

import (
"context"
Expand All @@ -17,6 +17,11 @@ import (
validatorfw_string "github.com/jfrog/terraform-provider-shared/validator/fw/string"
)

var Version = "1.6.1"

// needs to be exported so make file can update this
var productId = "terraform-provider-project/" + Version

// Ensure the implementation satisfies the provider.Provider interface.
var _ provider.Provider = &ProjectProvider{}

Expand Down Expand Up @@ -65,8 +70,9 @@ func (p *ProjectProvider) Schema(ctx context.Context, req provider.SchemaRequest
Description: "OIDC provider name. See [Configure an OIDC Integration](https://jfrog.com/help/r/jfrog-platform-administration-documentation/configure-an-oidc-integration) for more details.",
},
"check_license": schema.BoolAttribute{
Optional: true,
Description: "Toggle for pre-flight checking of Artifactory Enterprise license. Default to `true`.",
Optional: true,
Description: "Toggle for pre-flight checking of Artifactory Enterprise license. Default to `true`.",
DeprecationMessage: "Remove this attribute from your provider configuration as it is no longer used and the attribute will be removed in the next major version of the provider.",
},
},
}
Expand Down Expand Up @@ -147,16 +153,6 @@ func (p *ProjectProvider) Configure(ctx context.Context, req provider.ConfigureR
)
}

if config.CheckLicense.IsNull() || config.CheckLicense.ValueBool() {
if err := util.CheckArtifactoryLicense(restyClient, "Enterprise", "Commercial", "Edge"); err != nil {
resp.Diagnostics.AddError(
"Error checking Artifactory license",
err.Error(),
)
return
}
}

version, err := util.GetArtifactoryVersion(restyClient)
if err != nil {
resp.Diagnostics.AddError(
Expand Down Expand Up @@ -189,6 +185,8 @@ func (p *ProjectProvider) Resources(ctx context.Context) []func() resource.Resou
project.NewProjectGroupResource,
project.NewProjectRepositoryResource,
project.NewProjectRoleResource,
project.NewProjectShareRepositoryResource,
project.NewProjectShareRepositoryWithAllResource,
project.NewProjectUserResource,
}
}
Expand All @@ -198,7 +196,7 @@ func (p *ProjectProvider) DataSources(_ context.Context) []func() datasource.Dat
return []func() datasource.DataSource{}
}

func Framework() func() provider.Provider {
func NewProvider() func() provider.Provider {
return func() provider.Provider {
return &ProjectProvider{}
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/project/provider/provider.go

This file was deleted.

9 changes: 5 additions & 4 deletions pkg/project/resource/membership_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestAccProject_membership(t *testing.T) {
resourceName := "project." + name
projectKey := strings.ToLower(acctest.RandSeq(10))

username1 := "user1"
username2 := "user2"
username1 := fmt.Sprintf("user1%s", strings.ToLower(acctest.RandSeq(5)))
username2 := fmt.Sprintf("user2%s", strings.ToLower(acctest.RandSeq(5)))
developeRole := "Developer"
contributorRole := "Contributor"

Expand Down Expand Up @@ -174,8 +174,9 @@ func TestAccProject_group(t *testing.T) {
resourceName := "project." + name
projectKey := strings.ToLower(acctest.RandSeq(10))

group1 := "group1"
group2 := "group2"
group1 := fmt.Sprintf("group1%s", strings.ToLower(acctest.RandSeq(5)))
group2 := fmt.Sprintf("group2%s", strings.ToLower(acctest.RandSeq(5)))

developeRole := "Developer"
contributorRole := "Contributor"

Expand Down
5 changes: 3 additions & 2 deletions pkg/project/resource/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const (
var customRoleTypeRegex = regexp.MustCompile(fmt.Sprintf("^%s$", customRoleType))

func NewProjectResource() resource.Resource {
return &ProjectResource{}
return &ProjectResource{
TypeName: "project",
}
}

type ProjectResource struct {
Expand Down Expand Up @@ -401,7 +403,6 @@ type ProjectAPIModel struct {

func (r *ProjectResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName
r.TypeName = resp.TypeName
}

var schemaV1 = schema.Schema{
Expand Down
7 changes: 4 additions & 3 deletions pkg/project/resource/resource_project_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import (
const ProjectEnvironmentUrl = "/access/api/v1/projects/{projectKey}/environments"

func NewProjectEnvironmentResource() resource.Resource {
return &ProjectEnvironmentResource{}
return &ProjectEnvironmentResource{
TypeName: "project_environment",
}
}

type ProjectEnvironmentResource struct {
Expand All @@ -47,8 +49,7 @@ type ProjectEnvironmentUpdateAPIModel struct {
}

func (r *ProjectEnvironmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_environment"
r.TypeName = resp.TypeName
resp.TypeName = r.TypeName
}

func (r *ProjectEnvironmentResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down
7 changes: 4 additions & 3 deletions pkg/project/resource/resource_project_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
const ProjectGroupsUrl = "access/api/v1/projects/{projectKey}/groups/{name}"

func NewProjectGroupResource() resource.Resource {
return &ProjectGroupResource{}
return &ProjectGroupResource{
TypeName: "project_group",
}
}

type ProjectGroupResource struct {
Expand All @@ -44,8 +46,7 @@ type ProjectGroupAPIModel struct {
}

func (r *ProjectGroupResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_group"
r.TypeName = resp.TypeName
resp.TypeName = r.TypeName
}

func (r *ProjectGroupResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down
Loading

0 comments on commit 2a293cd

Please sign in to comment.