Skip to content

Commit

Permalink
Migrate remaining local repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhung committed Jan 9, 2025
1 parent 662768f commit a6f4d36
Show file tree
Hide file tree
Showing 40 changed files with 2,702 additions and 883 deletions.
20 changes: 19 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 @@ -253,7 +265,13 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R
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
10 changes: 0 additions & 10 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,13 +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_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 @@ -91,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
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 HelmOciFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalHelmOciRepository(data *schema.ResourceData, Rclass string) local.HelmOciLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.HelmOciLocalRepositoryParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.HelmOCIPackageType),
MaxUniqueTags: d.GetInt("max_unique_tags", false),
TagRetention: d.GetInt("tag_retention", false),
}
}

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

var unpackRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := HelmOciFederatedRepositoryParams{
HelmOciLocalRepositoryParams: local.UnpackLocalHelmOciRepository(data, Rclass),
HelmOciLocalRepositoryParams: unpackLocalHelmOciRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
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,19 @@ type JavaFederatedRepositoryParams struct {
RepoParams
}

var unpackLocalJavaRepository = func(data *schema.ResourceData, Rclass string, packageType string) local.JavaLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.JavaLocalRepositoryParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, packageType),
ChecksumPolicyType: d.GetString("checksum_policy_type", false),
SnapshotVersionBehavior: d.GetString("snapshot_version_behavior", false),
MaxUniqueSnapshots: d.GetInt("max_unique_snapshots", false),
HandleReleases: d.GetBool("handle_releases", false),
HandleSnapshots: d.GetBool("handle_snapshots", false),
SuppressPomConsistencyChecks: d.GetBool("suppress_pom_consistency_checks", false),
}
}

func ResourceArtifactoryFederatedJavaRepository(packageType string, suppressPom bool) *schema.Resource {

javaFederatedSchema := lo.Assign(
Expand All @@ -25,7 +39,7 @@ func ResourceArtifactoryFederatedJavaRepository(packageType string, suppressPom

var unpackFederatedJavaRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := JavaFederatedRepositoryParams{
JavaLocalRepositoryParams: local.UnpackLocalJavaRepository(data, Rclass, packageType),
JavaLocalRepositoryParams: unpackLocalJavaRepository(data, Rclass, packageType),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
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 NugetFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalNugetRepository(data *schema.ResourceData, Rclass string) local.NugetLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.NugetLocalRepositoryParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.NugetPackageType),
MaxUniqueSnapshots: d.GetInt("max_unique_snapshots", false),
ForceNugetAuthentication: d.GetBool("force_nuget_authentication", false),
}
}

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

var unpackFederatedNugetRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := NugetFederatedRepositoryParams{
NugetLocalRepositoryParams: local.UnpackLocalNugetRepository(data, Rclass),
NugetLocalRepositoryParams: unpackLocalNugetRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
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,16 @@ type OciFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalOciRepository(data *schema.ResourceData, Rclass string) local.OciLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.OciLocalRepositoryParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.OCIPackageType),
MaxUniqueTags: d.GetInt("max_unique_tags", false),
DockerApiVersion: "V2",
TagRetention: d.GetInt("tag_retention", false),
}
}

func ResourceArtifactoryFederatedOciRepository() *schema.Resource {
ociFederatedSchema := lo.Assign(
local.OCILocalSchemas[local.CurrentSchemaVersion],
Expand All @@ -24,7 +35,7 @@ func ResourceArtifactoryFederatedOciRepository() *schema.Resource {

var unpackFederatedOciRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := OciFederatedRepositoryParams{
OciLocalRepositoryParams: local.UnpackLocalOciRepository(data, Rclass),
OciLocalRepositoryParams: unpackLocalOciRepository(data, Rclass),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
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,23 @@ type RpmFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalRpmRepository(data *schema.ResourceData, Rclass string) local.RpmLocalRepositoryParams {
d := &utilsdk.ResourceData{ResourceData: data}
return local.RpmLocalRepositoryParams{
RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.RPMPackageType),
PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{
PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false),
},
SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{
SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false),
},
RootDepth: d.GetInt("yum_root_depth", false),
CalculateYumMetadata: d.GetBool("calculate_yum_metadata", false),
EnableFileListsIndexing: d.GetBool("enable_file_lists_indexing", false),
GroupFileNames: d.GetString("yum_group_file_names", false),
}
}

func ResourceArtifactoryFederatedRpmRepository() *schema.Resource {
rpmFederatedSchema := lo.Assign(
local.RPMSchemas[local.CurrentSchemaVersion],
Expand All @@ -24,7 +42,7 @@ func ResourceArtifactoryFederatedRpmRepository() *schema.Resource {

var unpackFederatedRpmRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := RpmFederatedRepositoryParams{
RpmLocalRepositoryParams: local.UnpackLocalRpmRepository(data, Rclass),
RpmLocalRepositoryParams: unpackLocalRpmRepository(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,13 @@ type TerraformFederatedRepositoryParams struct {
RepoParams
}

func unpackLocalTerraformRepository(data *schema.ResourceData, Rclass string, registryType string) local.RepositoryBaseParams {
repo := local.UnpackBaseRepo(Rclass, data, "terraform_"+registryType)
repo.TerraformType = registryType

return repo
}

func ResourceArtifactoryFederatedTerraformRepository(registryType string) *schema.Resource {
packageType := "terraform_" + registryType

Expand All @@ -26,7 +33,7 @@ func ResourceArtifactoryFederatedTerraformRepository(registryType string) *schem

var unpackFederatedTerraformRepository = func(data *schema.ResourceData) (interface{}, string, error) {
repo := TerraformFederatedRepositoryParams{
RepositoryBaseParams: local.UnpackLocalTerraformRepository(data, Rclass, registryType),
RepositoryBaseParams: unpackLocalTerraformRepository(data, Rclass, registryType),
Members: unpackMembers(data),
RepoParams: unpackRepoParams(data),
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/artifactory/resource/repository/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ const (
CurrentSchemaVersion = 1
)

func NewLocalRepositoryResource(packageType string, resourceModelType, apiModelType reflect.Type) localResource {
func NewLocalRepositoryResource(packageType, packageName string, resourceModelType, apiModelType reflect.Type) localResource {
return localResource{
BaseResource: repository.BaseResource{
JFrogResource: util.JFrogResource{
TypeName: fmt.Sprintf("artifactory_local_%s_repository", packageType),
CollectionEndpoint: "artifactory/api/repositories",
DocumentEndpoint: "artifactory/api/repositories/{key}",
},
Description: fmt.Sprintf("Provides a resource to creates a %s repository.", packageType),
Description: fmt.Sprintf("Provides a resource to creates a %s repository.", packageName),
PackageType: packageType,
Rclass: Rclass,
ResourceModelType: resourceModelType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ import (

func NewAlpineLocalRepositoryResource() resource.Resource {
return &localAlpineResource{
localResource: NewLocalRepositoryResource(repository.AlpinePackageType, reflect.TypeFor[LocalAlpineResourceModel](), reflect.TypeFor[LocalAlpineAPIModel]()),
localResource: NewLocalRepositoryResource(
repository.AlpinePackageType,
"Alpine",
reflect.TypeFor[LocalAlpineResourceModel](),
reflect.TypeFor[LocalAlpineAPIModel](),
),
}
}

Expand Down
Loading

0 comments on commit a6f4d36

Please sign in to comment.