-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from gruntwork-io/auto-create-s3-bucket
Terragrunt will now create remote state S3 bucket if it doesn't exist
- Loading branch information
Showing
14 changed files
with
597 additions
and
163 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package aws_helper | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/defaults" | ||
"github.com/gruntwork-io/terragrunt/errors" | ||
) | ||
|
||
// Returns an AWS config object for the given region, ensuring that the config has credentials | ||
func CreateAwsConfig(awsRegion string) (*aws.Config, error) { | ||
config := defaults.Get().Config.WithRegion(awsRegion) | ||
|
||
_, err := config.Credentials.Get() | ||
if err != nil { | ||
return nil, errors.WithStackTraceAndPrefix(err, "Error finding AWS credentials (did you set the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables?)") | ||
} | ||
|
||
return config, nil | ||
} |
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,121 @@ | ||
package cli | ||
|
||
import ( | ||
"testing" | ||
"github.com/gruntwork-io/terragrunt/options" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/gruntwork-io/terragrunt/errors" | ||
"github.com/gruntwork-io/terragrunt/config" | ||
) | ||
|
||
func TestParseTerragruntOptionsFromArgs(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
args []string | ||
expectedOptions *options.TerragruntOptions | ||
expectedErr error | ||
}{ | ||
{ | ||
[]string{}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: config.DefaultTerragruntConfigPath, | ||
NonInteractive: false, | ||
NonTerragruntArgs: []string{}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"foo", "bar"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: config.DefaultTerragruntConfigPath, | ||
NonInteractive: false, | ||
NonTerragruntArgs: []string{"foo", "bar"}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--foo", "--bar"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: config.DefaultTerragruntConfigPath, | ||
NonInteractive: false, | ||
NonTerragruntArgs: []string{"--foo", "--bar"}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--foo", "apply", "--bar"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: config.DefaultTerragruntConfigPath, | ||
NonInteractive: false, | ||
NonTerragruntArgs: []string{"--foo", "apply", "--bar"}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--terragrunt-non-interactive"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: config.DefaultTerragruntConfigPath, | ||
NonInteractive: true, | ||
NonTerragruntArgs: []string{}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--terragrunt-config", "/some/path/.terragrunt"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: "/some/path/.terragrunt", | ||
NonInteractive: false, | ||
NonTerragruntArgs: []string{}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--terragrunt-config", "/some/path/.terragrunt", "--terragrunt-non-interactive"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: "/some/path/.terragrunt", | ||
NonInteractive: true, | ||
NonTerragruntArgs: []string{}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--foo", "--terragrunt-config", "/some/path/.terragrunt", "bar", "--terragrunt-non-interactive", "--baz"}, | ||
&options.TerragruntOptions{ | ||
TerragruntConfigPath: "/some/path/.terragrunt", | ||
NonInteractive: true, | ||
NonTerragruntArgs: []string{"--foo", "bar", "--baz"}, | ||
}, | ||
nil, | ||
}, | ||
|
||
{ | ||
[]string{"--terragrunt-config"}, | ||
nil, | ||
MissingTerragruntConfigValue, | ||
}, | ||
|
||
{ | ||
[]string{"--foo", "bar", "--terragrunt-config"}, | ||
nil, | ||
MissingTerragruntConfigValue, | ||
}, | ||
} | ||
|
||
for _, testCase := range testCases { | ||
actualOptions, actualErr := parseTerragruntOptionsFromArgs(testCase.args) | ||
if testCase.expectedErr != nil { | ||
assert.True(t, errors.IsError(actualErr, testCase.expectedErr), "Expected error %v but got error %v", testCase.expectedErr, actualErr) | ||
} else { | ||
assert.Nil(t, actualErr, "Unexpected error: %v", actualErr) | ||
assert.Equal(t, testCase.expectedOptions, actualOptions, "Expected options %v but got %v", testCase.expectedOptions, actualOptions) | ||
} | ||
} | ||
} |
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
Oops, something went wrong.