-
Notifications
You must be signed in to change notification settings - Fork 58
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
1 parent
3e503c3
commit 9922135
Showing
3 changed files
with
64 additions
and
12 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 |
---|---|---|
@@ -1,14 +1,34 @@ | ||
package tfexec | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Apply applies changes. | ||
func (c *terraformCLI) Apply(ctx context.Context, dirOrPlan string, opts ...string) error { | ||
// If a plan is given, use it for the input plan. | ||
func (c *terraformCLI) Apply(ctx context.Context, plan *Plan, dir string, opts ...string) error { | ||
args := []string{"apply"} | ||
args = append(args, opts...) | ||
if len(dirOrPlan) > 0 { | ||
args = append(args, dirOrPlan) | ||
|
||
if plan != nil { | ||
if len(dir) > 0 { | ||
return fmt.Errorf("failed to build options. The plan argument (!= nil) and the dir argument cannot be set at the same time: plan=%v, dir=%v", plan, dir) | ||
} | ||
tmpPlan, err := writeTempFile(plan.Bytes()) | ||
defer os.Remove(tmpPlan.Name()) | ||
if err != nil { | ||
return err | ||
} | ||
args = append(args, tmpPlan.Name()) | ||
} | ||
|
||
if len(dir) > 0 { | ||
args = append(args, dir) | ||
} | ||
|
||
_, _, err := c.Run(ctx, args...) | ||
|
||
return err | ||
} |
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