-
Notifications
You must be signed in to change notification settings - Fork 48
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
use 'terraform workspace' for terraform versions >= 0.10.x. Fixes #142 #172
Conversation
Codecov Report
@@ Coverage Diff @@
## master #172 +/- ##
==========================================
- Coverage 48.42% 48.24% -0.18%
==========================================
Files 29 29
Lines 1615 1621 +6
==========================================
Hits 782 782
- Misses 806 812 +6
Partials 27 27
Continue to review full report at Codecov.
|
outputs = append(outputs, output) | ||
if err != nil { | ||
return outputs, err | ||
} | ||
|
||
// terraform env or workspace selection based on version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golang comments should be full sentences with capitalization and periods. For here I'd say something like
// Terraform versions >0.8 and <0.10 use the env command.
// Versions >= 0.10 have env renamed to workspace.
// terraform env or workspace selection based on version | ||
// we will use 'terraform env' for terraform versions < 0.10.x | ||
// and we will use 'terraform workspace' for terraform versions >= 0.10.x | ||
tfCmdStr := "env" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tfCmdStr
could be named more explicitly so the reader can understand by the name what it does.
tf
is implied by the fact that we're in theterraform_client
struct so it doesn't tell us anythingStr
is the type which can easily be figured out so it doesn't add anything either really unless you're trying to distinguish between anothertfCmd
that isn't a string
Can we call this workspaceCmd
? I know that it won't make sense for tf < 0.10 but we could treat that as a special case. So I'd default to workspaceCmd := "workspace"
and then do a check on the version for <0.10.0 and change it to env
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like workspaceCmd
since it doesn't make sense for tf < 0.10. I will find a better name and push updates.
// run terraform env new and select | ||
output, err = c.RunCommandWithVersion(log, path, []string{"env", "select", "-no-color", env}, version, env) | ||
output, err = c.RunCommandWithVersion(log, path, []string{tfCmdStr, "select", "-no-color", env}, v, env) | ||
outputs = append(outputs, output) | ||
if err != nil { | ||
// if terraform env select fails we will run terraform env new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to update the comment here. I think we can just go with workspace
everywhere
@@ -100,22 +100,31 @@ func (c *Client) RunCommandWithVersion(log *logging.SimpleLogger, path string, a | |||
// RunInitAndEnv executes "terraform init" and "terraform env select" in path. | |||
// env is the environment to select and extraInitArgs are additional arguments | |||
// applied to the init command. | |||
func (c *Client) RunInitAndEnv(log *logging.SimpleLogger, path string, env string, extraInitArgs []string, version *version.Version) ([]string, error) { | |||
func (c *Client) RunInitAndEnv(log *logging.SimpleLogger, path string, env string, extraInitArgs []string, v *version.Version) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the function name. Let's go with Workspace
everywhere since 0.9 is the only version that called it an Env
@@ -100,22 +100,31 @@ func (c *Client) RunCommandWithVersion(log *logging.SimpleLogger, path string, a | |||
// RunInitAndEnv executes "terraform init" and "terraform env select" in path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to update the comment
Can we use this opportunity to test this class? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. What about tests?
// 2. "terraform workspace or env select" - This selects the workspace or environment for the terraform project | ||
// [optional] 3. "terraform workspace or env new" - This creates a new workspace or environment for the terraform project | ||
// env is the environment supplied by the atlantis user that is used to | ||
// select or create a new workspace or environment for terraform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs .
at end
tfCmdStr := "env" | ||
constraints, _ := version.NewConstraint(">= 0.10.0") | ||
// Terraform uses 'terraform env' command for versions > 0.8 and < 0.10. | ||
// Versions >= 0.10 use 'terraform workspace' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need .
at end
} | ||
|
||
// run terraform env new and select | ||
output, err = c.RunCommandWithVersion(log, path, []string{tfCmdStr, "select", "-no-color", env}, v, env) | ||
// Run 'terraform workspace/env select' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this comment is necessary because it's obvious from reading the line below what's happening. I try to reserve comments for explaining why code is doing what it is rather than what. So the comment above where we're saying why we're switching between env/workspace is a good one
output, err = c.RunCommandWithVersion(log, path, []string{tfCmdStr, "new", "-no-color", env}, v, env) | ||
// If 'terraform workspace/env select' fails we will run 'terraform workspace new' | ||
// to create a new environment. This is done for ease of use so that the atlantis | ||
// user doesn't have to create a new workspace/env manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice comment
@lkysow I tend on pushing stuff as I work on it. Yep, tests are the next push hopefully. |
Same fix contained in #219 |
We want to use
terraform workspace
for terraform versions >=0.10.x