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

Add contained_db field to mssql db secret backend #1259

Merged
merged 9 commits into from
Dec 17, 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
9 changes: 7 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ jobs:
- image: hashicorp/vault:latest
environment:
- VAULT_DEV_ROOT_TOKEN_ID=root
- image: mcr.microsoft.com/mssql/server:2017-latest-ubuntu
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=yourStrong1000Password
working_directory: /tmp/go/src/github.com/hashicorp/terraform-provider-vault
steps:
- checkout
- run:
name: Wait for containers to starts
command: dockerize -wait http://127.0.0.1:8200 -wait tcp://127.0.0.1:3306 -timeout 30s
command: dockerize -wait http://127.0.0.1:8200 -wait tcp://127.0.0.1:3306 -wait tcp://127.0.0.1:1433 -timeout 30s
- run:
name: "Set Environment Variables"
command: |
Expand All @@ -44,7 +48,8 @@ jobs:
export MYSQL_CONNECTION_URL="{{username}}:{{password}}@tcp(127.0.0.1:3306)/"
export MYSQL_CONNECTION_USERNAME="root"
export MYSQL_CONNECTION_PASSWORD="mysql"
export MONGODB_URL="mongodb://root:mongodb@localhost:27017/admin?ssl=false"
export MONGODB_URL="mongodb://root:[email protected]:27017/admin?ssl=false"
export MSSQL_URL="sqlserver://sa:[email protected]:1433"
# This will be removed after VAULT-4324 is fixed
export SKIP_RAFT_TESTS='true'
make testacc TESTARGS='-v'
Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ require (
github.com/Azure/azure-sdk-for-go v58.3.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.21
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/aws/aws-sdk-go v1.41.8
github.com/denisenkom/go-mssqldb v0.11.0
github.com/go-sql-driver/mysql v1.6.0
github.com/gosimple/slug v1.11.0
github.com/hashicorp/errwrap v1.1.0
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/go-hclog v1.0.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.6.8 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.8.0
github.com/hashicorp/vault v1.2.0
github.com/hashicorp/vault/api v1.2.0
github.com/hashicorp/vault/sdk v0.2.1
github.com/hashicorp/go-secure-stdlib/awsutil v0.1.5
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.2
github.com/hashicorp/terraform-plugin-sdk/v2 v2.10.0
github.com/hashicorp/vault v1.2.1-0.20211214161113-fcc5f22bea02
github.com/hashicorp/vault/api v1.3.0
github.com/hashicorp/vault/sdk v0.3.1-0.20211214161113-fcc5f22bea02
github.com/mitchellh/go-homedir v1.1.0
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1
)
1,309 changes: 1,141 additions & 168 deletions go.sum

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions vault/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"os"
"strings"

"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/go-secure-stdlib/awsutil"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/vault/api"
awsauth "github.com/hashicorp/vault/builtin/credential/aws"
"github.com/hashicorp/vault/command/config"

"github.com/hashicorp/terraform-provider-vault/helper"
Expand Down Expand Up @@ -804,7 +806,13 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {

method := authLogin["method"].(string)
if method == "aws" {
if err := signAWSLogin(authLoginParameters); err != nil {
logger := hclog.Default()
if logging.IsDebugOrHigher() {
logger.SetLevel(hclog.Debug)
} else {
logger.SetLevel(hclog.Error)
}
if err := signAWSLogin(authLoginParameters, logger); err != nil {
return nil, fmt.Errorf("error signing AWS login request: %s", err)
}
}
Expand Down Expand Up @@ -904,7 +912,7 @@ func parse(descs map[string]*Description) (map[string]*schema.Resource, error) {
return resourceMap, errs
}

func signAWSLogin(parameters map[string]interface{}) error {
func signAWSLogin(parameters map[string]interface{}, logger hclog.Logger) error {
var accessKey, secretKey, securityToken string
if val, ok := parameters["aws_access_key_id"].(string); ok {
accessKey = val
Expand All @@ -918,7 +926,7 @@ func signAWSLogin(parameters map[string]interface{}) error {
securityToken = val
}

creds, err := awsauth.RetrieveCreds(accessKey, secretKey, securityToken)
creds, err := awsutil.RetrieveCreds(accessKey, secretKey, securityToken, logger)
if err != nil {
return fmt.Errorf("failed to retrieve AWS credentials: %s", err)
}
Expand All @@ -932,7 +940,7 @@ func signAWSLogin(parameters map[string]interface{}) error {
stsRegion = val
}

loginData, err := awsauth.GenerateLoginData(creds, headerValue, stsRegion)
loginData, err := awsutil.GenerateLoginData(creds, headerValue, stsRegion, logger)
if err != nil {
return fmt.Errorf("failed to generate AWS login data: %s", err)
}
Expand Down
Loading