From 987d60a4265045652bf486005e924810e3982f7c Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 8 Jan 2025 09:47:07 -0800 Subject: [PATCH 1/8] Migrate Alpine local repository to Plugin Framework --- ...rce_artifactory_local_alpine_repository.go | 49 +++-- pkg/artifactory/provider/framework.go | 2 + pkg/artifactory/provider/resources.go | 1 - .../repository/federated/federated.go | 2 +- ...artifactory_federated_alpine_repository.go | 12 +- ...rtifactory_federated_ansible_repository.go | 4 +- .../resource/repository/local/local.go | 13 +- ...rce_artifactory_local_alpine_repository.go | 170 ++++++++++++++---- ...ce_artifactory_local_ansible_repository.go | 4 +- ...urce_artifactory_local_cargo_repository.go | 2 +- ...rce_artifactory_local_debian_repository.go | 10 +- ...ce_artifactory_local_generic_repository.go | 3 +- ...ource_artifactory_local_repository_test.go | 12 +- ...source_artifactory_local_rpm_repository.go | 8 +- .../resource/repository/remote/remote.go | 2 +- .../resource/repository/repository.go | 14 +- ...e_artifactory_virtual_alpine_repository.go | 4 +- ...e_artifactory_virtual_debian_repository.go | 8 +- ...urce_artifactory_virtual_rpm_repository.go | 8 +- 19 files changed, 225 insertions(+), 103 deletions(-) diff --git a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go index 2398a160e..381f5a47b 100644 --- a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go +++ b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go @@ -1,26 +1,41 @@ package local import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/datasource/repository" - resource_repository "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" + "context" + + "github.com/hashicorp/terraform-plugin-framework/datasource" + "github.com/hashicorp/terraform-plugin-framework/datasource/schema" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository/local" - "github.com/jfrog/terraform-provider-shared/packer" ) -func DataSourceArtifactoryLocalAlpineRepository() *schema.Resource { - constructor := func() (interface{}, error) { - return &local.AlpineLocalRepoParams{ - RepositoryBaseParams: local.RepositoryBaseParams{ - PackageType: resource_repository.AlpinePackageType, - Rclass: local.Rclass, - }, - }, nil - } +var _ datasource.DataSource = &AlpineLocalRepositoryDataSource{} + +type AlpineLocalRepositoryDataSource struct{} - return &schema.Resource{ - Schema: local.AlpineLocalSchemas[local.CurrentSchemaVersion], - ReadContext: repository.MkRepoReadDataSource(packer.Default(local.AlpineLocalSchemas[local.CurrentSchemaVersion]), constructor), - Description: "Data source for a local alpine repository", +func (d *AlpineLocalRepositoryDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { + resp.TypeName = "artifactory_local_alpine_repository" +} + +func (d *AlpineLocalRepositoryDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: local.AlpineLocalRepositoryAttributes, } } + +// +// func DataSourceArtifactoryLocalAlpineRepository() *schema.Resource { +// constructor := func() (interface{}, error) { +// return &local.AlpineLocalRepoParams{ +// RepositoryBaseParams: local.RepositoryBaseParams{ +// PackageType: resource_repository.AlpinePackageType, +// Rclass: local.Rclass, +// }, +// }, nil +// } +// +// return &schema.Resource{ +// Schema: local.AlpineLocalSchemas[local.CurrentSchemaVersion], +// ReadContext: repository.MkRepoReadDataSource(packer.Default(local.AlpineLocalSchemas[local.CurrentSchemaVersion]), constructor), +// Description: "Data source for a local alpine repository", +// } +// } diff --git a/pkg/artifactory/provider/framework.go b/pkg/artifactory/provider/framework.go index caae857c4..5e2f6d81c 100644 --- a/pkg/artifactory/provider/framework.go +++ b/pkg/artifactory/provider/framework.go @@ -246,6 +246,7 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R replication.NewLocalRepositorySingleReplicationResource, replication.NewLocalRepositoryMultiReplicationResource, replication.NewRemoteRepositoryReplicationResource, + local.NewAlpineLocalRepositoryResource, local.NewMachineLearningLocalRepositoryResource, webhook.NewArtifactWebhookResource, webhook.NewArtifactCustomWebhookResource, @@ -278,6 +279,7 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R // DataSources satisfies the provider.Provider interface for ArtifactoryProvider. func (p *ArtifactoryProvider) DataSources(_ context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ + datasource_repository.NewAlpineLocalRepositoryDataSource, datasource_repository.NewRepositoriesDataSource, datasource_artifact.NewFileListDataSource, } diff --git a/pkg/artifactory/provider/resources.go b/pkg/artifactory/provider/resources.go index c6aa0dacd..13c7841d5 100644 --- a/pkg/artifactory/provider/resources.go +++ b/pkg/artifactory/provider/resources.go @@ -33,7 +33,6 @@ func resourcesMap() map[string]*schema.Resource { "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(), diff --git a/pkg/artifactory/resource/repository/federated/federated.go b/pkg/artifactory/resource/repository/federated/federated.go index c99054830..5e6d08d0c 100644 --- a/pkg/artifactory/resource/repository/federated/federated.go +++ b/pkg/artifactory/resource/repository/federated/federated.go @@ -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, diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_alpine_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_alpine_repository.go index a7b892c8c..9b80e3fcf 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_alpine_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_alpine_repository.go @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_ansible_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_ansible_repository.go index faca450c8..f10a682c9 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_ansible_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_ansible_repository.go @@ -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), ) @@ -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 diff --git a/pkg/artifactory/resource/repository/local/local.go b/pkg/artifactory/resource/repository/local/local.go index 53de3ffbe..cc1d06b41 100644 --- a/pkg/artifactory/resource/repository/local/local.go +++ b/pkg/artifactory/resource/repository/local/local.go @@ -28,12 +28,13 @@ type localResource struct { type LocalResourceModel struct { repository.BaseResourceModel - BlackedOut types.Bool `tfsdk:"blacked_out"` - XrayIndex types.Bool `tfsdk:"xray_index"` - PropertySets types.Set `tfsdk:"property_sets"` - ArchiveBrowsingEnabled types.Bool `tfsdk:"archive_browsing_enabled"` - DownloadDirect types.Bool `tfsdk:"download_direct"` - PriorityResolution types.Bool `tfsdk:"priority_resolution"` + BlackedOut types.Bool `tfsdk:"blacked_out"` + XrayIndex types.Bool `tfsdk:"xray_index"` + PropertySets types.Set `tfsdk:"property_sets"` + ArchiveBrowsingEnabled types.Bool `tfsdk:"archive_browsing_enabled"` + DownloadDirect types.Bool `tfsdk:"download_direct"` + PriorityResolution types.Bool `tfsdk:"priority_resolution"` + RepoLayoutRef types.String `tfsdk:"repo_layout_ref"` } func (r *LocalResourceModel) GetCreateResourcePlanData(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 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 dacc2c793..63d09b791 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 @@ -1,55 +1,151 @@ package local import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "context" + "fmt" + "reflect" + + "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" + "github.com/hashicorp/terraform-plugin-framework/types" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" - "github.com/jfrog/terraform-provider-shared/packer" - utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk" + "github.com/jfrog/terraform-provider-shared/util" "github.com/samber/lo" ) -var alpineSchema = lo.Assign( - repository.RepoLayoutRefSDKv2Schema(Rclass, repository.AlpinePackageType), - repository.AlpinePrimaryKeyPairRef, - repository.CompressionFormats, -) +func NewAlpineLocalRepositoryResource() resource.Resource { + return &localAlpineResource{ + localResource: localResource{ + BaseResource: repository.BaseResource{ + JFrogResource: util.JFrogResource{ + TypeName: fmt.Sprintf("artifactory_local_%s_repository", repository.AlpinePackageType), + CollectionEndpoint: "artifactory/api/repositories", + DocumentEndpoint: "artifactory/api/repositories/{key}", + }, + Description: "Provides a resource to creates a Alpine repository.", + PackageType: repository.AlpinePackageType, + Rclass: Rclass, + ResourceModelType: reflect.TypeFor[LocalAlpineResourceModel](), + APIModelType: reflect.TypeFor[LocalAlpineAPIModel](), + }, + }, + } +} -var AlpineLocalSchemas = GetSchemas(alpineSchema) +type localAlpineResource struct { + localResource +} -type AlpineLocalRepoParams struct { - RepositoryBaseParams - repository.PrimaryKeyPairRefParam +type LocalAlpineResourceModel struct { + LocalResourceModel + PrimaryKeyPairRef types.String `tfsdk:"primary_keypair_ref"` } -func UnpackLocalAlpineRepository(data *schema.ResourceData, Rclass string) AlpineLocalRepoParams { - d := &utilsdk.ResourceData{ResourceData: data} - return AlpineLocalRepoParams{ - RepositoryBaseParams: UnpackBaseRepo(Rclass, data, repository.AlpinePackageType), - PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), - }, - } +func (r *LocalAlpineResourceModel) GetCreateResourcePlanData(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { + // Read Terraform plan data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, r)...) } -func ResourceArtifactoryLocalAlpineRepository() *schema.Resource { - var unpackLocalAlpineRepo = func(data *schema.ResourceData) (interface{}, string, error) { - repo := UnpackLocalAlpineRepository(data, Rclass) - return repo, repo.Id(), nil - } +func (r LocalAlpineResourceModel) SetCreateResourceStateData(ctx context.Context, resp *resource.CreateResponse) { + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &r)...) +} - constructor := func() (interface{}, error) { - return &AlpineLocalRepoParams{ - RepositoryBaseParams: RepositoryBaseParams{ - PackageType: repository.AlpinePackageType, - Rclass: Rclass, - }, - }, nil +func (r *LocalAlpineResourceModel) GetReadResourceStateData(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { + // Read Terraform state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, r)...) +} + +func (r LocalAlpineResourceModel) SetReadResourceStateData(ctx context.Context, resp *resource.ReadResponse) { + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &r)...) +} + +func (r *LocalAlpineResourceModel) GetUpdateResourcePlanData(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Read Terraform state data into the model + resp.Diagnostics.Append(req.Plan.Get(ctx, r)...) +} + +func (r *LocalAlpineResourceModel) GetUpdateResourceStateData(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { + // Read Terraform state data into the model + resp.Diagnostics.Append(req.State.Get(ctx, r)...) +} + +func (r LocalAlpineResourceModel) SetUpdateResourceStateData(ctx context.Context, resp *resource.UpdateResponse) { + // Save data into Terraform state + resp.Diagnostics.Append(resp.State.Set(ctx, &r)...) +} + +func (r LocalAlpineResourceModel) ToAPIModel(ctx context.Context, packageType string) (interface{}, diag.Diagnostics) { + diags := diag.Diagnostics{} + + model, d := r.LocalResourceModel.ToAPIModel(ctx, packageType) + if d != nil { + diags.Append(d...) } - return repository.MkResourceSchema( - AlpineLocalSchemas, - packer.Default(AlpineLocalSchemas[CurrentSchemaVersion]), - unpackLocalAlpineRepo, - constructor, + localAPIModel := model.(LocalAPIModel) + localAPIModel.RepoLayoutRef = r.RepoLayoutRef.ValueString() + + return LocalAlpineAPIModel{ + LocalAPIModel: localAPIModel, + PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueStringPointer(), + }, diags +} + +func (r *LocalAlpineResourceModel) FromAPIModel(ctx context.Context, apiModel interface{}) diag.Diagnostics { + diags := diag.Diagnostics{} + + model := apiModel.(*LocalAlpineAPIModel) + + r.LocalResourceModel.FromAPIModel(ctx, model.LocalAPIModel) + + r.RepoLayoutRef = types.StringValue(model.RepoLayoutRef) + r.PrimaryKeyPairRef = types.StringPointerValue(model.PrimaryKeyPairRef) + + return diags +} + +type LocalAlpineAPIModel struct { + LocalAPIModel + PrimaryKeyPairRef *string `json:"primaryKeyPairRef"` +} + +var AlpinePrimaryKeyPairRefAttribute = map[string]schema.Attribute{ + "primary_keypair_ref": schema.StringAttribute{ + Optional: true, + Computed: true, + Default: stringdefault.StaticString(""), + MarkdownDescription: "Used to sign index files in Alpine Linux repositories. " + + "See: https://www.jfrog.com/confluence/display/JFROG/Alpine+Linux+Repositories#AlpineLinuxRepositories-SigningAlpineLinuxIndex", + }, +} + +func (r *localAlpineResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { + attributes := lo.Assign( + LocalAttributes, + repository.RepoLayoutRefAttribute(Rclass, r.PackageType), + AlpinePrimaryKeyPairRefAttribute, ) + + resp.Schema = schema.Schema{ + Version: CurrentSchemaVersion, + Attributes: attributes, + Description: r.Description, + } +} + +var alpineSchema = lo.Assign( + repository.RepoLayoutRefSDKv2Schema(Rclass, repository.AlpinePackageType), + repository.AlpinePrimaryKeyPairRefSDKv2, + repository.CompressionFormatsSDKv2, +) + +var AlpineLocalSchemas = GetSchemas(alpineSchema) + +type AlpineLocalRepoParams struct { + RepositoryBaseParams + repository.PrimaryKeyPairRefParam } diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go index 1c4dc6591..fbc34a9ea 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go @@ -10,7 +10,7 @@ import ( var ansibleSchema = lo.Assign( repository.RepoLayoutRefSDKv2Schema(Rclass, repository.AnsiblePackageType), - repository.AlpinePrimaryKeyPairRef, + repository.AlpinePrimaryKeyPairRefSDKv2, ) var AnsibleSchemas = GetSchemas(ansibleSchema) @@ -25,7 +25,7 @@ func UnpackLocalAnsibleRepository(data *schema.ResourceData, Rclass string) Ansi return AnsibleLocalRepoParams{ RepositoryBaseParams: UnpackBaseRepo(Rclass, data, repository.AnsiblePackageType), PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, } } diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_cargo_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_cargo_repository.go index 30921dc63..ad83c35e4 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_cargo_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_cargo_repository.go @@ -24,7 +24,7 @@ var cargoSchema = lo.Assign( Description: "Enable internal index support based on Cargo sparse index specifications, instead of the default git index. Default value is 'false'.", }, }, - repository.CompressionFormats, + repository.CompressionFormatsSDKv2, ) var CargoSchemas = GetSchemas(cargoSchema) diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go index 19492f8b3..c7a9ed4fe 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go @@ -9,8 +9,8 @@ import ( ) var debianSchema = lo.Assign( - repository.PrimaryKeyPairRef, - repository.SecondaryKeyPairRef, + repository.PrimaryKeyPairRefSDKv2, + repository.SecondaryKeyPairRefSDKv2, map[string]*schema.Schema{ "trivial_layout": { Type: schema.TypeBool, @@ -21,7 +21,7 @@ var debianSchema = lo.Assign( }, }, repository.RepoLayoutRefSDKv2Schema(Rclass, repository.DebianPackageType), - repository.CompressionFormats, + repository.CompressionFormatsSDKv2, ) var DebianSchemas = GetSchemas(debianSchema) @@ -38,10 +38,10 @@ func UnpackLocalDebianRepository(data *schema.ResourceData, Rclass string) Debia d := &utilsdk.ResourceData{ResourceData: data} return DebianLocalRepositoryParams{ PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{ - SecondaryKeyPairRef: d.GetString("secondary_keypair_ref", false), + SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false), }, RepositoryBaseParams: UnpackBaseRepo(Rclass, data, repository.DebianPackageType), TrivialLayout: d.GetBool("trivial_layout", false), diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_generic_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_generic_repository.go index bed43f83b..23a178b57 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_generic_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_generic_repository.go @@ -66,8 +66,7 @@ type localGenericResource struct { type LocalGenericResourceModel struct { LocalResourceModel - RepoLayoutRef types.String `tfsdk:"repo_layout_ref"` - CDNRedirect types.Bool `tfsdk:"cdn_redirect"` + CDNRedirect types.Bool `tfsdk:"cdn_redirect"` } func (r *LocalGenericResourceModel) GetCreateResourcePlanData(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_repository_test.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_repository_test.go index ddf719e59..13258d568 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_repository_test.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_repository_test.go @@ -74,9 +74,8 @@ EOF } resource "artifactory_local_alpine_repository" "{{ .repo_name }}" { - key = "{{ .repo_name }}" + key = "{{ .repo_name }}" primary_keypair_ref = artifactory_keypair.{{ .kp_name }}.pair_name - depends_on = [artifactory_keypair.{{ .kp_name }}] } `, map[string]interface{}{ "kp_id": kpId, @@ -85,8 +84,7 @@ 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, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, CheckDestroy: acctest.CompositeCheckDestroy( acctest.VerifyDeleted(t, fqrn, "", acctest.CheckRepo), acctest.VerifyDeleted(t, kpFqrn, "pair_name", security.VerifyKeyPair), @@ -96,9 +94,11 @@ EOF Config: localRepositoryBasic, Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr(fqrn, "key", name), - resource.TestCheckResourceAttr(fqrn, "package_type", "alpine"), resource.TestCheckResourceAttr(fqrn, "primary_keypair_ref", kpName), - resource.TestCheckResourceAttr(fqrn, "repo_layout_ref", func() string { r, _ := repository.GetDefaultRepoLayoutRef("local", "alpine"); return r }()), //Check to ensure repository layout is set as per default even when it is not passed. + resource.TestCheckResourceAttr(fqrn, "repo_layout_ref", func() string { + r, _ := repository.GetDefaultRepoLayoutRef("local", repository.AlpinePackageType) + return r + }()), //Check to ensure repository layout is set as per default even when it is not passed. ), }, { diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_rpm_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_rpm_repository.go index 443e21235..6588c9e9c 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_rpm_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_rpm_repository.go @@ -10,8 +10,8 @@ import ( ) var rpmSchema = utilsdk.MergeMaps( - repository.PrimaryKeyPairRef, - repository.SecondaryKeyPairRef, + repository.PrimaryKeyPairRefSDKv2, + repository.SecondaryKeyPairRefSDKv2, map[string]*schema.Schema{ "yum_root_depth": { Type: schema.TypeInt, @@ -62,10 +62,10 @@ func UnpackLocalRpmRepository(data *schema.ResourceData, Rclass string) RpmLocal return RpmLocalRepositoryParams{ RepositoryBaseParams: UnpackBaseRepo(Rclass, data, repository.RPMPackageType), PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{ - SecondaryKeyPairRef: d.GetString("secondary_keypair_ref", false), + SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false), }, RootDepth: d.GetInt("yum_root_depth", false), CalculateYumMetadata: d.GetBool("calculate_yum_metadata", false), diff --git a/pkg/artifactory/resource/repository/remote/remote.go b/pkg/artifactory/resource/repository/remote/remote.go index 3da2fe1bd..4947cd9ed 100644 --- a/pkg/artifactory/resource/repository/remote/remote.go +++ b/pkg/artifactory/resource/repository/remote/remote.go @@ -109,7 +109,7 @@ var PackageTypesLikeBasic = []string{ } var baseSchema = lo.Assign( - repository.ProxySchema, + repository.ProxySchemaSDKv2, map[string]*schema.Schema{ "url": { Type: schema.TypeString, diff --git a/pkg/artifactory/resource/repository/repository.go b/pkg/artifactory/resource/repository/repository.go index 93cfc8c4a..d9c8224a7 100644 --- a/pkg/artifactory/resource/repository/repository.go +++ b/pkg/artifactory/resource/repository/repository.go @@ -623,7 +623,7 @@ var BaseSchemaV1 = map[string]*sdkv2_schema.Schema{ }, } -var ProxySchema = map[string]*sdkv2_schema.Schema{ +var ProxySchemaSDKv2 = map[string]*sdkv2_schema.Schema{ "proxy": { Type: sdkv2_schema.TypeString, Optional: true, @@ -637,7 +637,7 @@ var ProxySchema = map[string]*sdkv2_schema.Schema{ }, } -var CompressionFormats = map[string]*sdkv2_schema.Schema{ +var CompressionFormatsSDKv2 = map[string]*sdkv2_schema.Schema{ "index_compression_formats": { Type: sdkv2_schema.TypeSet, Elem: &sdkv2_schema.Schema{ @@ -648,7 +648,7 @@ var CompressionFormats = map[string]*sdkv2_schema.Schema{ }, } -var AlpinePrimaryKeyPairRef = map[string]*sdkv2_schema.Schema{ +var AlpinePrimaryKeyPairRefSDKv2 = map[string]*sdkv2_schema.Schema{ "primary_keypair_ref": { Type: sdkv2_schema.TypeString, Optional: true, @@ -657,7 +657,7 @@ var AlpinePrimaryKeyPairRef = map[string]*sdkv2_schema.Schema{ }, } -var PrimaryKeyPairRef = map[string]*sdkv2_schema.Schema{ +var PrimaryKeyPairRefSDKv2 = map[string]*sdkv2_schema.Schema{ "primary_keypair_ref": { Type: sdkv2_schema.TypeString, Optional: true, @@ -666,7 +666,7 @@ var PrimaryKeyPairRef = map[string]*sdkv2_schema.Schema{ }, } -var SecondaryKeyPairRef = map[string]*sdkv2_schema.Schema{ +var SecondaryKeyPairRefSDKv2 = map[string]*sdkv2_schema.Schema{ "secondary_keypair_ref": { Type: sdkv2_schema.TypeString, Optional: true, @@ -676,11 +676,11 @@ var SecondaryKeyPairRef = map[string]*sdkv2_schema.Schema{ } type PrimaryKeyPairRefParam struct { - PrimaryKeyPairRef string `hcl:"primary_keypair_ref" json:"primaryKeyPairRef"` + PrimaryKeyPairRefSDKv2 string `hcl:"primary_keypair_ref" json:"primaryKeyPairRef"` } type SecondaryKeyPairRefParam struct { - SecondaryKeyPairRef string `hcl:"secondary_keypair_ref" json:"secondaryKeyPairRef"` + SecondaryKeyPairRefSDKv2 string `hcl:"secondary_keypair_ref" json:"secondaryKeyPairRef"` } type ContentSynchronisation struct { diff --git a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_alpine_repository.go b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_alpine_repository.go index a51cdcd1b..965e6af1e 100644 --- a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_alpine_repository.go +++ b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_alpine_repository.go @@ -10,7 +10,7 @@ import ( var alpineSchema = lo.Assign( RetrievalCachePeriodSecondsSchema, - repository.PrimaryKeyPairRef, + repository.PrimaryKeyPairRefSDKv2, repository.RepoLayoutRefSDKv2Schema(Rclass, repository.AlpinePackageType), ) @@ -28,7 +28,7 @@ func ResourceArtifactoryVirtualAlpineRepository() *schema.Resource { repo := AlpineVirtualRepositoryParams{ RepositoryBaseParamsWithRetrievalCachePeriodSecs: UnpackBaseVirtRepoWithRetrievalCachePeriodSecs(s, repository.AlpinePackageType), PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, } repo.PackageType = repository.AlpinePackageType diff --git a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_debian_repository.go b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_debian_repository.go index 17c4fb368..d49b5fb63 100644 --- a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_debian_repository.go +++ b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_debian_repository.go @@ -13,8 +13,8 @@ import ( var debianSchema = lo.Assign( RetrievalCachePeriodSecondsSchema, - repository.PrimaryKeyPairRef, - repository.SecondaryKeyPairRef, + repository.PrimaryKeyPairRefSDKv2, + repository.SecondaryKeyPairRefSDKv2, map[string]*schema.Schema{ "optional_index_compression_formats": { Type: schema.TypeSet, @@ -56,10 +56,10 @@ func ResourceArtifactoryVirtualDebianRepository() *schema.Resource { repo := DebianVirtualRepositoryParams{ RepositoryBaseParamsWithRetrievalCachePeriodSecs: UnpackBaseVirtRepoWithRetrievalCachePeriodSecs(s, repository.DebianPackageType), PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{ - SecondaryKeyPairRef: d.GetString("secondary_keypair_ref", false), + SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false), }, OptionalIndexCompressionFormats: d.GetSet("optional_index_compression_formats"), DebianDefaultArchitectures: d.GetString("debian_default_architectures", false), diff --git a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_rpm_repository.go b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_rpm_repository.go index 53289ecbd..0e2abf842 100644 --- a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_rpm_repository.go +++ b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_rpm_repository.go @@ -9,8 +9,8 @@ import ( ) var rpmSchema = lo.Assign( - repository.PrimaryKeyPairRef, - repository.SecondaryKeyPairRef, + repository.PrimaryKeyPairRefSDKv2, + repository.SecondaryKeyPairRefSDKv2, repository.RepoLayoutRefSDKv2Schema(Rclass, repository.RPMPackageType), ) @@ -34,10 +34,10 @@ func ResourceArtifactoryVirtualRpmRepository() *schema.Resource { RepositoryBaseParams: UnpackBaseVirtRepo(s, "rpm"), CommonRpmDebianVirtualRepositoryParams: CommonRpmDebianVirtualRepositoryParams{ PrimaryKeyPairRefParam: repository.PrimaryKeyPairRefParam{ - PrimaryKeyPairRef: d.GetString("primary_keypair_ref", false), + PrimaryKeyPairRefSDKv2: d.GetString("primary_keypair_ref", false), }, SecondaryKeyPairRefParam: repository.SecondaryKeyPairRefParam{ - SecondaryKeyPairRef: d.GetString("secondary_keypair_ref", false), + SecondaryKeyPairRefSDKv2: d.GetString("secondary_keypair_ref", false), }, }, } From 662768f0affc27b6ce5a91682483240625ff9ace Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Wed, 8 Jan 2025 15:11:07 -0800 Subject: [PATCH 2/8] Migrate local repositories to Plugin Framework Sensible, Cargo, Conan, Debian, Docker v1 and v2 --- ...rce_artifactory_local_alpine_repository.go | 49 +- pkg/artifactory/provider/framework.go | 7 +- pkg/artifactory/provider/resources.go | 6 - ..._artifactory_federated_cargo_repository.go | 12 +- ...artifactory_federated_debian_repository.go | 17 +- ...artifactory_federated_docker_repository.go | 26 +- .../resource/repository/local/local.go | 20 + ...rce_artifactory_local_alpine_repository.go | 19 +- ...rtifactory_local_alpine_repository_test.go | 107 ++++ ...ce_artifactory_local_ansible_repository.go | 142 +++-- ...tifactory_local_ansible_repository_test.go | 107 ++++ ...urce_artifactory_local_cargo_repository.go | 167 ++++-- ...artifactory_local_cargo_repository_test.go | 54 ++ ...urce_artifactory_local_conan_repository.go | 155 ++++-- ...artifactory_local_conan_repository_test.go | 51 ++ ...rce_artifactory_local_debian_repository.go | 178 ++++-- ...rtifactory_local_debian_repository_test.go | 155 ++++++ ...rce_artifactory_local_docker_repository.go | 155 ------ ..._artifactory_local_docker_v1_repository.go | 184 ++++++ ...factory_local_docker_v1_repository_test.go | 54 ++ ..._artifactory_local_docker_v2_repository.go | 221 ++++++++ ...factory_local_docker_v2_repository_test.go | 86 +++ ...ource_artifactory_local_repository_test.go | 526 ------------------ .../resource/repository/repository.go | 27 + 24 files changed, 1629 insertions(+), 896 deletions(-) create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_cargo_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_conan_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository_test.go delete mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_repository.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v1_repository.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v1_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository_test.go diff --git a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go index 381f5a47b..2398a160e 100644 --- a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go +++ b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_alpine_repository.go @@ -1,41 +1,26 @@ package local import ( - "context" - - "github.com/hashicorp/terraform-plugin-framework/datasource" - "github.com/hashicorp/terraform-plugin-framework/datasource/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/datasource/repository" + resource_repository "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-shared/packer" ) -var _ datasource.DataSource = &AlpineLocalRepositoryDataSource{} - -type AlpineLocalRepositoryDataSource struct{} - -func (d *AlpineLocalRepositoryDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { - resp.TypeName = "artifactory_local_alpine_repository" -} +func DataSourceArtifactoryLocalAlpineRepository() *schema.Resource { + constructor := func() (interface{}, error) { + return &local.AlpineLocalRepoParams{ + RepositoryBaseParams: local.RepositoryBaseParams{ + PackageType: resource_repository.AlpinePackageType, + Rclass: local.Rclass, + }, + }, nil + } -func (d *AlpineLocalRepositoryDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { - resp.Schema = schema.Schema{ - Attributes: local.AlpineLocalRepositoryAttributes, + return &schema.Resource{ + Schema: local.AlpineLocalSchemas[local.CurrentSchemaVersion], + ReadContext: repository.MkRepoReadDataSource(packer.Default(local.AlpineLocalSchemas[local.CurrentSchemaVersion]), constructor), + Description: "Data source for a local alpine repository", } } - -// -// func DataSourceArtifactoryLocalAlpineRepository() *schema.Resource { -// constructor := func() (interface{}, error) { -// return &local.AlpineLocalRepoParams{ -// RepositoryBaseParams: local.RepositoryBaseParams{ -// PackageType: resource_repository.AlpinePackageType, -// Rclass: local.Rclass, -// }, -// }, nil -// } -// -// return &schema.Resource{ -// Schema: local.AlpineLocalSchemas[local.CurrentSchemaVersion], -// ReadContext: repository.MkRepoReadDataSource(packer.Default(local.AlpineLocalSchemas[local.CurrentSchemaVersion]), constructor), -// Description: "Data source for a local alpine repository", -// } -// } diff --git a/pkg/artifactory/provider/framework.go b/pkg/artifactory/provider/framework.go index 5e2f6d81c..b84e13337 100644 --- a/pkg/artifactory/provider/framework.go +++ b/pkg/artifactory/provider/framework.go @@ -247,6 +247,12 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R replication.NewLocalRepositoryMultiReplicationResource, replication.NewRemoteRepositoryReplicationResource, local.NewAlpineLocalRepositoryResource, + local.NewAnsibleLocalRepositoryResource, + local.NewCargoLocalRepositoryResource, + local.NewConanLocalRepositoryResource, + local.NewDebianLocalRepositoryResource, + local.NewDockerV2LocalRepositoryResource, + local.NewDockerV1LocalRepositoryResource, local.NewMachineLearningLocalRepositoryResource, webhook.NewArtifactWebhookResource, webhook.NewArtifactCustomWebhookResource, @@ -279,7 +285,6 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R // DataSources satisfies the provider.Provider interface for ArtifactoryProvider. func (p *ArtifactoryProvider) DataSources(_ context.Context) []func() datasource.DataSource { return []func() datasource.DataSource{ - datasource_repository.NewAlpineLocalRepositoryDataSource, datasource_repository.NewRepositoriesDataSource, datasource_artifact.NewFileListDataSource, } diff --git a/pkg/artifactory/provider/resources.go b/pkg/artifactory/provider/resources.go index 13c7841d5..5dcc1f099 100644 --- a/pkg/artifactory/provider/resources.go +++ b/pkg/artifactory/provider/resources.go @@ -32,12 +32,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_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(), diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_cargo_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_cargo_repository.go index b1d180806..656a86323 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_cargo_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_cargo_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 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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_debian_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_debian_repository.go index d84b01d63..13bd4a5e1 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_debian_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_debian_repository.go @@ -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], @@ -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), } diff --git a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_docker_repository.go b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_docker_repository.go index 650466fa9..d9890bda1 100644 --- a/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_docker_repository.go +++ b/pkg/artifactory/resource/repository/federated/resource_artifactory_federated_docker_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,17 @@ type DockerFederatedRepositoryParams struct { RepoParams } +func unpackLocalDockerV2Repository(data *schema.ResourceData, Rclass string) local.DockerLocalRepositoryParams { + d := &utilsdk.ResourceData{ResourceData: data} + return local.DockerLocalRepositoryParams{ + RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.DockerPackageType), + MaxUniqueTags: d.GetInt("max_unique_tags", false), + DockerApiVersion: "V2", + TagRetention: d.GetInt("tag_retention", false), + BlockPushingSchema1: d.GetBool("block_pushing_schema1", false), + } +} + func ResourceArtifactoryFederatedDockerV2Repository() *schema.Resource { dockerV2FederatedSchema := lo.Assign( local.DockerV2Schemas[local.CurrentSchemaVersion], @@ -24,7 +36,7 @@ func ResourceArtifactoryFederatedDockerV2Repository() *schema.Resource { var unpackFederatedDockerRepository = func(data *schema.ResourceData) (interface{}, string, error) { repo := DockerFederatedRepositoryParams{ - DockerLocalRepositoryParams: local.UnpackLocalDockerV2Repository(data, Rclass), + DockerLocalRepositoryParams: unpackLocalDockerV2Repository(data, Rclass), Members: unpackMembers(data), RepoParams: unpackRepoParams(data), } @@ -60,6 +72,16 @@ func ResourceArtifactoryFederatedDockerV2Repository() *schema.Resource { return mkResourceSchema(dockerV2FederatedSchema, pkr, unpackFederatedDockerRepository, constructor) } +func unpackLocalDockerV1Repository(data *schema.ResourceData, Rclass string) local.DockerLocalRepositoryParams { + return local.DockerLocalRepositoryParams{ + RepositoryBaseParams: local.UnpackBaseRepo(Rclass, data, repository.DockerPackageType), + DockerApiVersion: "V1", + MaxUniqueTags: 0, + TagRetention: 1, + BlockPushingSchema1: false, + } +} + func ResourceArtifactoryFederatedDockerV1Repository() *schema.Resource { dockerFederatedSchema := lo.Assign( local.DockerV1Schemas[local.CurrentSchemaVersion], @@ -69,7 +91,7 @@ func ResourceArtifactoryFederatedDockerV1Repository() *schema.Resource { var unpackFederatedDockerRepository = func(data *schema.ResourceData) (interface{}, string, error) { repo := DockerFederatedRepositoryParams{ - DockerLocalRepositoryParams: local.UnpackLocalDockerV1Repository(data, Rclass), + DockerLocalRepositoryParams: unpackLocalDockerV1Repository(data, Rclass), 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 cc1d06b41..31c1ad938 100644 --- a/pkg/artifactory/resource/repository/local/local.go +++ b/pkg/artifactory/resource/repository/local/local.go @@ -2,6 +2,8 @@ package local import ( "context" + "fmt" + "reflect" "strings" "github.com/hashicorp/terraform-plugin-framework-validators/setvalidator" @@ -13,6 +15,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/types" sdkv2_schema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" + "github.com/jfrog/terraform-provider-shared/util" utilsdk "github.com/jfrog/terraform-provider-shared/util/sdk" "github.com/samber/lo" ) @@ -22,6 +25,23 @@ const ( CurrentSchemaVersion = 1 ) +func NewLocalRepositoryResource(packageType 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), + PackageType: packageType, + Rclass: Rclass, + ResourceModelType: resourceModelType, + APIModelType: apiModelType, + }, + } +} + type localResource struct { repository.BaseResource } 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 63d09b791..b8f35f8b6 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 @@ -2,7 +2,6 @@ package local import ( "context" - "fmt" "reflect" "github.com/hashicorp/terraform-plugin-framework/diag" @@ -11,26 +10,12 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" - "github.com/jfrog/terraform-provider-shared/util" "github.com/samber/lo" ) func NewAlpineLocalRepositoryResource() resource.Resource { return &localAlpineResource{ - localResource: localResource{ - BaseResource: repository.BaseResource{ - JFrogResource: util.JFrogResource{ - TypeName: fmt.Sprintf("artifactory_local_%s_repository", repository.AlpinePackageType), - CollectionEndpoint: "artifactory/api/repositories", - DocumentEndpoint: "artifactory/api/repositories/{key}", - }, - Description: "Provides a resource to creates a Alpine repository.", - PackageType: repository.AlpinePackageType, - Rclass: Rclass, - ResourceModelType: reflect.TypeFor[LocalAlpineResourceModel](), - APIModelType: reflect.TypeFor[LocalAlpineAPIModel](), - }, - }, + localResource: NewLocalRepositoryResource(repository.AlpinePackageType, reflect.TypeFor[LocalAlpineResourceModel](), reflect.TypeFor[LocalAlpineAPIModel]()), } } @@ -126,7 +111,7 @@ var AlpinePrimaryKeyPairRefAttribute = map[string]schema.Attribute{ func (r *localAlpineResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { attributes := lo.Assign( LocalAttributes, - repository.RepoLayoutRefAttribute(Rclass, r.PackageType), + repository.RepoLayoutRefAttribute(r.Rclass, r.PackageType), AlpinePrimaryKeyPairRefAttribute, ) 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 new file mode 100644 index 000000000..8c7355142 --- /dev/null +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_alpine_repository_test.go @@ -0,0 +1,107 @@ +package local_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "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" + "github.com/jfrog/terraform-provider-shared/testutil" + "github.com/jfrog/terraform-provider-shared/util" + "github.com/jfrog/terraform-provider-shared/validator" +) + +func TestAccLocalAlpineRepository(t *testing.T) { + _, fqrn, name := testutil.MkNames("alpine-local-test-repo", "artifactory_local_alpine_repository") + kpId, kpFqrn, kpName := testutil.MkNames("some-keypair", "artifactory_keypair") + localRepositoryBasic := util.ExecuteTemplate("keypair", ` + resource "artifactory_keypair" "{{ .kp_name }}" { + pair_name = "{{ .kp_name }}" + pair_type = "RSA" + alias = "foo-alias{{ .kp_id }}" + private_key = < Date: Thu, 9 Jan 2025 15:09:18 -0800 Subject: [PATCH 3/8] Migrate remaining local repositories --- pkg/artifactory/provider/framework.go | 20 +- pkg/artifactory/provider/resources.go | 10 - ...rtifactory_federated_helmoci_repository.go | 12 +- ...e_artifactory_federated_java_repository.go | 16 +- ..._artifactory_federated_nuget_repository.go | 12 +- ...ce_artifactory_federated_oci_repository.go | 13 +- ...ce_artifactory_federated_rpm_repository.go | 20 +- ...ifactory_federated_terraform_repository.go | 9 +- .../resource/repository/local/local.go | 4 +- ...rce_artifactory_local_alpine_repository.go | 7 +- ...rtifactory_local_alpine_repository_test.go | 96 +++ ...ce_artifactory_local_ansible_repository.go | 7 +- ...tifactory_local_ansible_repository_test.go | 96 +++ ...urce_artifactory_local_cargo_repository.go | 7 +- ...artifactory_local_cargo_repository_test.go | 44 ++ ...urce_artifactory_local_conan_repository.go | 1 + ...artifactory_local_conan_repository_test.go | 42 ++ ...rce_artifactory_local_debian_repository.go | 1 + ...rtifactory_local_debian_repository_test.go | 139 +++++ ..._artifactory_local_docker_v1_repository.go | 2 +- ...factory_local_docker_v1_repository_test.go | 47 +- ..._artifactory_local_docker_v2_repository.go | 2 +- ...factory_local_docker_v2_repository_test.go | 46 ++ ...ce_artifactory_local_generic_repository.go | 22 +- ...tifactory_local_generic_repository_test.go | 88 ++- ...ce_artifactory_local_helmoci_repository.go | 183 ++++-- ...tifactory_local_helmoci_repository_test.go | 98 +++ ...ource_artifactory_local_java_repository.go | 266 +++++++-- ..._artifactory_local_java_repository_test.go | 203 +++++++ ...actory_local_machinelearning_repository.go | 22 +- ...urce_artifactory_local_nuget_repository.go | 206 +++++-- ...artifactory_local_nuget_repository_test.go | 95 +++ ...source_artifactory_local_oci_repository.go | 185 ++++-- ...e_artifactory_local_oci_repository_test.go | 125 ++++ ...ource_artifactory_local_repository_test.go | 563 ------------------ ...source_artifactory_local_rpm_repository.go | 235 ++++++-- ...e_artifactory_local_rpm_repository_test.go | 299 ++++++++++ ..._artifactory_local_terraform_repository.go | 154 ++++- ...factory_local_terraform_repository_test.go | 162 +++++ .../resource/repository/repository.go | 26 + 40 files changed, 2702 insertions(+), 883 deletions(-) create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_helmoci_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_java_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_nuget_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_oci_repository_test.go delete mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_rpm_repository_test.go create mode 100644 pkg/artifactory/resource/repository/local/resource_artifactory_local_terraform_repository_test.go diff --git a/pkg/artifactory/provider/framework.go b/pkg/artifactory/provider/framework.go index b84e13337..be6440f84 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 5dcc1f099..92948e273 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 25ea0fd42..acfc4f820 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 eef631aaa..a41a5240f 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 73f4c0c3c..0b5a69d3b 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 1f8329bc0..132800dba 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 5379edaae..7a8dc1fef 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 1f5ce3bfa..0764db62e 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 31c1ad938..88225b4f4 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 b8f35f8b6..81efcf17c 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 8c7355142..24616b63a 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 = < Date: Thu, 9 Jan 2025 15:25:42 -0800 Subject: [PATCH 4/8] Update CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a376a2dc1..0443ed70a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 12.8.1 (January 10, 2025) + +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.0 (January 8, 2025). Tested on Artifactory 7.98.13 with Terraform 1.10.3 and OpenTofu 1.8.8 FEATURES: From d55838986901e77ed75506fb3e599e2c34ef16a3 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Thu, 9 Jan 2025 15:46:56 -0800 Subject: [PATCH 5/8] Add `ddeb_supported` and `trivial_layout` attributes for Debian local repo Fix datasource tests --- ...ource_artifactory_local_repository_test.go | 47 ++++++------------- .../datasource/repository/local/local.go | 3 -- ...rce_artifactory_local_debian_repository.go | 23 +++++++++ ...rtifactory_local_debian_repository_test.go | 5 ++ 4 files changed, 43 insertions(+), 35 deletions(-) delete mode 100644 pkg/artifactory/datasource/repository/local/local.go diff --git a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_repository_test.go b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_repository_test.go index d7ada5104..6b268ca4c 100644 --- a/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_repository_test.go +++ b/pkg/artifactory/datasource/repository/local/datasource_artifactory_local_repository_test.go @@ -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, @@ -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, @@ -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 }}" { @@ -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{ { @@ -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, @@ -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, @@ -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), @@ -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), @@ -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, @@ -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, @@ -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, @@ -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), @@ -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, @@ -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, diff --git a/pkg/artifactory/datasource/repository/local/local.go b/pkg/artifactory/datasource/repository/local/local.go deleted file mode 100644 index b31fcb10a..000000000 --- a/pkg/artifactory/datasource/repository/local/local.go +++ /dev/null @@ -1,3 +0,0 @@ -package local - -const rclass = "local" diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go index 2161e89a3..bb99ac721 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository.go @@ -7,6 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/types" sdkv2_schema "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/jfrog/terraform-provider-artifactory/v12/pkg/artifactory/resource/repository" @@ -33,6 +34,8 @@ type LocalDebianResourceModel struct { PrimaryKeyPairRef types.String `tfsdk:"primary_keypair_ref"` SecondaryKeyPairRef types.String `tfsdk:"secondary_keypair_ref"` CompressionFormats types.Set `tfsdk:"index_compression_formats"` + TrivialLayout types.Bool `tfsdk:"trivial_layout"` + DdebSupported types.Bool `tfsdk:"ddeb_supported"` } func (r *LocalDebianResourceModel) GetCreateResourcePlanData(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { @@ -92,6 +95,8 @@ func (r LocalDebianResourceModel) ToAPIModel(ctx context.Context, packageType st PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueString(), SecondaryKeyPairRef: r.SecondaryKeyPairRef.ValueString(), CompressionFormats: compressionFormats, + TrivialLayout: r.TrivialLayout.ValueBool(), + DdebSupported: r.DdebSupported.ValueBool(), }, diags } @@ -111,6 +116,8 @@ func (r *LocalDebianResourceModel) FromAPIModel(ctx context.Context, apiModel in } r.CompressionFormats = compressionFormats + r.TrivialLayout = types.BoolValue(model.TrivialLayout) + r.DdebSupported = types.BoolValue(model.DdebSupported) return diags } @@ -120,6 +127,8 @@ type LocalDebianAPIModel struct { PrimaryKeyPairRef string `json:"primaryKeyPairRef"` SecondaryKeyPairRef string `json:"secondaryKeyPairRef"` CompressionFormats []string `json:"optionalIndexCompressionFormats,omitempty"` + TrivialLayout bool `json:"debianTrivialLayout"` + DdebSupported bool `json:"ddebSupported"` } func (r *localDebianResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { @@ -129,6 +138,20 @@ func (r *localDebianResource) Schema(ctx context.Context, req resource.SchemaReq repository.CompressionFormatsAttribute, repository.PrimaryKeyPairRefAttribute, repository.SecondaryKeyPairRefAttribute, + map[string]schema.Attribute{ + "trivial_layout": schema.BoolAttribute{ + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + MarkdownDescription: "When set, the repository will use the deprecated trivial layout.", + }, + "ddeb_supported": schema.BoolAttribute{ + Optional: true, + Computed: true, + Default: booldefault.StaticBool(false), + MarkdownDescription: "When set, enable indexing with debug symbols (.ddeb).", + }, + }, ) resp.Schema = schema.Schema{ diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository_test.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository_test.go index ad7079a64..96ea32f91 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository_test.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_debian_repository_test.go @@ -113,6 +113,8 @@ EOF primary_keypair_ref = artifactory_keypair.{{ .kp_name }}.pair_name secondary_keypair_ref = artifactory_keypair.{{ .kp_name2 }}.pair_name index_compression_formats = ["bz2","lzma","xz"] + trivial_layout = true + ddeb_supported = true } `, map[string]interface{}{ "kp_id": kpId, @@ -143,6 +145,8 @@ EOF r, _ := repository.GetDefaultRepoLayoutRef("local", repository.DebianPackageType) return r }()), //Check to ensure repository layout is set as per default even when it is not passed. + resource.TestCheckResourceAttr(fqrn, "trivial_layout", "true"), + resource.TestCheckResourceAttr(fqrn, "ddeb_supported", "true"), ), }, { @@ -256,6 +260,7 @@ EOF primary_keypair_ref = artifactory_keypair.{{ .kp_name }}.pair_name secondary_keypair_ref = artifactory_keypair.{{ .kp_name2 }}.pair_name index_compression_formats = ["bz2","lzma","xz"] + trivial_layout = true } `, map[string]interface{}{ "kp_id": kpId, From 9fb8114b850a08101dcb1e054eb3431b582f1a9d Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Fri, 10 Jan 2025 09:37:54 -0800 Subject: [PATCH 6/8] Fix incorrect default for docker v2 local repo Fix tests --- pkg/artifactory/datasource/repository/local/local.go | 3 +++ .../resource_artifactory_local_docker_v2_repository.go | 6 +++--- .../virtual/resource_artifactory_virtual_repository_test.go | 5 ++--- .../webhook/resource_artifactory_webhook_repo_test.go | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 pkg/artifactory/datasource/repository/local/local.go diff --git a/pkg/artifactory/datasource/repository/local/local.go b/pkg/artifactory/datasource/repository/local/local.go new file mode 100644 index 000000000..b31fcb10a --- /dev/null +++ b/pkg/artifactory/datasource/repository/local/local.go @@ -0,0 +1,3 @@ +package local + +const rclass = "local" diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository.go index 3e82ec1f4..5f9ce8086 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_docker_v2_repository.go @@ -151,11 +151,11 @@ func (r *localDockerV2Resource) Schema(ctx context.Context, req resource.SchemaR "tag_retention": schema.Int64Attribute{ Optional: true, Computed: true, - Default: int64default.StaticInt64(1), + Default: int64default.StaticInt64(0), Validators: []validator.Int64{ - int64validator.AtLeast(1), + int64validator.AtLeast(0), }, - MarkdownDescription: "If greater than 1, overwritten tags will be saved by their digest, up to the set up number. This only applies to manifest V2", + MarkdownDescription: "If greater than 1, overwritten tags will be saved by their digest, up to the set up number.", }, "block_pushing_schema1": schema.BoolAttribute{ Optional: true, diff --git a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_repository_test.go b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_repository_test.go index bdf678e58..8e2cffc03 100644 --- a/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_repository_test.go +++ b/pkg/artifactory/resource/repository/virtual/resource_artifactory_virtual_repository_test.go @@ -83,9 +83,8 @@ func TestAccVirtualRepository_reset_default_deployment_repo(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{ { diff --git a/pkg/artifactory/resource/webhook/resource_artifactory_webhook_repo_test.go b/pkg/artifactory/resource/webhook/resource_artifactory_webhook_repo_test.go index ae67feda3..7a4b5e281 100644 --- a/pkg/artifactory/resource/webhook/resource_artifactory_webhook_repo_test.go +++ b/pkg/artifactory/resource/webhook/resource_artifactory_webhook_repo_test.go @@ -305,7 +305,7 @@ func webhookMigrateFromSDKv2TestCase(webhookType string, t *testing.T) (*testing }, { Config: config, - ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories, + ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories, ConfigPlanChecks: resource.ConfigPlanChecks{ PreApply: []plancheck.PlanCheck{ plancheck.ExpectEmptyPlan(), From 45138b398a94a918f0f307cbac93716774772654 Mon Sep 17 00:00:00 2001 From: Alex Hung Date: Fri, 10 Jan 2025 10:18:50 -0800 Subject: [PATCH 7/8] Fix primary_keypair_ref attribute handling --- .../repository/datasource_artifactory_repositories_test.go | 1 - .../local/resource_artifactory_local_alpine_repository.go | 6 +++--- .../local/resource_artifactory_local_ansible_repository.go | 6 +++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/artifactory/datasource/repository/datasource_artifactory_repositories_test.go b/pkg/artifactory/datasource/repository/datasource_artifactory_repositories_test.go index 8221d9222..78b1a665a 100644 --- a/pkg/artifactory/datasource/repository/datasource_artifactory_repositories_test.go +++ b/pkg/artifactory/datasource/repository/datasource_artifactory_repositories_test.go @@ -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{ { 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 81efcf17c..8ec55811b 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 @@ -81,7 +81,7 @@ func (r LocalAlpineResourceModel) ToAPIModel(ctx context.Context, packageType st return LocalAlpineAPIModel{ LocalAPIModel: localAPIModel, - PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueStringPointer(), + PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueString(), }, diags } @@ -93,14 +93,14 @@ func (r *LocalAlpineResourceModel) FromAPIModel(ctx context.Context, apiModel in r.LocalResourceModel.FromAPIModel(ctx, model.LocalAPIModel) r.RepoLayoutRef = types.StringValue(model.RepoLayoutRef) - r.PrimaryKeyPairRef = types.StringPointerValue(model.PrimaryKeyPairRef) + r.PrimaryKeyPairRef = types.StringValue(model.PrimaryKeyPairRef) return diags } type LocalAlpineAPIModel struct { LocalAPIModel - PrimaryKeyPairRef *string `json:"primaryKeyPairRef"` + PrimaryKeyPairRef string `json:"primaryKeyPairRef"` } var AlpinePrimaryKeyPairRefAttribute = map[string]schema.Attribute{ diff --git a/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go b/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go index 7b76fd990..01163104d 100644 --- a/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go +++ b/pkg/artifactory/resource/repository/local/resource_artifactory_local_ansible_repository.go @@ -80,7 +80,7 @@ func (r LocalAnsibleResourceModel) ToAPIModel(ctx context.Context, packageType s return LocalAnsibleAPIModel{ LocalAPIModel: localAPIModel, - PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueStringPointer(), + PrimaryKeyPairRef: r.PrimaryKeyPairRef.ValueString(), }, diags } @@ -92,14 +92,14 @@ func (r *LocalAnsibleResourceModel) FromAPIModel(ctx context.Context, apiModel i r.LocalResourceModel.FromAPIModel(ctx, model.LocalAPIModel) r.RepoLayoutRef = types.StringValue(model.RepoLayoutRef) - r.PrimaryKeyPairRef = types.StringPointerValue(model.PrimaryKeyPairRef) + r.PrimaryKeyPairRef = types.StringValue(model.PrimaryKeyPairRef) return diags } type LocalAnsibleAPIModel struct { LocalAPIModel - PrimaryKeyPairRef *string `json:"primaryKeyPairRef"` + PrimaryKeyPairRef string `json:"primaryKeyPairRef"` } func (r *localAnsibleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { From 64a41829c9dff87b215694bcd9143886113cdbf0 Mon Sep 17 00:00:00 2001 From: JFrog CI Date: Fri, 10 Jan 2025 18:50:05 +0000 Subject: [PATCH 8/8] JFrog Pipelines - Add Artifactory version to CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0443ed70a..3c97e8a6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 12.8.1 (January 10, 2025) +## 12.8.1 (January 10, 2025). Tested on Artifactory 7.98.13 with Terraform 1.10.4 and OpenTofu 1.9.0 IMPROVEMENTS: