Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin
bin-plugin
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Contributing to Atlas CLI plugin for MongoDB Atlas Provider
# Contributing to the Atlas CLI plugin for Terraform's MongoDB Atlas Provider

WIP

## Building

You can build the binary plugin by running `make build`. You'll need to have Go installed. Then you can run directly the generated binary `./bin/binary terraform [command]` to test your changes.

## Using the plugin from the CLI

You can also use the plugin with your changes from the CLI by running: `make local` and following the instructions displayed.
18 changes: 0 additions & 18 deletions GNUmakefile

This file was deleted.

55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
CLI_SOURCE_FILES?=./cmd/plugin
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using Makefile instead of GNUmakefile as we don't need specific features

CLI_BINARY_NAME?=binary
CLI_DESTINATION=./bin/$(CLI_BINARY_NAME)
MANIFEST_FILE?=./bin/manifest.yml
WIN_MANIFEST_FILE?=./bin/manifest.windows.yml

GOLANGCI_VERSION=v1.63.4 # Also update golangci-lint GH action in code-health.yml when updating this version

.PHONY: build
build: ## Generate the binary in ./bin
@echo "==> Building plugin binary: $(CLI_BINARY_NAME)"
go build -o $(CLI_DESTINATION) $(CLI_SOURCE_FILES)

.PHONY: tools
tools: ## Install the dev tools (dependencies)
@echo "==> Installing dev tools..."
go telemetry off # disable sending telemetry data, more info: https://go.dev/doc/telemetry
go install github.com/rhysd/actionlint/cmd/actionlint@latest
go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_VERSION)

.PHONY: clean
clean: ## Clean binary folders
rm -rf ./bin ./bin-plugin

Copy link
Collaborator Author

@lantoli lantoli Jan 13, 2025

Choose a reason for hiding this comment

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

local make target

.PHONY: local
local: clean build ## Allow to run the plugin locally
@echo "==> Configuring plugin locally"
VERSION=0.0.1-local GITHUB_REPOSITORY_OWNER=owner GITHUB_REPOSITORY_NAME=repo $(MAKE) generate-manifest
@mkdir -p ./bin-plugin
cp -r ./bin ./bin-plugin/atlas-cli-plugin-terraform
@echo
@echo "==> Plugin is ready to be used locally"
@echo "run: export ATLAS_CLI_EXTRA_PLUGIN_DIRECTORY=./bin-plugin"
@echo "then this command should show the plugin: atlas plugin list"

.PHONY: generate-all-manifests
generate-all-manifests: generate-manifest generate-manifest-windows ## Generate all the manifest files

.PHONY: generate-manifest
generate-manifest: ## Generate the manifest file for non-windows OSes
@echo "==> Generating non-windows manifest file"
@mkdir -p ./bin
BINARY=$(CLI_BINARY_NAME) envsubst < manifest.template.yml > $(MANIFEST_FILE)

.PHONY: generate-manifest-windows
generate-manifest-windows: ## Generate the manifest file for windows OSes
@echo "==> Generating windows manifest file"
CLI_BINARY_NAME="${CLI_BINARY_NAME}.exe" MANIFEST_FILE="$(WIN_MANIFEST_FILE)" $(MAKE) generate-manifest

.PHONY: help
.DEFAULT_GOAL := help
help:
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
# Atlas CLI plugin for MongoDB Atlas Provider
# Atlas CLI plugin for Terraform's MongoDB Atlas Provider

[![Code Health](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/actions/workflows/code-health.yml/badge.svg)](https://github.com/mongodb-labs/atlas-cli-plugin-terraform/actions/workflows/code-health.yml)

This repository contains the Atlas CLI plugin for MongoDB Atlas Provider.
This repository contains the Atlas CLI plugin for Terraform's MongoDB Atlas Provider.

WIP

## Installing

Install the [Atlas CLI](https://github.com/mongodb/mongodb-atlas-cli) if you haven't done it yet.

Install the plugin by running:
```bash
atlas plugin install github.com/mongodb-labs/atlas-cli-plugin-terraform
```

## Usage


## Contributing

See our [CONTRIBUTING.md](CONTRIBUTING.md) guide.

## License

MongoDB Atlas CLI is released under the Apache 2.0 license. See [LICENSE.md](LICENSE.md)
37 changes: 35 additions & 2 deletions cmd/plugin/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,40 @@
package main

import "fmt"
import (
"fmt"
"os"

"github.com/mongodb-labs/atlas-cli-plugin-terraform/internal/cli/hello"
"github.com/spf13/cobra"
)

func main() {
fmt.Println("WIP - Placeholder for CLI plugin entrypoint")
terraformCmd := &cobra.Command{
Use: "terraform",
Short: "Utilities for Terraform's MongoDB Atlas Provider",
Aliases: []string{"tf"},
}

terraformCmd.AddCommand(
hello.Builder(),
)

completionOption := &cobra.CompletionOptions{
DisableDefaultCmd: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these options?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

using the same defaults as in example and kubernetes plugins

DisableNoDescFlag: true,
DisableDescriptions: true,
HiddenDefaultCmd: true,
}
rootCmd := &cobra.Command{
DisableFlagParsing: true,
DisableAutoGenTag: true,
DisableSuggestions: true,
CompletionOptions: *completionOption,
}
rootCmd.AddCommand(terraformCmd)

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
module github.com/mongodb-labs/atlas-cli-plugin-terraform

go 1.23.4

require github.com/spf13/cobra v1.8.1

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
17 changes: 17 additions & 0 deletions internal/cli/hello/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package hello

import (
"fmt"

"github.com/spf13/cobra"
)

func Builder() *cobra.Command {
return &cobra.Command{
Use: "hello",
Short: "The Hello World command",
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("Hello World, Terraform! This command will be eventually deleted.")
},
}
}
12 changes: 12 additions & 0 deletions manifest.template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: atlas-cli-plugin-terraform
description: Utilities for Terraform's MongoDB Atlas Provider
version: $VERSION
github:
owner: $GITHUB_REPOSITORY_OWNER
Copy link
Contributor

Choose a reason for hiding this comment

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

nice usage of env-vars

name: $GITHUB_REPOSITORY_NAME
binary: $BINARY
commands:
terraform:
description: Utilities for Terraform's MongoDB Atlas Provider
tf:
Copy link
Contributor

Choose a reason for hiding this comment

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

love the shorthand option tf

description: Alias for the terraform command
Loading