Skip to content
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

feat: add test environment with proper docker-compose using MinIO + add compatibility for it to AWS provider #165

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ The precedence of configurations is as described below.
|`--aws-external-id` | `AWS_EXTERNAL_ID` | `aws.external-id` | External ID to use when assuming role | - |
|`--key-prefix` | `AWS_KEY_PREFIX` | `aws.key-prefix` | AWS Key Prefix | - |
|`--file-extension` | `AWS_FILE_EXTENSION` | `aws.file-extension` | File extension(s) of state files. Use multiple CLI flags or a comma separated list ENV variable | .tfstate |
|`--aws-region` | `AWS_REGION` | `aws.region` | AWS region | - |
|`--aws-endpoint` | `AWS_ENDPOINT` | `aws.endpoint` | Custom AWS endpoint | - |
|`--no-locks` | `TERRABOARD_NO_LOCKS` | `provider.no-locks` | Disable locks support from Terraboard (useful for S3 compatible providers like MinIO) | false |
|`--no-versioning` | `TERRABOARD_NO_VERSIONING` | `provider.no-versioning` | Disable versioning support from Terraboard (useful for S3 compatible providers like MinIO) | false |
|`--force-path-style` | `AWS_FORCE_PATH_STYLE` | `aws.s3.force-path-style` | Force path style S3 bucket calls. | false |
|`--base-url` | `TERRABOARD_BASE_URL` | `web.base-url` | Base URL | / |
|`--logout-url` | `TERRABOARD_LOGOUT_URL` | `web.logout-url` | Logout URL | - |
|`--tfe-address` | `TFE_ADDRESS` | `tfe.tfe-address` | Terraform Enterprise address for states access | - |
Expand Down
8 changes: 8 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ type WebConfig struct {
LogoutURL string `long:"logout-url" env:"TERRABOARD_LOGOUT_URL" yaml:"logout-url" description:"Logout URL."`
}

// ProviderConfig stores genral provider parameters
type ProviderConfig struct {
NoVersioning bool `long:"no-versioning" env:"TERRABOARD_NO_VERSIONING" yaml:"no-versioning" description:"Disable versioning support from Terraboard (useful for S3 compatible providers like MinIO)"`
NoLocks bool `long:"no-locks" env:"TERRABOARD_NO_LOCKS" yaml:"no-locks" description:"Disable locks support from Terraboard (useful for S3 compatible providers like MinIO)"`
}

// Config stores the handler's configuration and UI interface parameters
type Config struct {
Version bool `short:"V" long:"version" description:"Display version."`

ConfigFilePath string `short:"c" long:"config-file" env:"CONFIG_FILE" description:"Config File path"`

Provider ProviderConfig `group:"General Provider Options" yaml:"provider"`

Log LogConfig `group:"Logging Options" yaml:"log"`

DB DBConfig `group:"Database Options" yaml:"database"`
Expand Down
4 changes: 4 additions & 0 deletions example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ database:
no-sync: false
sync-interval: 5

provider:
no-locks: "true"
no-versioning: "false"

aws:
dynamodb-table: terraboard
s3:
Expand Down
21 changes: 20 additions & 1 deletion state/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"strings"
"time"

aws_sdk "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
Expand All @@ -25,6 +26,8 @@ type AWS struct {
dynamoTable string
keyPrefix string
fileExtension []string
noLocks bool
noVersioning bool
}

// NewAWS creates an AWS object
Expand Down Expand Up @@ -58,11 +61,18 @@ func NewAWS(c *config.Config) AWS {
fileExtension: c.AWS.S3.FileExtension,
dynamoSvc: dynamodb.New(sess, awsConfig),
dynamoTable: c.AWS.DynamoDBTable,
noLocks: c.Provider.NoLocks,
noVersioning: c.Provider.NoVersioning,
}
}

// GetLocks returns a map of locks by State path
func (a *AWS) GetLocks() (locks map[string]LockInfo, err error) {
if a.noLocks {
locks = make(map[string]LockInfo)
return
}

if a.dynamoTable == "" {
err = fmt.Errorf("no dynamoDB table provided, not getting locks")
return
Expand Down Expand Up @@ -94,6 +104,7 @@ func (a *AWS) GetLocks() (locks map[string]LockInfo, err error) {
locks[strings.TrimPrefix(info.Path, infoPrefix)] = info
}
}

return
}

Expand Down Expand Up @@ -138,7 +149,7 @@ func (a *AWS) GetState(st, versionID string) (sf *statefile.File, err error) {
Bucket: aws_sdk.String(a.bucket),
Key: aws_sdk.String(st),
}
if versionID != "" {
if versionID != "" && !a.noVersioning {
input.VersionId = &versionID
}
result, err := a.svc.GetObjectWithContext(context.Background(), input)
Expand Down Expand Up @@ -168,6 +179,14 @@ func (a *AWS) GetState(st, versionID string) (sf *statefile.File, err error) {
// GetVersions returns a slice of Version objects
func (a *AWS) GetVersions(state string) (versions []Version, err error) {
versions = []Version{}
if a.noVersioning {
versions = append(versions, Version{
ID: "1",
LastModified: time.Now(),
})
return
}

result, err := a.svc.ListObjectVersions(&s3.ListObjectVersionsInput{
Bucket: aws_sdk.String(a.bucket),
Prefix: aws_sdk.String(state),
Expand Down
2 changes: 2 additions & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data/*
!data/test-bucket
Empty file added test/data/test-bucket/.gitkeep
Empty file.
62 changes: 62 additions & 0 deletions test/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
version: "3"
services:
terraboard-dev:
build:
context: ../
dockerfile: ./Dockerfile
environment:
AWS_ACCESS_KEY_ID: root
AWS_SECRET_ACCESS_KEY: mypassword
AWS_BUCKET: test-bucket
AWS_REGION: eu-west-1
AWS_ENDPOINT: http://minio:9000/
AWS_FORCE_PATH_STYLE: "true"
TERRABOARD_LOG_LEVEL: debug
TERRABOARD_NO_LOCKS: "true"
TERRABOARD_NO_VERSIONING: "true"
DB_PASSWORD: mypassword
DB_SSLMODE: disable
GODEBUG: netdns=go
depends_on:
- "db"
- "minio"
volumes:
- ../static:/static:ro
ports:
- "8080:8080"

minio:
image: minio/minio:latest
environment:
MINIO_ROOT_USER: root
MINIO_ROOT_PASSWORD: mypassword
expose:
- "9000"
ports:
- "9200:9000"
volumes:
- ./data:/data
command: server /data

db:
image: postgres:9.5
environment:
POSTGRES_USER: gorm
POSTGRES_PASSWORD: mypassword
POSTGRES_DB: gorm
volumes:
- tb-data:/var/lib/postgresql/data

pgadmin:
container_name: pgadmin4_container
image: dpage/pgadmin4
restart: always
environment:
PGADMIN_DEFAULT_EMAIL: admin@admin.com
PGADMIN_DEFAULT_PASSWORD: root
ports:
- "5050:80"

volumes:
tb-data: {}