diff --git a/pkg/artifactory/provider/framework.go b/pkg/artifactory/provider/framework.go index b84e1333..be6440f8 100644 --- a/pkg/artifactory/provider/framework.go +++ b/pkg/artifactory/provider/framework.go @@ -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" @@ -205,6 +206,7 @@ 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, @@ -212,9 +214,19 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R 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, @@ -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, diff --git a/pkg/artifactory/provider/resources.go b/pkg/artifactory/provider/resources.go index 5dcc1f09..92948e27 100644 --- a/pkg/artifactory/provider/resources.go +++ b/pkg/artifactory/provider/resources.go @@ -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" @@ -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(), @@ -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) diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_helmoci_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_helmoci_repository.go index 25ea0fd4..acfc4f82 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_helmoci_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_helmoci_repository.go @@ -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" ) @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_java_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_java_repository.go index eef631aa..a41a5240 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_java_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_java_repository.go @@ -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" ) @@ -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( @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_nuget_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_nuget_repository.go index 73f4c0c3..0b5a69d3 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_nuget_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_nuget_repository.go @@ -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" ) @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_oci_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_oci_repository.go index 1f8329bc..132800db 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_oci_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_oci_repository.go @@ -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" ) @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_rpm_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_rpm_repository.go index 5379edaa..7a8dc1fe 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_rpm_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_rpm_repository.go @@ -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" ) @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_terraform_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_terraform_repository.go index 1f5ce3bf..0764db62 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_terraform_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_terraform_repository.go @@ -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 @@ -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), } diff --git a/pkg/artifactory/resource/repository/local/local.go b/pkg/artifactory/resource/repository/local/local.go index 31c1ad93..88225b4f 100644 --- a/pkg/artifactory/resource/repository/local/local.go +++ b/pkg/artifactory/resource/repository/local/local.go @@ -25,7 +25,7 @@ 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{ @@ -33,7 +33,7 @@ func NewLocalRepositoryResource(packageType string, resourceModelType, apiModelT 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, diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository.go index b8f35f8b..81efcf17 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository.go @@ -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](), + ), } } diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go index 8c735514..24616b63 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/plancheck" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/acctest" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/security" @@ -105,3 +106,98 @@ EOF }, }) } + +func TestAccLocalAlpineRepository_UpgradeFromSDKv2(t *testing.T) { + _, fqrn, name := testutil.MkNames("alpine-local-test-repo", "artifactory_local_alpine_repository") + kpId, _, kpName := testutil.MkNames("some-keypair", "artifactory_keypair") + + config := util.ExecuteTemplate("keypair", ` + resource "artifactory_keypair" "{{ .kp_name }}" { + pair_name = "{{ .kp_name }}" + pair_type = "RSA" + alias = "foo-alias{{ .kp_id }}" + private_key = <