-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ecs): add
BaseService.fromServiceArnWithCluster()
for use in C…
…odePipeline (#18530) This adds support for importing a ECS Cluster via the Arn, and not requiring the VPC or Security Groups. This will generate an ICluster which can be used in `Ec2Service.fromEc2ServiceAttributes()` and `FargateService.fromFargateServiceAttributes()` to get an `IBaseService` which can be used in the `EcsDeployAction` to allow for cross account/region deployments in CodePipelines. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
de3fa57
commit 3d192a9
Showing
7 changed files
with
266 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import * as ecs from '../lib'; | ||
|
||
let stack: cdk.Stack; | ||
|
||
beforeEach(() => { | ||
stack = new cdk.Stack(); | ||
}); | ||
|
||
describe('When import an ECS Service', () => { | ||
test('with serviceArnWithCluster', () => { | ||
// GIVEN | ||
const clusterName = 'cluster-name'; | ||
const serviceName = 'my-http-service'; | ||
const region = 'service-region'; | ||
const account = 'service-account'; | ||
const serviceArn = `arn:aws:ecs:${region}:${account}:service/${clusterName}/${serviceName}`; | ||
|
||
// WHEN | ||
const service = ecs.BaseService.fromServiceArnWithCluster(stack, 'Service', serviceArn); | ||
|
||
// THEN | ||
expect(service.serviceArn).toEqual(serviceArn); | ||
expect(service.serviceName).toEqual(serviceName); | ||
expect(service.env.account).toEqual(account); | ||
expect(service.env.region).toEqual(region); | ||
|
||
expect(service.cluster.clusterName).toEqual(clusterName); | ||
expect(service.cluster.env.account).toEqual(account); | ||
expect(service.cluster.env.region).toEqual(region); | ||
}); | ||
|
||
test('throws an expection if no resourceName provided on fromServiceArnWithCluster', () => { | ||
expect(() => { | ||
ecs.BaseService.fromServiceArnWithCluster(stack, 'Service', 'arn:aws:ecs:service-region:service-account:service'); | ||
}).toThrowError(/Missing resource Name from service ARN/); | ||
}); | ||
|
||
test('throws an expection if not using cluster arn format on fromServiceArnWithCluster', () => { | ||
expect(() => { | ||
ecs.BaseService.fromServiceArnWithCluster(stack, 'Service', 'arn:aws:ecs:service-region:service-account:service/my-http-service'); | ||
}).toThrowError(/is not using the ARN cluster format/); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters