Skip to content

Commit

Permalink
Merge pull request #56 from Cox-Automotive/develop
Browse files Browse the repository at this point in the history
Merge Develop to Master
  • Loading branch information
webbbarker authored May 16, 2019
2 parents f43dd15 + 3e57772 commit e1a8f08
Show file tree
Hide file tree
Showing 178 changed files with 22,640 additions and 8,903 deletions.
40 changes: 24 additions & 16 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
unused-packages = true

[[constraint]]
branch = "master"
name = "github.com/aws/aws-sdk-go"

[[constraint]]
Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ install:
release:
mkdir -p release

GOOS=darwin GOARCH=amd64 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-darwin-amd64.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=freebsd GOARCH=386 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=freebsd GOARCH=386 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-freebsd-386.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=freebsd GOARCH=amd64 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=freebsd GOARCH=amd64 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-freebsd-amd64.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=linux GOARCH=386 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=linux GOARCH=386 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-linux-386.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=linux GOARCH=amd64 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-linux-amd64.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=solaris GOARCH=amd64 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
GOOS=solaris GOARCH=amd64 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG) $(package)
chmod +x release/terraform-provider-alks_v$(TRAVIS_TAG)
tar -cvzf release/terraform-provider-alks-solaris-amd64.tar.gz -C release/ terraform-provider-alks_v$(TRAVIS_TAG)

GOOS=windows GOARCH=386 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG).exe $(package)
GOOS=windows GOARCH=386 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG).exe $(package)
zip release/terraform-provider-alks-windows-386.zip release/terraform-provider-alks_v$(TRAVIS_TAG).exe

GOOS=windows GOARCH=amd64 go build -o release/terraform-provider-alks_v$(TRAVIS_TAG).exe $(package)
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.versionNumber=$(TRAVIS_TAG)" -o release/terraform-provider-alks_v$(TRAVIS_TAG).exe $(package)
zip release/terraform-provider-alks-windows-amd64.zip release/terraform-provider-alks_v$(TRAVIS_TAG).exe

rm release/terraform-provider-alks_v$(TRAVIS_TAG).exe
Expand Down
31 changes: 31 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import (
"errors"
"fmt"
"log"
"os"
"time"

"github.com/hashicorp/go-cleanhttp"

"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/ec2metadata"

alks "github.com/Cox-Automotive/alks-go"
Expand All @@ -16,6 +21,10 @@ import (
"github.com/aws/aws-sdk-go/service/sts"
)

// Version number, to be injected at link time
// to set, add `-ldflags "-X main.versionNumber=1.2.3"` to the go build command
var versionNumber string

// Config stores ALKS configuration and credentials
type Config struct {
URL string
Expand Down Expand Up @@ -57,6 +66,18 @@ func getCredentials(c *Config) *credentials.Credentials {
},
}

// Check for ECS container, for more details see:
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html
if uri := os.Getenv("AWS_CONTAINER_CREDENTIALS_RELATIVE_URI"); len(uri) > 0 {
client := cleanhttp.DefaultClient()
client.Timeout = 100 * time.Millisecond
cfg := &aws.Config{
HTTPClient: client,
}

providers = append(providers, defaults.RemoteCredProvider(*cfg, defaults.Handlers()))
}

return credentials.NewChainCredentials(providers)
}

Expand Down Expand Up @@ -131,7 +152,17 @@ providing credentials for the ALKS Provider`)
return nil, err
}

client.SetUserAgent(fmt.Sprintf("alks-terraform-provider-%s", getPluginVersion()))

log.Println("[INFO] ALKS Client configured")

return client, nil
}

func getPluginVersion() string {
if versionNumber != "" {
return versionNumber
}

return "unknown"
}
10 changes: 10 additions & 0 deletions resource_alks_iamrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"strings"
"time"

alks "github.com/Cox-Automotive/alks-go"
Expand Down Expand Up @@ -147,6 +148,10 @@ func resourceAlksIamTrustRoleCreate(d *schema.ResourceData, meta interface{}) er
var err error
resp, err = client.CreateIamTrustRole(roleName, roleType, trustArn, enableAlksAccess)
if err != nil {
if strings.Contains(err.Error(), "Role already exists") || strings.Contains(err.Error(), "Instance profile exists") {
return resource.NonRetryableError(err)
}

return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
Expand Down Expand Up @@ -189,6 +194,11 @@ func resourceAlksIamRoleExists(d *schema.ResourceData, meta interface{}) (b bool
foundrole, err := client.GetIamRole(d.Id())

if err != nil {
// TODO: Clean-up this logic, likely by improving the error responses from `alks-go`
if strings.Contains(err.Error(), "Role not found") {
return false, nil
}

return false, err
}

Expand Down
28 changes: 28 additions & 0 deletions vendor/github.com/Cox-Automotive/alks-go/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions vendor/github.com/Cox-Automotive/alks-go/Gopkg.toml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions vendor/github.com/Cox-Automotive/alks-go/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e1a8f08

Please sign in to comment.