Skip to content

Commit

Permalink
Merge pull request #336 from concourse/aws-cross-account
Browse files Browse the repository at this point in the history
Add aws_account_id parameter
  • Loading branch information
taylorsilva authored Feb 23, 2023
2 parents 5ebd24a + 8869bd9 commit 1782ca1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ differences:
<code>aws_role_arn</code> is also specified.
</td>
</tr>
<tr>
<td><code>aws_account_id</code> <em>(Optional)</em></td>
<td>
The AWS Account ID that the image is located in. Useful if interacting with
images in another account. If omitted then the current AWS account ID will
be used. Be sure to wrap the account ID in quotes so it is parsed as a
string instead of a number.
</td>
</tr>
<tr>
<td><code>platform</code> <em>(Optional)<br>(Experimental)</em></td>
<td>
Expand Down
8 changes: 7 additions & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type AwsCredentials struct {
AWSECRRegistryId string `json:"aws_ecr_registry_id,omitempty"`
AwsRoleArn string `json:"aws_role_arn,omitempty"`
AwsRoleArns []string `json:"aws_role_arns,omitempty"`
AwsAccountId string `json:"aws_account_id,omitempty"`
}

type BasicCredentials struct {
Expand Down Expand Up @@ -426,7 +427,12 @@ func (source *Source) AuthenticateToECR() bool {

// Update username and repository
source.Username = "AWS"
source.Repository = strings.Join([]string{strings.TrimPrefix(*result.AuthorizationData[0].ProxyEndpoint, "https://"), source.Repository}, "/")

if source.AwsAccountId != "" {
source.Repository = fmt.Sprintf("%s.dkr.ecr.%s.amazonaws.com/%s", source.AwsAccountId, source.AwsRegion, source.Repository)
} else {
source.Repository = fmt.Sprintf("%s/%s", strings.TrimPrefix(*result.AuthorizationData[0].ProxyEndpoint, "https://"), source.Repository)
}

return true
}
Expand Down

0 comments on commit 1782ca1

Please sign in to comment.