|
1 | 1 | import { testDeprecated } from '@aws-cdk/cdk-build-tools';
|
2 | 2 | import { Annotations, Match, Template } from '../../../assertions';
|
3 | 3 | import * as appscaling from '../../../aws-applicationautoscaling';
|
| 4 | +import * as batch from '../../../aws-batch'; |
4 | 5 | import * as cloudwatch from '../../../aws-cloudwatch';
|
5 | 6 | import * as ec2 from '../../../aws-ec2';
|
6 | 7 | import * as elbv2 from '../../../aws-elasticloadbalancingv2';
|
@@ -685,6 +686,92 @@ describe('fargate service', () => {
|
685 | 686 | }).toThrow(/one essential container/);
|
686 | 687 | });
|
687 | 688 |
|
| 689 | + test('errors when platform version does not support containers which references secret JSON field', () => { |
| 690 | + // GIVEN |
| 691 | + const stack = new cdk.Stack(); |
| 692 | + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); |
| 693 | + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); |
| 694 | + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { |
| 695 | + runtimePlatform: { |
| 696 | + operatingSystemFamily: ecs.OperatingSystemFamily.LINUX, |
| 697 | + cpuArchitecture: ecs.CpuArchitecture.ARM64, |
| 698 | + }, |
| 699 | + memoryLimitMiB: 512, |
| 700 | + cpu: 256, |
| 701 | + }); |
| 702 | + |
| 703 | + // Errors on validation, not on construction. |
| 704 | + new ecs.FargateService(stack, 'FargateService', { |
| 705 | + cluster, |
| 706 | + taskDefinition, |
| 707 | + platformVersion: ecs.FargatePlatformVersion.VERSION1_2, |
| 708 | + }); |
| 709 | + |
| 710 | + taskDefinition.addContainer('main', { |
| 711 | + image: ecs.ContainerImage.fromRegistry('somecontainer'), |
| 712 | + secrets: { |
| 713 | + envName: batch.Secret.fromSecretsManager(new secretsmanager.Secret(stack, 'testSecret'), 'secretField'), |
| 714 | + }, |
| 715 | + }); |
| 716 | + |
| 717 | + // THEN |
| 718 | + expect(() => { |
| 719 | + Template.fromStack(stack); |
| 720 | + }).toThrow(/This feature requires platform version/); |
| 721 | + }); |
| 722 | + |
| 723 | + test('errors when platform version does not support ephemeralStorageGiB', () => { |
| 724 | + // GIVEN |
| 725 | + const stack = new cdk.Stack(); |
| 726 | + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); |
| 727 | + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); |
| 728 | + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { |
| 729 | + runtimePlatform: { |
| 730 | + operatingSystemFamily: ecs.OperatingSystemFamily.LINUX, |
| 731 | + cpuArchitecture: ecs.CpuArchitecture.ARM64, |
| 732 | + }, |
| 733 | + memoryLimitMiB: 512, |
| 734 | + cpu: 256, |
| 735 | + ephemeralStorageGiB: 100, |
| 736 | + }); |
| 737 | + |
| 738 | + // WHEN |
| 739 | + // THEN |
| 740 | + expect(() => { |
| 741 | + new ecs.FargateService(stack, 'FargateService', { |
| 742 | + cluster, |
| 743 | + taskDefinition, |
| 744 | + platformVersion: ecs.FargatePlatformVersion.VERSION1_2, |
| 745 | + }); |
| 746 | + }).toThrow(/The ephemeralStorageGiB feature requires platform version/); |
| 747 | + }); |
| 748 | + |
| 749 | + test('errors when platform version does not support pidMode', () => { |
| 750 | + // GIVEN |
| 751 | + const stack = new cdk.Stack(); |
| 752 | + const vpc = new ec2.Vpc(stack, 'MyVpc', {}); |
| 753 | + const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc }); |
| 754 | + const taskDefinition = new ecs.FargateTaskDefinition(stack, 'FargateTaskDef', { |
| 755 | + runtimePlatform: { |
| 756 | + operatingSystemFamily: ecs.OperatingSystemFamily.LINUX, |
| 757 | + cpuArchitecture: ecs.CpuArchitecture.ARM64, |
| 758 | + }, |
| 759 | + memoryLimitMiB: 512, |
| 760 | + cpu: 256, |
| 761 | + pidMode: ecs.PidMode.HOST, |
| 762 | + }); |
| 763 | + |
| 764 | + // WHEN |
| 765 | + // THEN |
| 766 | + expect(() => { |
| 767 | + new ecs.FargateService(stack, 'FargateService', { |
| 768 | + cluster, |
| 769 | + taskDefinition, |
| 770 | + platformVersion: ecs.FargatePlatformVersion.VERSION1_2, |
| 771 | + }); |
| 772 | + }).toThrow(/The pidMode feature requires platform version/); |
| 773 | + }); |
| 774 | + |
688 | 775 | test('allows adding the default container after creating the service', () => {
|
689 | 776 | // GIVEN
|
690 | 777 | const stack = new cdk.Stack();
|
|
0 commit comments