-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/pluralsh/plural/pkg/terraform" | ||
"github.com/pluralsh/plural/pkg/utils" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func terraformCommands() []cli.Command { | ||
return []cli.Command{ | ||
{ | ||
Name: "init", | ||
Usage: "command initializes a working directory containing Terraform configuration files", | ||
Action: terraformVersion(latestVersion(terraformInit)), | ||
}, | ||
} | ||
} | ||
|
||
func terraformInit(c *cli.Context) error { | ||
_, found := utils.ProjectRoot() | ||
if !found { | ||
return fmt.Errorf("Project not initialized, run `plural init` to set up a workspace") | ||
} | ||
|
||
return terraform.Init() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package terraform | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/hashicorp/terraform-exec/tfexec" | ||
"github.com/mitchellh/go-homedir" | ||
) | ||
|
||
func Init() error { | ||
ctx := context.Background() | ||
homeDir, err := homedir.Expand("~/.plural") | ||
if err != nil { | ||
return err | ||
} | ||
terraformBinPath := filepath.Join(homeDir, "terraform") | ||
workingDir, err := os.Getwd() | ||
if err != nil { | ||
return err | ||
} | ||
tf, err := tfexec.NewTerraform(workingDir, terraformBinPath) | ||
if err != nil { | ||
return fmt.Errorf("error running NewTerraform: %w", err) | ||
} | ||
tf.SetStdout(os.Stdout) | ||
|
||
err = tf.Init(ctx, tfexec.Upgrade(true)) | ||
if err != nil { | ||
return fmt.Errorf("error running Init: %w", err) | ||
} | ||
|
||
return nil | ||
} |