Skip to content

Conversation

lantoli
Copy link
Collaborator

@lantoli lantoli commented Jan 22, 2025

Description

Create plugin command with test infra

  • Command is very basic at the moment, it just transforms the resource type
  • There is an example of tests using golden files

Link to any related issue(s): CLOUDP-295406

Type of change:

  • Bug fix (non-breaking change which fixes an issue). Please, add the "bug" label to the PR.
  • New feature (non-breaking change which adds functionality). Please, add the "enhancement" label to the PR. A migration guide must be created or updated if the new feature will go in a major version.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected). Please, add the "breaking change" label to the PR. A migration guide must be created or updated.
  • This change requires a documentation update
  • Documentation fix/enhancement

Required Checklist:

  • I have signed the MongoDB CLA
  • I have read the contributing guides
  • I have checked that this change does not generate any credentials and that they are NOT accidentally logged anywhere.
  • I have added tests that prove my fix is effective or that my feature works per HashiCorp requirements
  • I have added any necessary documentation (if appropriate)
  • I have run make fmt and formatted my code
  • If changes include deprecations or removals I have added appropriate changelog entries.
  • If changes include removal or addition of 3rd party GitHub actions, I updated our internal document. Reach out to the APIx Integration slack channel to get access to the internal document.

Further comments

Copy link

This PR has gone 7 days without any activity and meets the project’s definition of "stale". This will be auto-closed if there is no new activity over the next 7 days. If the issue is still relevant and active, you can simply comment with a "bump" to keep it open, or add the label "not_stale". Thanks for keeping our repository healthy!

return o.Run()
},
}
cmd.Flags().StringVarP(&o.file, "file", "f", "", "input file")
Copy link
Collaborator Author

@lantoli lantoli Jan 30, 2025

Choose a reason for hiding this comment

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

I think that at the moment it's not necessary to have const files for Flag, Usage, etc.

@lantoli lantoli marked this pull request as ready for review January 30, 2025 07:24
@lantoli lantoli requested a review from a team as a code owner January 30, 2025 07:25
@@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/mongodb-labs/atlas-cli-plugin-terraform/internal/cli/hello"
"github.com/mongodb-labs/atlas-cli-plugin-terraform/internal/cli/clu2adv"
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit unconventional package name, but I like it

Copy link
Collaborator Author

@lantoli lantoli Jan 30, 2025

Choose a reason for hiding this comment

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

it's the (short) alias for the command, but let me know if you think of a better name

require (
github.com/hashicorp/hcl/v2 v2.23.0
github.com/sebdah/goldie/v2 v2.5.5
github.com/spf13/afero v1.12.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like a solid choice for fs handling

Copy link
Collaborator Author

@lantoli lantoli Jan 30, 2025

Choose a reason for hiding this comment

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

yes, same as in CLI

"github.com/stretchr/testify/require"
)

func TestClusterToAdvancedCluster(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice! This will be easy to extend

Copy link
Collaborator Author

@lantoli lantoli Jan 30, 2025

Choose a reason for hiding this comment

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

yes, just drop the .in.tf , use make test-update, and check the output files are as expected, and there you have more tests

Copy link
Contributor

@EspenAlbert EspenAlbert left a comment

Choose a reason for hiding this comment

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

Great job!

isResource := resource.Type() == "resource"
labels := resource.Labels()
resourceName := labels[0]
if !isResource || resourceName != "mongodbatlas_cluster" {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you make const strings from this file? mongodbatlas_cluster, mongodbatlas_advanced_cluster, resource

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

thanks, changed here: db532d0

o := &opts{fs: afero.NewOsFs()}
cmd := &cobra.Command{
Use: "cluster_to_advanced",
Short: "Upgrade cluster to advanced_cluster",
Copy link
Contributor

Choose a reason for hiding this comment

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

Upgrades?

Copy link
Contributor

Choose a reason for hiding this comment

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

isn't actually Converts more accurate?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you're right, changed here: 1c24a51

cmd := &cobra.Command{
Use: "cluster_to_advanced",
Short: "Upgrade cluster to advanced_cluster",
Long: "Upgrade Terraform config from mongodbatlas_cluster to mongodbatlas_advanced_cluster",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Long: "Upgrade Terraform config from mongodbatlas_cluster to mongodbatlas_advanced_cluster",
Long: "Converts a Terraform configuration from mongodbatlas_cluster to mongodbatlas_advanced_cluster",

Copy link
Collaborator Author

@lantoli lantoli Jan 30, 2025

Choose a reason for hiding this comment

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

changed here: 1c24a51
(keeping 2nd person form to be consistent)

_ = cmd.MarkFlagRequired("file")
cmd.Flags().StringVarP(&o.output, "output", "o", "", "output file")
_ = cmd.MarkFlagRequired("output")
cmd.Flags().BoolVarP(&o.overwriteOutput, "overwriteOutput", "w", false, "overwrite output file if exists")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

file and output are the standard params for input and output files

@lantoli lantoli requested a review from a team January 30, 2025 15:05
Copy link
Contributor

@carriecwk carriecwk left a comment

Choose a reason for hiding this comment

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

lgtm

Co-authored-by: carriecwk <[email protected]>
@lantoli lantoli merged commit af30720 into main Jan 30, 2025
6 checks passed
@lantoli lantoli deleted the CLOUDP-295406_test_commands branch January 30, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants