Skip to content

Commit

Permalink
fix(apprunner-alpha): respect serviceName property (#26238)
Browse files Browse the repository at this point in the history
Use `serviceName` property when creating CfnService resource. 

BREAKING CHANGE: This change will be destructive if the `serviceName` is set on an existing resources.

Closes #26237 

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
roketworks authored Jul 7, 2023
1 parent fdd3309 commit 6da9a4c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 38 deletions.
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-apprunner-alpha/lib/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ export class Service extends cdk.Resource {
}

const resource = new CfnService(this, 'Resource', {
serviceName: this.props.serviceName,
instanceConfiguration: {
cpu: this.props.cpu?.unit,
memory: this.props.memory?.unit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "32.0.0",
"files": {
"798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215": {
"2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e": {
"source": {
"path": "integ-apprunner-ecr-public.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215.json",
"objectKey": "2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"EgressConfiguration": {
"EgressType": "DEFAULT"
}
}
},
"ServiceName": "service1"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/798d29f00c3d8f856bf85b7138c6e647084b39d095a48e9fe00157a314591215.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/2181f59f2645e4bd58941c645d6d82a03c41c276ad3e6fd67609d6a733a7248e.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand All @@ -36,7 +36,10 @@
"/integ-apprunner-ecr-public/Service1/Resource": [
{
"type": "aws:cdk:logicalId",
"data": "Service1EDCC8134"
"data": "Service1EDCC8134",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_REPLACE"
]
}
],
"/integ-apprunner-ecr-public/URL1": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"egressConfiguration": {
"egressType": "DEFAULT"
}
}
},
"serviceName": "service1"
}
},
"constructInfo": {
Expand All @@ -56,38 +57,6 @@
"version": "0.0.0"
}
},
"ServiceName": {
"id": "ServiceName",
"path": "integ-apprunner-ecr-public/ServiceName",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnOutput",
"version": "0.0.0"
}
},
"ServiceId": {
"id": "ServiceId",
"path": "integ-apprunner-ecr-public/ServiceId",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnOutput",
"version": "0.0.0"
}
},
"ServiceStatus": {
"id": "ServiceStatus",
"path": "integ-apprunner-ecr-public/ServiceStatus",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnOutput",
"version": "0.0.0"
}
},
"ServiceArn": {
"id": "ServiceArn",
"path": "integ-apprunner-ecr-public/ServiceArn",
"constructInfo": {
"fqn": "aws-cdk-lib.CfnOutput",
"version": "0.0.0"
}
},
"BootstrapVersion": {
"id": "BootstrapVersion",
"path": "integ-apprunner-ecr-public/BootstrapVersion",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const stack = new cdk.Stack(app, 'integ-apprunner-ecr-public');

// Scenario 1: Create the service from ECR public
const service1 = new Service(stack, 'Service1', {
serviceName: 'service1',
source: Source.fromEcrPublic({
imageConfiguration: {
port: 8000,
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-apprunner-alpha/test/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,27 @@ test('autoDeploymentsEnabled flag is NOT set', () => {
});
});

test('serviceName is set', () => {
// GIVEN
const app = new cdk.App();
const stack = new cdk.Stack(app, 'demo-stack');
const serviceName = 'demo-service';
// WHEN
new apprunner.Service(stack, 'DemoService', {
serviceName: serviceName,
source: apprunner.Source.fromGitHub({
repositoryUrl: 'https://github.com/aws-containers/hello-app-runner',
branch: 'main',
configurationSource: apprunner.ConfigurationSourceType.REPOSITORY,
connection: apprunner.GitHubConnection.fromConnectionArn('MOCK'),
}),
});
// THEN
Template.fromStack(stack).hasResourceProperties('AWS::AppRunner::Service', {
ServiceName: serviceName,
});
});

testDeprecated('Using both environmentVariables and environment should throw an error', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'demo-stack');
Expand Down

0 comments on commit 6da9a4c

Please sign in to comment.