Skip to content

Commit

Permalink
fix .travis.yml when id account is also an account (#192)
Browse files Browse the repository at this point in the history
* fix .travis.yml when id account is also an account

* remove no-longer-needed fields for id account name
  • Loading branch information
ryanking authored Nov 20, 2018
1 parent 5d7cc01 commit c1011a5
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 21 deletions.
1 change: 0 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ type Module struct {
type TravisCI struct {
Enabled bool `json:"enabled"`
AWSIAMRoleName string `json:"aws_iam_role_name"`
IDAccountName string `json:"id_account_name"`
TestBuckets int `json:"test_buckets"`
}

Expand Down
7 changes: 3 additions & 4 deletions plan/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ type TfLint struct {
}

type AWSProfile struct {
Name string
ID int64
Role string
IDAccountName string
Name string
ID int64
Role string
}

// Plugins contains a plan around plugins
Expand Down
15 changes: 6 additions & 9 deletions plan/travisci.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import (
)

type TravisCI struct {
Enabled bool
AWSIDAccountName string
AWSProfiles []AWSProfile
TestBuckets [][]string
Enabled bool
AWSProfiles []AWSProfile
TestBuckets [][]string
}

func (p *Plan) buildTravisCI(c *config.Config) TravisCI {
Expand All @@ -20,8 +19,7 @@ func (p *Plan) buildTravisCI(c *config.Config) TravisCI {
}

tr := TravisCI{
Enabled: c.TravisCI.Enabled,
AWSIDAccountName: c.TravisCI.IDAccountName,
Enabled: c.TravisCI.Enabled,
}
var profiles []AWSProfile

Expand All @@ -30,9 +28,8 @@ func (p *Plan) buildTravisCI(c *config.Config) TravisCI {
Name: name,
// TODO since accountID is required here, that means we need
// to make it non-optional, either in defaults or post-plan.
ID: *p.Accounts[name].AccountID,
Role: c.TravisCI.AWSIAMRoleName,
IDAccountName: c.TravisCI.IDAccountName,
ID: *p.Accounts[name].AccountID,
Role: c.TravisCI.AWSIAMRoleName,
})
}
tr.AWSProfiles = profiles
Expand Down
3 changes: 0 additions & 3 deletions plan/travisci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func Test_buildTravisCI_Profiles(t *testing.T) {
TravisCI: &config.TravisCI{
Enabled: true,
AWSIAMRoleName: "rollin",
IDAccountName: "hub",
},
}
p := &Plan{}
Expand All @@ -51,7 +50,6 @@ func Test_buildTravisCI_Profiles(t *testing.T) {
a.Equal(tr.AWSProfiles[0].Name, "foo")
a.Equal(tr.AWSProfiles[0].ID, id1)
a.Equal(tr.AWSProfiles[0].Role, "rollin")
a.Equal(tr.AWSProfiles[0].IDAccountName, "hub")
}

func Test_buildTravisCI_TestBuckets(t *testing.T) {
Expand All @@ -69,7 +67,6 @@ func Test_buildTravisCI_TestBuckets(t *testing.T) {
TravisCI: &config.TravisCI{
Enabled: true,
AWSIAMRoleName: "rollin",
IDAccountName: "hub",
},
}

Expand Down
8 changes: 4 additions & 4 deletions templates/travis-ci/.travis.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ install:
- aws --version
before_script:
# TODO add note about why these need to be prefixed with HUB_
- aws configure set aws_access_key_id $IDACCT_AWS_ACCESS_KEY_ID --profile {{ .AWSIDAccountName }}
- aws configure set aws_secret_access_key $IDACCT_AWS_SECRET_ACCESS_KEY --profile {{ .AWSIDAccountName }}
- aws --profile {{ .AWSIDAccountName }} sts get-caller-identity
- aws configure set aws_access_key_id $IDACCT_AWS_ACCESS_KEY_ID --profile _idacct
- aws configure set aws_secret_access_key $IDACCT_AWS_SECRET_ACCESS_KEY --profile _idacct
- aws --profile _idacct sts get-caller-identity

{{ range $profile := .AWSProfiles}}
- aws configure set profile.{{ $profile.Name }}.role_arn arn:aws:iam::{{ $profile.ID }}:role/{{ $profile.Role}}
- aws configure set profile.{{ $profile.Name }}.source_profile {{ $profile.IDAccountName }}
- aws configure set profile.{{ $profile.Name }}.source_profile _idacct
- aws --profile {{ $profile.Name }} sts get-caller-identity
{{ end }}

Expand Down

0 comments on commit c1011a5

Please sign in to comment.