Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to Terraform provider framework #167

Merged
merged 36 commits into from
May 15, 2024

Commits on May 2, 2024

  1. Update all Go packages to the latest version

    Run the following commands:
    - `go get -u ./...`
    - `go mod tidy`
    - `go mod vendor`
    
    With this, we also update Go version to 1.21.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    69982a8 View commit details
    Browse the repository at this point in the history
  2. Add provider framework dependencies and update packages

    - Move `github.com/hashicorp/terraform-plugin-framework` package from indirect dependency to direct dependency
    - `go get -u ./...`
    - `go mod tidy`
    - `go mod vendor`
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    a5f346c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    fae4cfb View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    16353d9 View commit details
    Browse the repository at this point in the history
  5. Remove provider function scaffolding

    Currently, the provider doesn't implement any functions. Therefore, these files are removed.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    beedbb2 View commit details
    Browse the repository at this point in the history
  6. Implement 1Password Client interface

    This client will be used by the provider to create, read, update and delete items using either Connect or 1Password CLI.
    
    This client is also capable of fetching vault data.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    614906e View commit details
    Browse the repository at this point in the history
  7. Add Connect client

    Changes made compared to `onepassword/connectctx/wrapper.go`
    - NewClient function is now responsible of creating the Connect client with user agent.
    - Renaming the struct for clarity and cleanliness.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    1ffaa67 View commit details
    Browse the repository at this point in the history
  8. Add CLI client

    Changes made compared to the code in `internal/onepassword/cli` directory:
    - New function is renamed to NewClient and implements the initializeCLI function
    - Enable password generation when updating an item (to be consistent with the Connect client).
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    b1d648f View commit details
    Browse the repository at this point in the history
  9. Implement new 1Password client function

    This function will return either the Connect or the CLI client.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    96117be View commit details
    Browse the repository at this point in the history
  10. Define OnePassword provider

    - Name the struct as OnePasswordProvider
    - Implement provider schema
    - Implement provider data model
    
    What changed from the previous implementation is that we marked the service account token and connect token as sensitive.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    c813650 View commit details
    Browse the repository at this point in the history
  11. Add provider configuration functionality

    - Load default values from environment variables
    - Initialize the 1Password client (either Connect or CLI client based on the configuration)
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    750ee46 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    54b104c View commit details
    Browse the repository at this point in the history
  13. Add framework validator package

    This is used to add validators to schemas (e.g. dependencies between attributes). Some of these will be used by the vault data source.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    c912599 View commit details
    Browse the repository at this point in the history
  14. Define vault data source schema and model

    With the vault data source fully implemented, we add it to the list of data sources the provider supports.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    47ede0a View commit details
    Browse the repository at this point in the history
  15. Add constants for attribute descriptions

    Changes made here as part of the migration:
    - Add a new constant `terraformItemIDDescription` which will be used for both item resource and data source for consistency.
    - The slices of categories, field purposes, and field types are now based on the constants available in the Connect Go SDK to eliminate hardcoding the string values (these apply to both Connect and CLI clients).
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    a96b298 View commit details
    Browse the repository at this point in the history
  16. Rename scaffolding files

    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    7648c0b View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    865371c View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    7d1f3c9 View commit details
    Browse the repository at this point in the history
  19. Add additional packages in vendor

    These new ones are used by the item resource schema.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    967dc53 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    6fbe23b View commit details
    Browse the repository at this point in the history
  21. Implement custom value modifier

    With the new framework, Terraform wants to be more predictable, therefore any computed values will be recomputed whenever something in the resource changes.
    
    What this modifier does is that it will use the existing value in the state unless one of the following two scenarios happen:
    - The value is set to a specific new one in the plan.
    - The password recipe (which was used to generate it) is changed.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    a6f169e View commit details
    Browse the repository at this point in the history
  22. Implement itemToData function

    This converts an item into a data source model. It’s a rewrite of the same function that exists in the old provider code.
    
    A couple of improvements have been added as part of the migration:
    - No longer throw cause Terraform to trigger a change or an inconsistency error if the tags are the same, but in different order. This is because 1Password sorts the tags alphabetically, which can have a different order than the one tags passed in Terraform have.
    - With the new framework, Terraform will throw an inconsistency error if the planned value is null (i.e. not set) and the result is empty string). That's why we use the custom `setStringValue` function to set a value on each attribute based on the actual value in 1Password.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    f2f9b01 View commit details
    Browse the repository at this point in the history
  23. Implement dataToItem function

    This converts the Terraform data into a 1Password item. It's a rewrite of the same function that exists in the old provider code.
    
    We also implemented the functions associated to it:
    - parseGeneratorRecipe - currently missing the case in which the attribute is not defined (or Nil)
    - addRecipe - identical to the one in the old provider code
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    d1f801b View commit details
    Browse the repository at this point in the history
  24. Add vaultAndItemUUID function

    This function extracts the vault and item UUIDs from the terraform ID.
    
    This matches the function with the same name from the old provider code.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    1810a11 View commit details
    Browse the repository at this point in the history
  25. Implement rest of functions for item resource

    Implement configure, create, read, update and delete functions for item resource
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    fdfe03b View commit details
    Browse the repository at this point in the history
  26. Add test server logic and item generation helpers

    These will help with the following:
    - easily generate the items that we will use for testing.
    - have a mock server that will act as a Connect server during the tests.
    
    Co-authored-by: jillianwilson <jillian.morgan@agilebits.com>
    edif2008 and jillianwilson committed May 2, 2024
    Configuration menu
    Copy the full SHA
    4a975a8 View commit details
    Browse the repository at this point in the history
  27. Configure the testing provider

    Co-authored-by: jillianwilson <jillian.morgan@agilebits.com>
    edif2008 and jillianwilson committed May 2, 2024
    Configuration menu
    Copy the full SHA
    ef19767 View commit details
    Browse the repository at this point in the history
  28. Add tests for vault data source

    Co-authored-by: jillianwilson <jillian.morgan@agilebits.com>
    edif2008 and jillianwilson committed May 2, 2024
    Configuration menu
    Copy the full SHA
    f45f3c8 View commit details
    Browse the repository at this point in the history
  29. Add tests for item data source

    Co-authored-by: jillianwilson <jillian.morgan@agilebits.com>
    edif2008 and jillianwilson committed May 2, 2024
    Configuration menu
    Copy the full SHA
    e71cbc8 View commit details
    Browse the repository at this point in the history
  30. Add tests for item resource

    Co-authored-by: jillianwilson <jillian.morgan@agilebits.com>
    edif2008 and jillianwilson committed May 2, 2024
    Configuration menu
    Copy the full SHA
    2f1c752 View commit details
    Browse the repository at this point in the history
  31. Remove copyright

    This came as part of the scaffolding. We remove it since the 1Password Terraform provider is under the MIT license.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    743477b View commit details
    Browse the repository at this point in the history
  32. Add other improvements as part of the migration

    - Add make command for running acceptance tests.
    - Update conditional compilation for tools package. Since Go 1.18 the new conditional compilation is `//go:build` instead of `// + build`.
    - Add terraform-registry-manifest.json file. This file is part of the new framework structure. It's used by the terraform registry to get additional data about the provider being published. For details check this link: https://developer.hashicorp.com/terraform/registry/providers/publishing#terraform-registry-manifest-file
    - Update goreleaser to use the registry manifest file
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    576e7a5 View commit details
    Browse the repository at this point in the history
  33. Update and improve docs

    Update the docs based on the migrated provider and add small improvements to existing examples.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    bb22670 View commit details
    Browse the repository at this point in the history
  34. Update GitHub Action versions used in pipeline

    We also do the following adjustments:
    - Update Go version in the pipeline to 1.21.
    - Run the test step with TF_ACC=1 to enable acceptance tests (which are the ones we implemented in the migration).
    - Switch the `paultyng/ghaction-import-gpg@v2.1.0` action to `crazy-max/ghaction-import-gpg@v6` since the previous one is deprecated and it was recommended to use the upstream action that we now use.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    31cc8e7 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    0792838 View commit details
    Browse the repository at this point in the history
  36. Add validator for IDs for OTP field

    Field of type OTP require a special field ID. Adding this validator achieves the following:
    - Ensures that the user will have a functional OTP field.
    - Terraform will not throw inconsistency errors when the CLI tries to correct the custom ID for OTP field.
    edif2008 committed May 2, 2024
    Configuration menu
    Copy the full SHA
    025df7d View commit details
    Browse the repository at this point in the history