Skip to content

Commit

Permalink
Merge pull request #1168 from jfrog/migrate-local-repository-to-plugi…
Browse files Browse the repository at this point in the history
…n-framework

Migrate local repository to plugin framework
  • Loading branch information
alexhung authored Jan 14, 2025
2 parents a32ce6a + f5d7f74 commit a0e150e
Show file tree
Hide file tree
Showing 56 changed files with 4,521 additions and 1,832 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 12.8.2 (January 14, 2025). Tested on Artifactory 7.98.13 with Terraform 1.10.4 and OpenTofu 1.9.0

IMPROVEMENTS:

* resource/artifactory_local_alpine_repository, resource/artifactory_local_ansible_repository, resource/artifactory_local_cargo_repository, resource/artifactory_local_conan_repository, resource/artifactory_local_docker_v1_repository, resource/artifactory_local_docker_v2_repository, resource/artifactory_local_gradle_repository, resource/artifactory_local_helmoci_repository, resource/artifactory_local_ivy_repository, resource/artifactory_local_nuget_repository, resource/artifactory_local_helm_repository, resource/artifactory_local_hunggingfaceml_repository, resource/artifactory_local_oci_repository, resource/artifactory_local_rpm_repository, resource/artifactory_local_sbt_repository, resource/artifactory_local_terraform_module_repository, resource/artifactory_local_terraform_provider_repository are migrated to Plugin Framework. PR: [#1168](https://github.com/jfrog/terraform-provider-artifactory/pull/1168)

## 12.8.1 (January 13, 2025). Tested on Artifactory 7.98.13 with Terraform 1.10.4 and OpenTofu 1.9.0

BUG FIXES:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func TestAccDataSourceRepositories(t *testing.T) {
artifactoryURL := acctest.GetArtifactoryUrl(t)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,7 @@ func TestAccDataSourceLocalCargoRepository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -290,8 +289,7 @@ func TestAccDataSourceLocalConanRepository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -406,10 +404,6 @@ EOF
secondary_keypair_ref = artifactory_keypair.{{ .kp_name2 }}.pair_name
index_compression_formats = ["bz2","lzma","xz"]
trivial_layout = true
depends_on = [
artifactory_keypair.{{ .kp_name }},
artifactory_keypair.{{ .kp_name2 }},
]
}
data "artifactory_local_debian_repository" "{{ .repo_name }}" {
Expand All @@ -424,7 +418,6 @@ EOF
}) // we use randomness so that, in the case of failure and dangle, the next test can run without collision

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -467,8 +460,7 @@ func TestAccDataSourceLocalDockerV2Repository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -499,8 +491,7 @@ func TestAccDataSourceLocalDockerV1Repository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -551,8 +542,7 @@ func TestAccDataSourceLocalMavenRepository(t *testing.T) {
tempStruct["suppress_pom_consistency_checks"] = false

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: util.ExecuteTemplate(fqrn, localJavaRepositoryBasic, tempStruct),
Expand Down Expand Up @@ -584,9 +574,8 @@ func makeDataSourceLocalGradleLikeRepoTestCase(repoType string, t *testing.T) (*
fqrn := "data." + tempFqrn

return t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
Steps: []resource.TestStep{
{
Config: util.ExecuteTemplate(fqrn, localJavaRepositoryBasic, tempStruct),
Expand Down Expand Up @@ -624,8 +613,7 @@ func TestAccDataSourceLocalHelmOciRepository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -667,9 +655,8 @@ func TestAccDataSourceLocalNugetRepository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -704,8 +691,7 @@ func TestAccDataSourceLocalOciRepository(t *testing.T) {
`, params)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -840,7 +826,6 @@ EOF
}) // we use randomness so that, in the case of failure and dangle, the next test can run without collision

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
CheckDestroy: acctest.CompositeCheckDestroy(
acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
Expand Down Expand Up @@ -883,9 +868,8 @@ func TestAccDataSourceLocalTerraformModuleRepository(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down Expand Up @@ -917,9 +901,8 @@ func TestAccDataSourceLocalTerraformProviderRepository(t *testing.T) {
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProviderFactories: acctest.ProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
CheckDestroy: acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo),
Steps: []resource.TestStep{
{
Config: localRepositoryBasic,
Expand Down
27 changes: 26 additions & 1 deletion pkg/artifactory/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/configuration"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/lifecycle"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/replication"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/local"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/security"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/user"
Expand Down Expand Up @@ -205,16 +206,27 @@ func (p *ArtifactoryProvider) Configure(ctx context.Context, req provider.Config

// Resources satisfies the provider.Provider interface for ArtifactoryProvider.
func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.Resource {
resources := []func() resource.Resource{}

localGenericLikeRepositoryResources := lo.Map(
local.PackageTypesLikeGeneric,
func(packageType string, _ int) func() resource.Resource {
return local.NewGenericLocalRepositoryResource(packageType)
},
)
resources = append(resources, localGenericLikeRepositoryResources...)

localGradleLikeRepositoryResources := lo.Map(
repository.PackageTypesLikeGradle,
func(packageType string, _ int) func() resource.Resource {
return local.NewJavaLocalRepositoryResource(packageType, true)
},
)
resources = append(resources, localGradleLikeRepositoryResources...)
resources = append(resources, local.NewJavaLocalRepositoryResource(repository.MavenPackageType, false))

return append(
localGenericLikeRepositoryResources,
resources,
[]func() resource.Resource{
artifact.NewArtifactResource,
artifact.NewItemPropertiesResource,
Expand Down Expand Up @@ -246,7 +258,20 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R
replication.NewLocalRepositorySingleReplicationResource,
replication.NewLocalRepositoryMultiReplicationResource,
replication.NewRemoteRepositoryReplicationResource,
local.NewAlpineLocalRepositoryResource,
local.NewAnsibleLocalRepositoryResource,
local.NewCargoLocalRepositoryResource,
local.NewConanLocalRepositoryResource,
local.NewDebianLocalRepositoryResource,
local.NewDockerV2LocalRepositoryResource,
local.NewDockerV1LocalRepositoryResource,
local.NewHelmOCILocalRepositoryResource,
local.NewMachineLearningLocalRepositoryResource,
local.NewNugetLocalRepositoryResource,
local.NewOCILocalRepositoryResource,
local.NewRPMLocalRepositoryResource,
local.NewTerraformModuleLocalRepositoryResource,
local.NewTerraformProviderLocalRepositoryResource,
webhook.NewArtifactWebhookResource,
webhook.NewArtifactCustomWebhookResource,
webhook.NewArtifactLifecycleWebhookResource,
Expand Down
17 changes: 0 additions & 17 deletions pkg/artifactory/provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/replication"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/federated"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/local"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/remote"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/virtual"
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/security"
Expand All @@ -32,20 +31,6 @@ func resourcesMap() map[string]*schema.Resource {
"artifactory_federated_rpm_repository": federated.ResourceArtifactoryFederatedRpmRepository(),
"artifactory_federated_terraform_module_repository": federated.ResourceArtifactoryFederatedTerraformRepository("module"),
"artifactory_federated_terraform_provider_repository": federated.ResourceArtifactoryFederatedTerraformRepository("provider"),
"artifactory_local_ansible_repository": local.ResourceArtifactoryLocalAnsibleRepository(),
"artifactory_local_alpine_repository": local.ResourceArtifactoryLocalAlpineRepository(),
"artifactory_local_cargo_repository": local.ResourceArtifactoryLocalCargoRepository(),
"artifactory_local_conan_repository": local.ResourceArtifactoryLocalConanRepository(),
"artifactory_local_debian_repository": local.ResourceArtifactoryLocalDebianRepository(),
"artifactory_local_docker_v2_repository": local.ResourceArtifactoryLocalDockerV2Repository(),
"artifactory_local_docker_v1_repository": local.ResourceArtifactoryLocalDockerV1Repository(),
"artifactory_local_helmoci_repository": local.ResourceArtifactoryLocalHelmOciRepository(),
"artifactory_local_maven_repository": local.ResourceArtifactoryLocalJavaRepository(repository.MavenPackageType, false),
"artifactory_local_nuget_repository": local.ResourceArtifactoryLocalNugetRepository(),
"artifactory_local_oci_repository": local.ResourceArtifactoryLocalOciRepository(),
"artifactory_local_rpm_repository": local.ResourceArtifactoryLocalRpmRepository(),
"artifactory_local_terraform_module_repository": local.ResourceArtifactoryLocalTerraformRepository("module"),
"artifactory_local_terraform_provider_repository": local.ResourceArtifactoryLocalTerraformRepository("provider"),
"artifactory_remote_ansible_repository": remote.ResourceArtifactoryRemoteAnsibleRepository(),
"artifactory_remote_bower_repository": remote.ResourceArtifactoryRemoteBowerRepository(),
"artifactory_remote_cargo_repository": remote.ResourceArtifactoryRemoteCargoRepository(),
Expand Down Expand Up @@ -98,8 +83,6 @@ func resourcesMap() map[string]*schema.Resource {
}

for _, packageType := range repository.PackageTypesLikeGradle {
localResourceName := fmt.Sprintf("artifactory_local_%s_repository", packageType)
resourcesMap[localResourceName] = local.ResourceArtifactoryLocalJavaRepository(packageType, true)
virtualResourceName := fmt.Sprintf("artifactory_virtual_%s_repository", packageType)
resourcesMap[virtualResourceName] = virtual.ResourceArtifactoryVirtualJavaRepository(packageType)
federatedResourceName := fmt.Sprintf("artifactory_federated_%s_repository", packageType)
Expand Down
2 changes: 1 addition & 1 deletion pkg/artifactory/resource/repository/federated/federated.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Member struct {

var SchemaGeneratorV3 = func(isRequired bool) map[string]*schema.Schema {
return lo.Assign(
repository.ProxySchema,
repository.ProxySchemaSDKv2,
map[string]*schema.Schema{
"cleanup_on_delete": {
Type: schema.TypeBool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ type AlpineRepositoryParams struct {
RepoParams
}

func unpackLocalAlpineRepository(data *schema.ResourceData, Rclass string) local.AlpineLocalRepoParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.AlpineLocalRepoParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.AlpinePackageType),
PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{
PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false),
},
}
}

func ResourceArtifactoryFederatedAlpineRepository() *schema.Resource {
alpineFederatedSchema := utilsdk.MergeMaps(
local.AlpineLocalSchemas[local.CurrentSchemaVersion],
Expand All @@ -24,7 +34,7 @@ func ResourceArtifactoryFederatedAlpineRepository() *schema.Resource {

var unpackFederatedAlpineRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := AlpineRepositoryParams{
AlpineLocalRepoParams: local.UnpackLocalAlpineRepository(data, Rclass),
AlpineLocalRepoParams: unpackLocalAlpineRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func ResourceArtifactoryFederatedAnsibleRepository() *schema.Resource {
var ansibleSchema = lo.Assign(
local.GetGenericSchemas(repository.AnsiblePackageType)[local.CurrentSchemaVersion],
federatedSchemaV4,
repository.AlpinePrimaryKeyPairRef,
repository.AlpinePrimaryKeyPairRefSDKv2,
repository.RepoLayoutRefSDKv2Schema(Rclass, repository.AnsiblePackageType),
)

Expand All @@ -33,7 +33,7 @@ func ResourceArtifactoryFederatedAnsibleRepository() *schema.Resource {
RepoParams: unpackRepoParams(data),
Members: unpackMembers(data),
PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{
PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false),
PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false),
},
}
return repo, repo.Id(), nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/local"
"github.com/jfrog/terraform-provider-shared/packer"
"github.com/jfrog/terraform-provider-shared/predicate"
utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk"
"github.com/samber/lo"
)

Expand All @@ -15,6 +16,15 @@ type CargoFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalCargoRepository(data *schema.ResourceData, Rclass string) local.CargoLocalRepoParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.CargoLocalRepoParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.CargoPackageType),
AnonymousAccess: d.GetBool("anonymous_access", false),
EnableSparseIndex: d.GetBool("enable_sparse_index", false),
}
}

func ResourceArtifactoryFederatedCargoRepository() *schema.Resource {
cargoFederatedSchema := lo.Assign(
local.CargoSchemas[local.CurrentSchemaVersion],
Expand All @@ -24,7 +34,7 @@ func ResourceArtifactoryFederatedCargoRepository() *schema.Resource {

var unpackFederatedCargoRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := CargoFederatedRepositoryParams{
CargoLocalRepoParams: local.UnpackLocalCargoRepository(data, Rclass),
CargoLocalRepoParams: unpackLocalCargoRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@ type DebianFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalDebianRepository(data *schema.ResourceData, Rclass string) local.DebianLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.DebianLocalRepositoryParams{
PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{
PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false),
},
SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{
SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false),
},
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.DebianPackageType),
TrivialLayout: d.GetBool("trivial_layout", false),
IndexCompressionFormats: d.GetSet("index_compression_formats"),
}
}

func ResourceArtifactoryFederatedDebianRepository() *schema.Resource {
debianFederatedSchema := utilsdk.MergeMaps(
local.DebianSchemas[local.CurrentSchemaVersion],
Expand All @@ -24,7 +39,7 @@ func ResourceArtifactoryFederatedDebianRepository() *schema.Resource {

var unpackFederatedDebianRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := DebianFederatedRepositoryParams{
DebianLocalRepositoryParams: local.UnpackLocalDebianRepository(data, Rclass),
DebianLocalRepositoryParams: unpackLocalDebianRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
Expand Down
Loading

0 comments on commit a0e150e

Please sign in to comment.