Skip to content

Commit

Permalink
Merge pull request #820 from jfrog/GH-818-remove-default-value-from-e…
Browse files Browse the repository at this point in the history
…xpires-in

Remove default value for `artifactory_scoped_token.expires_in`
  • Loading branch information
alexhung authored Oct 6, 2023
2 parents d813096 + 7767125 commit b1cd6a9
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 9.3.1 (Oct 6, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.6.0

BUG FIX:
* resource/artifactory_scoped_token: Remove default value for `expires_in` attribute which should fix state drift when upgrading from 7.11.2 or earlier. Issue: [#818](https://github.com/jfrog/terraform-provider-artifactory/issues/818) PR: [#820](https://github.com/jfrog/terraform-provider-artifactory/pull/820)

## 9.3.0 (Oct 3, 2023). Tested on Artifactory 7.68.13 with Terraform CLI v1.5.7

IMPROVEMENTS:
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/scoped_token.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "artifactory_scoped_token" "audience" {

- `audiences` (Set of String) A list of the other instances or services that should accept this token identified by their Service-IDs. Limited to total 255 characters. Default to '*@*' if not set. Service ID must begin with valid JFrog service type. Options: jfrt, jfxr, jfpip, jfds, jfmc, jfac, jfevt, jfmd, jfcon, or *. For instructions to retrieve the Artifactory Service ID see this [documentation](https://jfrog.com/help/r/jfrog-rest-apis/get-service-id)
- `description` (String) Free text token description. Useful for filtering and managing tokens. Limited to 1024 characters.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/revoke-token-by-id) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
- `expires_in` (Number) The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/create-token) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.
- `grant_type` (String) The grant type used to authenticate the request. In this case, the only value supported is `client_credentials` which is also the default value if this parameter is not specified.
- `include_reference_token` (Boolean) Also create a reference token which can be used like an API key.
- `refreshable` (Boolean) Is this token refreshable? Default is `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64default"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
Expand Down Expand Up @@ -198,7 +197,6 @@ func (r *ScopedTokenResource) Schema(ctx context.Context, req resource.SchemaReq
MarkdownDescription: "The amount of time, in seconds, it would take for the token to expire. An admin shall be able to set whether expiry is mandatory, what is the default expiry, and what is the maximum expiry allowed. Must be non-negative. Default value is based on configuration in 'access.config.yaml'. See [API documentation](https://jfrog.com/help/r/jfrog-rest-apis/revoke-token-by-id) for details. Access Token would not be saved by Artifactory if this is less than the persistence threshold value (default to 10800 seconds) set in Access configuration. See [official documentation](https://jfrog.com/help/r/jfrog-platform-administration-documentation/using-the-revocable-and-persistency-thresholds) for details.",
Optional: true,
Computed: true,
Default: int64default.StaticInt64(0),
PlanModifiers: []planmodifier.Int64{
int64planmodifier.RequiresReplaceIfConfigured(),
int64planmodifier.UseStateForUnknown(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,64 @@ func TestAccScopedToken_UpgradeGH_792(t *testing.T) {
})
}

func TestAccScopedToken_UpgradeGH_818(t *testing.T) {
_, fqrn, name := testutil.MkNames("test-scope-token", "artifactory_scoped_token")
config := utilsdk.ExecuteTemplate(
"TestAccScopedToken",
`resource "artifactory_user" "test-user" {
name = "testuser"
email = "[email protected]"
admin = true
disable_ui_access = false
groups = ["readers"]
password = "Passw0rd!"
}
resource "artifactory_scoped_token" "{{ .name }}" {
scopes = ["applied-permissions/user"]
username = artifactory_user.test-user.name
}`,
map[string]interface{}{
"name": name,
},
)

resource.Test(t, resource.TestCase{
Steps: []resource.TestStep{
{
ExternalProviders: map[string]resource.ExternalProvider{
"artifactory": {
VersionConstraint: "7.2.0",
Source: "registry.terraform.io/jfrog/artifactory",
},
},
Config: config,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(fqrn, "username", "testuser"),
resource.TestCheckResourceAttr(fqrn, "scopes.#", "1"),
resource.TestCheckResourceAttr(fqrn, "expires_in", "31536000"),
resource.TestCheckNoResourceAttr(fqrn, "audiences"),
resource.TestCheckResourceAttrSet(fqrn, "access_token"),
resource.TestCheckNoResourceAttr(fqrn, "refresh_token"),
resource.TestCheckNoResourceAttr(fqrn, "reference_token"),
resource.TestCheckResourceAttr(fqrn, "token_type", "Bearer"),
resource.TestCheckResourceAttrSet(fqrn, "subject"),
resource.TestCheckResourceAttrSet(fqrn, "expiry"),
resource.TestCheckResourceAttrSet(fqrn, "issued_at"),
resource.TestCheckResourceAttrSet(fqrn, "issuer"),
),
ConfigPlanChecks: acctest.ConfigPlanChecks,
},
{
ProtoV5ProviderFactories: acctest.ProtoV5MuxProviderFactories,
Config: config,
PlanOnly: true,
ConfigPlanChecks: acctest.ConfigPlanChecks,
},
},
})
}

func scopedTokenUpgradeTestCase(version string, t *testing.T) (*testing.T, resource.TestCase) {
_, fqrn, name := testutil.MkNames("test-access-token", "artifactory_scoped_token")

Expand Down Expand Up @@ -246,7 +304,7 @@ func TestAccScopedToken_WithAttributes(t *testing.T) {
scopes = ["applied-permissions/admin", "system:metrics:r"]
description = "test description"
refreshable = true
expires_in = 31536000
expires_in = 0
audiences = ["jfrt@1", "jfxr@*"]
}`,
map[string]interface{}{
Expand Down Expand Up @@ -275,7 +333,7 @@ func TestAccScopedToken_WithAttributes(t *testing.T) {
resource.TestCheckTypeSetElemAttr(fqrn, "scopes.*", "applied-permissions/admin"),
resource.TestCheckTypeSetElemAttr(fqrn, "scopes.*", "system:metrics:r"),
resource.TestCheckResourceAttr(fqrn, "refreshable", "true"),
resource.TestCheckResourceAttr(fqrn, "expires_in", "31536000"),
resource.TestCheckResourceAttr(fqrn, "expires_in", "0"),
resource.TestCheckResourceAttr(fqrn, "description", "test description"),
resource.TestCheckResourceAttr(fqrn, "audiences.#", "2"),
resource.TestCheckTypeSetElemAttr(fqrn, "audiences.*", "jfrt@1"),
Expand Down

0 comments on commit b1cd6a9

Please sign in to comment.