Skip to content

Commit

Permalink
Merge pull request #946 from jfrog/GH-944-make-username-replace-on-ch…
Browse files Browse the repository at this point in the history
…ange

Make user name replace on change
  • Loading branch information
alexhung authored Apr 30, 2024
2 parents 771dcfa + 1bf57b0 commit 88cf465
Show file tree
Hide file tree
Showing 20 changed files with 228 additions and 125 deletions.
12 changes: 9 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
## 10.7.3 (May 1, 2024)

BUG FIXES:

* resource/artifactory_managed_user, resource/artifactory_unmanaged_user, resource/artifactory_user: Make `name` attribute trigger resource replacement if changed. Issue: [#944](https://github.com/jfrog/terraform-provider-artifactory/issues/944) PR: [#946](https://github.com/jfrog/terraform-provider-artifactory/pull/946)

## 10.7.2 (Apr 26, 2024)

BUG FIXES:

resource/artifactory_proxy: Fix hidden state drifts with resource created using SDKv2 (i.e. <= 10.1.0). Issue: [#941](https://github.com/jfrog/terraform-provider-artifactory/issues/941) PR: [#943](https://github.com/jfrog/terraform-provider-artifactory/pull/943)
* resource/artifactory_proxy: Fix hidden state drifts with resource created using SDKv2 (i.e. <= 10.1.0). Issue: [#941](https://github.com/jfrog/terraform-provider-artifactory/issues/941) PR: [#943](https://github.com/jfrog/terraform-provider-artifactory/pull/943)

## 10.7.1 (Apr 25, 2024)

BUG FIXES:

resource/artifactory_managed_user, resource/artifactory_unmanaged_user, resource/artifactory_user: Toggle between using (old) Artifactory Security API and (new) Access API based on Artifactory version 7.84.3 due to Access API bug in updating user without password field. Issue: [#931](https://github.com/jfrog/terraform-provider-artifactory/issues/931) PR: [#940](https://github.com/jfrog/terraform-provider-artifactory/pull/940)
* resource/artifactory_managed_user, resource/artifactory_unmanaged_user, resource/artifactory_user: Toggle between using (old) Artifactory Security API and (new) Access API based on Artifactory version 7.84.3 due to Access API bug in updating user without password field. Issue: [#931](https://github.com/jfrog/terraform-provider-artifactory/issues/931) PR: [#940](https://github.com/jfrog/terraform-provider-artifactory/pull/940)

## 10.7.0 (Apr 18, 2024)

Expand All @@ -20,7 +26,7 @@ FEATURES:

BUG FIXES:

resource/artifactory_unmanaged_user, resource/artifactory_user: Revert storing auto-generated `password` attribute value in Terraform state. Revert back to Artifactory Security API until Artifactory version 7.83.1 due to Access API bug in updating user without password field. Issue: [#931](https://github.com/jfrog/terraform-provider-artifactory/issues/931) PR: [#937](https://github.com/jfrog/terraform-provider-artifactory/pull/937)
* resource/artifactory_unmanaged_user, resource/artifactory_user: Revert storing auto-generated `password` attribute value in Terraform state. Revert back to Artifactory Security API until Artifactory version 7.83.1 due to Access API bug in updating user without password field. Issue: [#931](https://github.com/jfrog/terraform-provider-artifactory/issues/931) PR: [#937](https://github.com/jfrog/terraform-provider-artifactory/pull/937)

IMPROVEMENTS:

Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/google/go-querystring v1.1.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/terraform-json v0.18.0
github.com/hashicorp/terraform-plugin-docs v0.16.0
github.com/hashicorp/terraform-plugin-framework v1.5.0
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
Expand All @@ -17,7 +16,7 @@ require (
github.com/hashicorp/terraform-plugin-mux v0.12.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.30.0
github.com/hashicorp/terraform-plugin-testing v1.5.1
github.com/jfrog/terraform-provider-shared v1.24.0
github.com/jfrog/terraform-provider-shared v1.25.0
github.com/samber/lo v1.39.0
github.com/sethvargo/go-password v0.2.0
github.com/stretchr/testify v1.8.4
Expand All @@ -27,6 +26,8 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require github.com/hashicorp/terraform-json v0.18.0 // indirect

require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ github.com/imdario/mergo v0.3.15 h1:M8XP7IuFNsqUx6VPK2P9OSmsYsI/YFaGil0uD21V3dM=
github.com/imdario/mergo v0.3.15/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
github.com/jfrog/terraform-provider-shared v1.24.0 h1:VItpElBn9Jku8gtN7DhOURUIyoUYYw8R9erPBPgKwv8=
github.com/jfrog/terraform-provider-shared v1.24.0/go.mod h1:OozwvfahZU4Q9u3kXdpQI3h/Etrs2DXoouQDrpxB1cQ=
github.com/jfrog/terraform-provider-shared v1.25.0 h1:FyubiyixS7QnUXb1JKKo957tCFZO2xVKSPLyKzBnvKk=
github.com/jfrog/terraform-provider-shared v1.25.0/go.mod h1:L987Z8XO4cuv7ys4Tw6sP/LESw7z0Dji0U2ysR8FUP4=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=
Expand Down
83 changes: 0 additions & 83 deletions pkg/acctest/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package acctest

import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
Expand All @@ -12,16 +11,12 @@ import (

"github.com/go-resty/resty/v2"
"github.com/hashicorp/go-version"
tfjson "github.com/hashicorp/terraform-json"
"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-mux/tf5to6server"
"github.com/hashicorp/terraform-plugin-mux/tf6muxserver"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
terraform2 "github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/plancheck"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/jfrog/terraform-provider-artifactory/v10/pkg/artifactory/provider"
"github.com/jfrog/terraform-provider-artifactory/v10/pkg/artifactory/resource/configuration"
Expand All @@ -30,7 +25,6 @@ import (
"github.com/jfrog/terraform-provider-shared/client"
"github.com/jfrog/terraform-provider-shared/testutil"
"github.com/jfrog/terraform-provider-shared/util"
"github.com/samber/lo"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -381,80 +375,3 @@ func CompareArtifactoryVersions(t *testing.T, instanceVersions string) (bool, er
}
return skipTest, nil
}

var ConfigPlanChecks = resource.ConfigPlanChecks{
PostApplyPreRefresh: []plancheck.PlanCheck{
DebugPlan("PostApplyPreRefresh"),
},
PostApplyPostRefresh: []plancheck.PlanCheck{
DebugPlan("PostApplyPostRefresh"),
},
}

var _ plancheck.PlanCheck = PlanCheck{}

type PlanCheck struct {
Stage string
}

func (p PlanCheck) CheckPlan(ctx context.Context, req plancheck.CheckPlanRequest, resp *plancheck.CheckPlanResponse) {
var err error

rc, err := json.Marshal(req.Plan.ResourceChanges[0])
if err != nil {
resp.Error = err
return
}

pv, err := json.Marshal(req.Plan.PlannedValues)
if err != nil {
resp.Error = err
return
}

ps, err := json.Marshal(req.Plan.PriorState)
if err != nil {
resp.Error = err
return
}

rd, err := json.Marshal(req.Plan.ResourceDrift)
if err != nil {
resp.Error = err
return
}

tflog.Debug(ctx, "CheckPlan", map[string]interface{}{
"stage": p.Stage,
"req.Plan.ResourceChanges.ResourceDrift": string(rd),
"req.Plan.ResourceChanges": string(rc),
"req.Plan.PlannedValues": string(pv),
"req.Plan.PriorState": string(ps),
})

if len(req.Plan.ResourceDrift) > 0 {
drifts := lo.Map(req.Plan.ResourceDrift, func(c *tfjson.ResourceChange, index int) string {
return fmt.Sprintf("Name: %s, Before: %v, After: %v", c.Name, c.Change.Before, c.Change.After)
})
resp.Error = fmt.Errorf("expected empty plan, but has resouce drifts(s): %v", strings.Join(drifts, ", "))
return
}

var errStrings []string
for _, rc := range req.Plan.ResourceChanges {
if !rc.Change.Actions.NoOp() {
errStrings = append(errStrings, fmt.Sprintf("expected empty plan, but %s has planned action(s): %v\n\nbefore: %v\n\nafter: %v\n\nunknown: %v", rc.Address, rc.Change.Actions, rc.Change.Before, rc.Change.After, rc.Change.AfterUnknown))
}
}

if len(errStrings) > 0 {
resp.Error = fmt.Errorf(strings.Join(errStrings, "\n"))
return
}
}

func DebugPlan(stage string) plancheck.PlanCheck {
return PlanCheck{
Stage: stage,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestAccLdapGroupSettingV2_full(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "description_attribute", "description"),
resource.TestCheckResourceAttr(fqrn, "strategy", "STATIC"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
Config: LdapSettingTemplateFullUpdate,
Expand All @@ -85,7 +85,7 @@ func TestAccLdapGroupSettingV2_full(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "description_attribute", "description"),
resource.TestCheckResourceAttr(fqrn, "strategy", "DYNAMIC"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ResourceName: fqrn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestAccLdapSettingV2_full_no_search(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "user_dn_pattern", params["user_dn_pattern"].(string)),
resource.TestCheckResourceAttr(fqrn, "email_attribute", "mail_attr"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ResourceName: fqrn,
Expand Down Expand Up @@ -102,7 +102,7 @@ func TestAccLdapSettingV2_full_with_search(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "search_filter", "(uid={0})"),
resource.TestCheckResourceAttr(fqrn, "search_base", params["search_base"].(string)),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ResourceName: fqrn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestAccPropertySet_UpgradeFromSDKv2(t *testing.T) {
},
Config: config,
Check: resource.ComposeTestCheckFunc(verifyPropertySet(fqrn, testData)),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func TestAccProxy_UpgradeFromSDKv2(t *testing.T) {
resource.TestCheckNoResourceAttr(fqrn, "redirect_to_hosts"),
resource.TestCheckNoResourceAttr(fqrn, "services"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ func TestAccRepositoryLayout_UpgradeFromSDKv2(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "folder_integration_revision_regexp", "SNAPSHOT"),
resource.TestCheckResourceAttr(fqrn, "file_integration_revision_regexp", "SNAPSHOT|(?:(?:[0-9]{8}.[0-9]{6})-(?:[0-9]+))"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func TestAccRemoteUpgradeFromVersionWithNoDisableProxyAttr(t *testing.T) {
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func TestAccCertificate_UpgradeFromSDKv2(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "issued_to", "Unknown"),
resource.TestCheckResourceAttr(fqrn, "valid_until", "2029-05-14T10:03:26.000Z"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ func TestAccDistributionPublicKey_UpgradeFromSDKv2(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "fingerprint", "10:16:2c:c5:1c:db:d0:59:ad:86:d3:66:dc:d1:d9:02:65:03:a8:25"),
resource.TestCheckResourceAttr(fqrn, "issued_by", "alan <[email protected]>"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Config: keyBasic,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func TestAccGroup_UpgradeFromSDKv2(t *testing.T) {
resource.TestCheckNoResourceAttr(fqrn, "users_names"),
resource.TestCheckResourceAttr(fqrn, "watch_manager", "false"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ EOF
resource.TestCheckResourceAttr(fqrn, "passphrase", "password"),
resource.TestCheckResourceAttr(fqrn, "unavailable", "false"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Config: keyPairConfig,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ func TestAccPermissionTarget_MigrateFromFrameworkBackToSDKv2(t *testing.T) {
resource.TestCheckResourceAttr(fqrn, "build.#", "1"),
resource.TestCheckResourceAttr(fqrn, "release_bundle.#", "1"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
{
ProtoV6ProviderFactories: acctest.ProtoV6MuxProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
ConfigPlanChecks: testutil.ConfigPlanChecks,
},
},
})
Expand Down
Loading

0 comments on commit 88cf465

Please sign in to comment.