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

feat: add new tool versions datasource #580

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Conversation

Apollorion
Copy link
Member

@Apollorion Apollorion commented Oct 31, 2024

Description of the change

Introduce new tool versions datasource, will list out supported tool versions for KUBECTL, OPEN_TOFU, TERRAFORM_FOSS, and TERRAGRUNT.

data "spacelift_tool_versions" "test" {
    tool = "TERRAFORM_FOSS"
}

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (non-breaking change that adds documentation)

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • Examples for new resources and data sources have been added
  • Default values have been documented in the description (e.g., "Dummy: (Boolean) Blah blah. Defaults to false.)
  • If the action fails that checks the documentation: Run go generate to make sure the docs are up to date

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Pull Request is no longer marked as "draft"
  • Reviewers have been assigned
  • Changes have been reviewed by at least one other engineer

@Apollorion Apollorion force-pushed the supported-versions branch 7 times, most recently from 28586d8 to 7e17c96 Compare October 31, 2024 16:41
@Apollorion Apollorion requested review from a team October 31, 2024 16:44
@Apollorion Apollorion force-pushed the supported-versions branch 3 times, most recently from e2b7304 to 1720813 Compare October 31, 2024 16:56
peterdeme
peterdeme previously approved these changes Oct 31, 2024
@Apollorion Apollorion force-pushed the supported-versions branch 5 times, most recently from 7cac4af to 1e57602 Compare October 31, 2024 21:06
@Apollorion
Copy link
Member Author

Im not entirely sure why the test is failing, are these queries gated in some fashion that I cannot see? I cant imagine it, all these queries work even anonymously.

I thought this might have been a difference in the way the provider is authenticated to spacelift in CI vs my local, but the tests pass locally no matter how I authenticate (generated token vs api key and id).

Built the plugin and ran it with tofu:

$ tofu apply
╷
│ Warning: Provider development overrides are in effect
│
│ The following provider development overrides are set in the CLI configuration:
│  - spacelift.io/spacelift-io/spacelift in /Users/apollorion/projects/src/github.com/spacelift-io/terraform-provider-spacelift/dist/terraform-provider-spacelift_darwin_arm64
│
│ The behavior may therefore not match any released version of the provider and applying changes may cause the state to become incompatible with published releases.
╵
data.spacelift_tool_versions.kubectl: Reading...
data.spacelift_tool_versions.terragrunt: Reading...
data.spacelift_tool_versions.terraform: Reading...
data.spacelift_tool_versions.opentofu: Reading...
data.spacelift_tool_versions.terragrunt: Read complete after 0s [id=spacelift-versions]
data.spacelift_tool_versions.opentofu: Read complete after 1s [id=spacelift-versions]
data.spacelift_tool_versions.kubectl: Read complete after 1s [id=spacelift-versions]
data.spacelift_tool_versions.terraform: Read complete after 1s [id=spacelift-versions]

Changes to Outputs:
  + kubectl    = {
      + id       = "spacelift-versions"
      + tool     = "KUBECTL"
      + versions = [
          + "1.31.1",
          + "1.31.0",
          + "1.30.5",
          ...(edited for brevity)
        ]
    }
  + terraform  = {
      + id       = "spacelift-versions"
      + tool     = "TERRAFORM_FOSS"
      + versions = [
          + "1.5.7",
          + "1.5.6",
          + "1.5.5",
          ...(edited for brevity)
        ]
    }
  + terragrunt = {
      + id       = "spacelift-versions"
      + tool     = "TERRAGRUNT"
      + versions = [
          + "0.67.2",
          + "0.67.1",
          + "0.67.0",
          ...(edited for brevity)
        ]
    }
  + tofu       = {
      + id       = "spacelift-versions"
      + tool     = "OPEN_TOFU"
      + versions = [
          + "1.8.4",
          + "1.8.3",
          + "1.8.2",
          ...(edited for brevity)
        ]
    }

I can also run the tests with no problem locally:

$ go test ./... -run 'TestToolVersionsData'
?   	github.com/spacelift-io/terraform-provider-spacelift	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs/search	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs/search/predicates	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/structs/vcs	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/testhelpers	[no test files]
?   	github.com/spacelift-io/terraform-provider-spacelift/spacelift/internal/validations	[no test files]
ok  	github.com/spacelift-io/terraform-provider-spacelift/spacelift	32.917s

The error says Error running pre-apply refresh, but Im able to also run tofu refresh with no problems:

$ tofu refresh
data.spacelift_tool_versions.kubectl: Reading...
data.spacelift_tool_versions.opentofu: Reading...
data.spacelift_tool_versions.terragrunt: Reading...
data.spacelift_tool_versions.terraform: Reading...
data.spacelift_tool_versions.kubectl: Read complete after 0s [id=spacelift-versions]
data.spacelift_tool_versions.terragrunt: Read complete after 0s [id=spacelift-versions]
data.spacelift_tool_versions.terraform: Read complete after 0s [id=spacelift-versions]
data.spacelift_tool_versions.opentofu: Read complete after 0s [id=spacelift-versions]
╷
│ Warning: Empty or non-existent state
│
│ There are currently no remote objects tracked in the state, so there is nothing to refresh.
╵

I dont see what the difference is between CI and my local.

peterdeme
peterdeme previously approved these changes Oct 31, 2024
Copy link
Contributor

@adamconnelly adamconnelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left one question, but other than that LGTM!

spacelift/data_tool_versions.go Outdated Show resolved Hide resolved
@adamconnelly
Copy link
Contributor

@Apollorion the reason the tests are failing in CI is because of a bug in the Spacelift backend code. Here's the relevant error in the logs:

image

The problem is that the API key you'll have generated for local testing isn't quite the same as a Spacelift run token, and the GitHub Actions tests use a token that simulates a Spacelift run. I'll fix the backend issue just now.

adamconnelly
adamconnelly previously approved these changes Nov 1, 2024
Copy link
Contributor

@adamconnelly adamconnelly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, looks good, but let's not merge this until we get the backend fix released and the tests pass.

@Apollorion Apollorion dismissed stale reviews from adamconnelly and peterdeme via 7f0b77b November 1, 2024 12:55
@Apollorion
Copy link
Member Author

Pushed up the ID change, once that backend fix is in place tests should pass 👍 @adamconnelly @peterdeme need reapproval :)

@Apollorion Apollorion merged commit 7931b5b into main Nov 1, 2024
7 checks passed
@Apollorion Apollorion deleted the supported-versions branch November 1, 2024 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants