Skip to content

Commit

Permalink
Add option to change state file extension (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonbondon authored and raphink committed Nov 23, 2017
1 parent 3de1da0 commit 9d0281c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Config struct {
Bucket string `long:"s3-bucket" env:"AWS_BUCKET" description:"AWS S3 bucket."`
DynamoDBTable string `long:"dynamodb-table" env:"AWS_DYNAMODB_TABLE" description:"AWS DynamoDB table for locks."`
KeyPrefix string `long:"key-prefix" env:"AWS_KEY_PREFIX" description:"AWS Key Prefix."`
FileExtension string `long:"file-extension" env:"AWS_FILE_EXTENSION" description:"File extension of state files." default:".tfstate"`
} `group:"AWS S3 Options"`

Authentication struct {
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
AWS_REGION: ${AWS_DEFAULT_REGION}
AWS_BUCKET: ${AWS_BUCKET}
AWS_FILE_EXTENSION: ${AWS_FILE_EXTENSION}
BASE_URL: /terraboard/
DB_PASSWORD: mypassword
AWS_DYNAMODB_TABLE: ${AWS_DYNAMODB_TABLE}
Expand Down
4 changes: 3 additions & 1 deletion s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ var dynamoSvc *dynamodb.DynamoDB
var bucket string
var dynamoTable string
var keyPrefix string
var fileExtension string

// Setup sets up AWS S3 connection
func Setup(c *config.Config) {
sess := session.Must(session.NewSession())
svc = s3.New(sess, &aws.Config{})
bucket = c.S3.Bucket
keyPrefix = c.S3.KeyPrefix
fileExtension = c.S3.FileExtension

dynamoSvc = dynamodb.New(sess, &aws.Config{})
dynamoTable = c.S3.DynamoDBTable
Expand Down Expand Up @@ -100,7 +102,7 @@ func GetStates() (states []string, err error) {

var keys []string
for _, obj := range result.Contents {
if strings.HasSuffix(*obj.Key, ".tfstate") {
if strings.HasSuffix(*obj.Key, fileExtension) {
keys = append(keys, *obj.Key)
}
}
Expand Down

0 comments on commit 9d0281c

Please sign in to comment.