diff --git a/.VERSION b/.VERSION index e21e727f..6fea73af 100644 --- a/.VERSION +++ b/.VERSION @@ -1 +1 @@ -1.4.0 \ No newline at end of file +1.4.1-beta01 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b8d65c..83799038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,14 @@ --- +[//]: # (START/v1.4.1-beta01) +# v1.4.1-beta01 + +## Fixes +* Using provider on Terraform Cloud. {#116} + +--- + [//]: # (START/v1.4.0) # v1.4.0 diff --git a/onepassword/cli/op.go b/onepassword/cli/op.go index 5983d67c..ba7d7c55 100644 --- a/onepassword/cli/op.go +++ b/onepassword/cli/op.go @@ -14,6 +14,10 @@ import ( "github.com/hashicorp/terraform-plugin-log/tflog" ) +const ( + minimumOpCliVersion = "2.23.0" // introduction of stdin json support for `op item update` +) + type OP struct { binaryPath string serviceAccountToken string @@ -41,7 +45,22 @@ func (op *OP) GetVersion(ctx context.Context) (*semver.Version, error) { return version, nil } +func (op *OP) checkCliVersion(ctx context.Context) error { + cliVersion, err := op.GetVersion(ctx) + if err != nil { + return fmt.Errorf("failed to get version of op CLI: %w", err) + } + if cliVersion.LessThan(semver.MustParse(minimumOpCliVersion)) { + return fmt.Errorf("current 1Password CLI version is \"%s\". Please upgrade to at least \"%s\"", cliVersion, minimumOpCliVersion) + } + return nil +} + func (op *OP) GetVault(ctx context.Context, uuid string) (*onepassword.Vault, error) { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return nil, versionErr + } var res *onepassword.Vault err := op.execJson(ctx, &res, nil, p("vault"), p("get"), p(uuid)) if err != nil { @@ -51,6 +70,10 @@ func (op *OP) GetVault(ctx context.Context, uuid string) (*onepassword.Vault, er } func (op *OP) GetVaultsByTitle(ctx context.Context, title string) ([]onepassword.Vault, error) { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return nil, versionErr + } var allVaults []onepassword.Vault err := op.execJson(ctx, &allVaults, nil, p("vault"), p("list")) if err != nil { @@ -67,6 +90,10 @@ func (op *OP) GetVaultsByTitle(ctx context.Context, title string) ([]onepassword } func (op *OP) GetItem(ctx context.Context, itemUuid, vaultUuid string) (*onepassword.Item, error) { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return nil, versionErr + } var res *onepassword.Item err := op.execJson(ctx, &res, nil, p("item"), p("get"), p(itemUuid), f("vault", vaultUuid)) if err != nil { @@ -80,6 +107,10 @@ func (op *OP) GetItemByTitle(ctx context.Context, title string, vaultUuid string } func (op *OP) CreateItem(ctx context.Context, item *onepassword.Item, vaultUuid string) (*onepassword.Item, error) { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return nil, versionErr + } return op.withRetry(func() (*onepassword.Item, error) { return op.create(ctx, item, vaultUuid) }) @@ -116,6 +147,10 @@ func (op *OP) create(ctx context.Context, item *onepassword.Item, vaultUuid stri } func (op *OP) UpdateItem(ctx context.Context, item *onepassword.Item, vaultUuid string) (*onepassword.Item, error) { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return nil, versionErr + } return op.withRetry(func() (*onepassword.Item, error) { return op.update(ctx, item, vaultUuid) }) @@ -141,6 +176,10 @@ func (op *OP) update(ctx context.Context, item *onepassword.Item, vaultUuid stri } func (op *OP) DeleteItem(ctx context.Context, item *onepassword.Item, vaultUuid string) error { + versionErr := op.checkCliVersion(ctx) + if versionErr != nil { + return versionErr + } _, err := op.withRetry(func() (*onepassword.Item, error) { return op.delete(ctx, item, vaultUuid) }) diff --git a/onepassword/provider.go b/onepassword/provider.go index 13a08de4..1430551d 100644 --- a/onepassword/provider.go +++ b/onepassword/provider.go @@ -9,14 +9,12 @@ import ( "github.com/1Password/terraform-provider-onepassword/onepassword/cli" "github.com/1Password/terraform-provider-onepassword/onepassword/connectctx" "github.com/1Password/terraform-provider-onepassword/version" - "github.com/Masterminds/semver/v3" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) const ( terraformProviderUserAgent = "terraform-provider-connect/%s" - minimumOpCliVersion = "2.23.0" // introduction of stdin json support for `op item update` ) func init() { @@ -124,14 +122,6 @@ func initializeCLI(ctx context.Context, serviceAccountToken, account, opCliPath op = cli.New(serviceAccountToken, opCliPath, "") } - cliVersion, err := op.GetVersion(ctx) - if err != nil { - return nil, diag.FromErr(fmt.Errorf("failed to get version of op CLI: %w", err)) - } - if cliVersion.LessThan(semver.MustParse(minimumOpCliVersion)) { - return nil, diag.Errorf("Current 1Password CLI version is \"%s\". Please upgrade to at least \"%s\".", cliVersion, minimumOpCliVersion) - } - return op, nil }