Skip to content

Commit

Permalink
Merge branch 'master' into jfrogGH-621-bulk-import
Browse files Browse the repository at this point in the history
  • Loading branch information
chb0github authored Oct 6, 2023
2 parents 4083ecd + 79db6fa commit 7fb6218
Show file tree
Hide file tree
Showing 9 changed files with 510 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .jfrog-pipelines/TFproviderTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,4 @@ pipelines:
send_notification partnership_slack --text "${pipeline_name} failed on <${step_url}|${step_name}> step."
fi
onComplete:
- echo "Cleaning up"
- echo "Cleaning up"
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 9.3.0 (Oct 3, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.5.7

IMPROVEMENTS:

* resource/artifactory_distribution_public_key is migrated to Plugin Framework. PR: [#817](https://github.com/jfrog/terraform-provider-artifactory/pull/817)
* resource/artifactory_remote_\*\_repository: Fix incorrect default value for `store_artifacts_locally` attribute in documentation. PR: [#816](https://github.com/jfrog/terraform-provider-artifactory/pull/816)


## 9.2.1 (Sep 29, 2023). Tested on Artifactory 7.68.11 with Terraform CLI v1.5.7

IMPROVEMENTS:
Expand Down
1 change: 1 addition & 0 deletions pkg/artifactory/provider/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ func (p *ArtifactoryProvider) Resources(ctx context.Context) []func() resource.R
security.NewScopedTokenResource,
security.NewPermissionTargetResource,
security.NewGlobalEnvironmentResource,
security.NewDistributionPublicKeyResource,
configuration.NewLdapSettingResource,
configuration.NewLdapGroupSettingResource,
configuration.NewBackupResource,
Expand Down
1 change: 0 additions & 1 deletion pkg/artifactory/provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ func resourcesMap() map[string]*schema.Resource {
"artifactory_certificate": security.ResourceArtifactoryCertificate(),
"artifactory_api_key": security.ResourceArtifactoryApiKey(),
"artifactory_access_token": security.ResourceArtifactoryAccessToken(),
"artifactory_distribution_public_key": security.ResourceArtifactoryDistributionPublicKey(),
"artifactory_general_security": configuration.ResourceArtifactoryGeneralSecurity(),
"artifactory_oauth_settings": configuration.ResourceArtifactoryOauthSettings(),
"artifactory_saml_settings": configuration.ResourceArtifactorySamlSettings(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,14 @@ func (r *BackupResource) Create(ctx context.Context, req resource.CreateRequest,
}

func (r *BackupResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
var data *BackupResourceModel
var state *BackupResourceModel
// Read Terraform prior state data into the model
resp.Diagnostics.Append(req.State.Get(ctx, &data)...)
resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
if resp.Diagnostics.HasError() {
return
}

backups := Backups{}
var backups Backups
_, err := r.ProviderData.Client.R().
SetResult(&backups).
Get("artifactory/api/system/configuration")
Expand All @@ -262,26 +262,26 @@ func (r *BackupResource) Read(ctx context.Context, req resource.ReadRequest, res
return
}

matchedBackup := FindConfigurationById[BackupAPIModel](backups.BackupArr, data.Key.ValueString())
matchedBackup := FindConfigurationById[BackupAPIModel](backups.BackupArr, state.Key.ValueString())
if matchedBackup == nil {
resp.Diagnostics.AddAttributeWarning(
path.Root("key"),
"no matching backup found",
data.Key.ValueString(),
state.Key.ValueString(),
)
resp.State.RemoveResource(ctx)
return
}

// Convert from the API data model to the Terraform data model
// and refresh any attribute values.
resp.Diagnostics.Append(data.FromAPIModel(ctx, matchedBackup)...)
resp.Diagnostics.Append(state.FromAPIModel(ctx, matchedBackup)...)
if resp.Diagnostics.HasError() {
return
}

// Save updated data into Terraform state
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

func (r *BackupResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
Expand Down Expand Up @@ -340,16 +340,10 @@ func (r *BackupResource) Delete(ctx context.Context, req resource.DeleteRequest,
return
}

var backup BackupAPIModel
resp.Diagnostics.Append(data.toAPIModel(ctx, &backup)...)
if resp.Diagnostics.HasError() {
return
}

deleteBackupConfig := fmt.Sprintf(`
backups:
%s: ~
`, backup.Key)
`, data.Key.ValueString())

err := SendConfigurationPatch([]byte(deleteBackupConfig), r.ProviderData)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"encoding/hex"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"strings"

Expand Down Expand Up @@ -71,7 +70,7 @@ func ResourceArtifactoryCertificate() *schema.Resource {
if _, err := os.Stat(value.(string)); err != nil {
return nil, append(errors, err)
}
data, err := ioutil.ReadFile(value.(string))
data, err := os.ReadFile(value.(string))
if err != nil {
return nil, append(errors, err)
}
Expand Down Expand Up @@ -109,7 +108,7 @@ func ResourceArtifactoryCertificate() *schema.Resource {
}

func calculateFingerprint(_ context.Context, d *schema.ResourceDiff, _ interface{}) error {
content, err := getContentFromDiff(d)
content, _ := getContentFromDiff(d)
fingerprint, err := calculateFingerPrint(content)
if err != nil {
return err
Expand Down Expand Up @@ -203,7 +202,7 @@ func resourceCertificateRead(_ context.Context, d *schema.ResourceData, m interf
setValue("issued_to", (*cert).IssuedTo)
errors := setValue("valid_until", (*cert).ValidUntil)

if errors != nil && len(errors) > 0 {
if len(errors) > 0 {
return diag.Errorf("failed to pack certificate %q", errors)
}

Expand All @@ -227,7 +226,7 @@ func getContentFromDiff(d *schema.ResourceDiff) (string, error) {
return content.(string), nil
}
if fileExists {
data, err := ioutil.ReadFile(file.(string))
data, err := os.ReadFile(file.(string))
if err != nil {
return "", err
}
Expand All @@ -242,7 +241,7 @@ func getContentFromData(d *schema.ResourceData) (string, error) {
return content.(string), nil
}
if file, ok := d.GetOk("file"); ok {
data, err := ioutil.ReadFile(file.(string))
data, err := os.ReadFile(file.(string))
if err != nil {
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestAccCertHasFileAndContentFails(t *testing.T) {
},
})
}

func TestAccCertWithFileMissing(t *testing.T) {
const certWithMissingFile = `
resource "artifactory_certificate" "fail" {
Expand Down
Loading

0 comments on commit 7fb6218

Please sign in to comment.