Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cdk): Expose props as read/write properties in CFN resources #2372

Merged
merged 1 commit into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class Deployment extends Resource {
}

this.api = props.api;
this.deploymentId = Lazy.stringValue({ produce: () => this.resource.deploymentId });
this.deploymentId = Lazy.stringValue({ produce: () => this.resource.refAsString });
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class Resource extends ResourceBase {
};
const resource = new CfnResource(this, 'Resource', resourceProps);

this.resourceId = resource.resourceId;
this.resourceId = resource.refAsString;
this.restApi = props.parent.restApi;

// render resource path (special case for root)
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class RestApi extends Resource implements IRestApi {
this.configureCloudWatchRole(resource);
}

this.root = new RootResource(this, props, resource.restApiRootResourceId);
this.root = new RootResource(this, props, resource.attrRootResourceId);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ export class VpcLink extends Resource {
targetArns: props.targets.map(nlb => nlb.loadBalancerArn)
});

this.vpcLinkId = cfnResource.vpcLinkId;
this.vpcLinkId = cfnResource.refAsString;
}
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,4 @@ export = {

}
}
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class ScalableTarget extends Resource implements IScalableTarget {
serviceNamespace: props.serviceNamespace
});

this.scalableTargetId = resource.scalableTargetId;
this.scalableTargetId = resource.refAsString;
}

/**
Expand Down Expand Up @@ -269,4 +269,4 @@ export enum ServiceNamespace {
* Custom Resource
*/
CustomResource = 'custom-resource',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class StepScalingAction extends cdk.Construct {
} as CfnScalingPolicy.StepScalingPolicyConfigurationProperty
});

this.scalingPolicyArn = resource.scalingPolicyArn;
this.scalingPolicyArn = resource.refAsString;
}

/**
Expand Down Expand Up @@ -190,4 +190,4 @@ export interface AdjustmentTier {
* @default +Infinity
*/
readonly upperBound?: number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct {
}
});

this.scalingPolicyArn = resource.scalingPolicyArn;
this.scalingPolicyArn = resource.refAsString;
}
}

Expand Down Expand Up @@ -171,4 +171,4 @@ export enum PredefinedMetric {
SageMakerVariantInvocationsPerInstance = 'SageMakerVariantInvocationsPerInstance',
ECSServiceAverageCPUUtilization = 'ECSServiceAverageCPUUtilization',
ECSServiceAverageMemoryUtilization = 'ECSServiceAverageMemoryUtilization',
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ export class AutoScalingGroup extends AutoScalingGroupBase implements

this.autoScalingGroup = new CfnAutoScalingGroup(this, 'ASG', asgProps);
this.osType = machineImage.os.type;
this.autoScalingGroupName = this.autoScalingGroup.autoScalingGroupName;
this.autoScalingGroupName = this.autoScalingGroup.refAsString;
this.autoScalingGroupArn = Stack.of(this).formatArn({
service: 'autoscaling',
resource: 'autoScalingGroup:*:autoScalingGroupName',
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
// lifecycle hook.
resource.node.addDependency(this.role);

this.lifecycleHookName = resource.lifecycleHookName;
this.lifecycleHookName = resource.refAsString;
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-autoscaling/lib/step-scaling-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class StepScalingAction extends cdk.Construct {
stepAdjustments: cdk.Lazy.anyValue({ produce: () => this.adjustments }),
});

this.scalingPolicyArn = resource.scalingPolicyArn;
this.scalingPolicyArn = resource.refAsString;
}

/**
Expand Down Expand Up @@ -178,4 +178,4 @@ export interface AdjustmentTier {
* @default +Infinity
*/
readonly upperBound?: number;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class TargetTrackingScalingPolicy extends cdk.Construct {
}
});

this.scalingPolicyArn = this.resource.scalingPolicyArn;
this.scalingPolicyArn = this.resource.refAsString;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class Certificate extends Resource implements ICertificate {
domainValidationOptions: allDomainNames.map(domainValidationOption),
});

this.certificateArn = cert.certificateArn;
this.certificateArn = cert.refAsString;

/**
* Return the domain validation options for the given domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function uppercaseProperties(props: Properties): Properties {

function renderResourceType(resourceType?: string) {
if (!resourceType) {
return CfnCustomResource.resourceTypeName;
return CfnCustomResource.cfnResourceTypeName;
}

if (!resourceType.startsWith('Custom::')) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/lib/web_distribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,8 @@ export class CloudFrontWebDistribution extends cdk.Construct implements IDistrib
}

const distribution = new CfnDistribution(this, 'CFDistribution', { distributionConfig });
this.domainName = distribution.distributionDomainName;
this.distributionId = distribution.distributionId;
this.domainName = distribution.attrDomainName;
this.distributionId = distribution.refAsString;
}

private toBehavior(input: BehaviorWithOrigin, protoPolicy?: ViewerProtocolPolicy) {
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-s3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const dist = new cloudfront.CloudFrontWebDistribution(stack, 'Distribution', {
behaviors: [{ isDefaultBehavior: true }],
s3OriginSource: {
s3BucketSource: bucket,
originAccessIdentityId: oai.cloudFrontOriginAccessIdentityId,
originAccessIdentityId: oai.refAsString,
},
}]
});
bucket.addToResourcePolicy(new iam.PolicyStatement({
actions: ['s3:Get*', 's3:List*'],
resources: [bucket.bucketArn, bucket.arnForObjects('*')],
principals: [new iam.CanonicalUserPrincipal(oai.cloudFrontOriginAccessIdentityS3CanonicalUserId)]
principals: [new iam.CanonicalUserPrincipal(oai.attrS3CanonicalUserId)],
}));

new cdk.CfnOutput(stack, 'DistributionDomainName', { value: dist.domainName });
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-cloudtrail/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class Trail extends Resource {

logsRole.addToPolicy(new iam.PolicyStatement({
actions: ["logs:PutLogEvents", "logs:CreateLogStream"],
resources: [logGroup.logGroupArn],
resources: [logGroup.attrArn],
}));
}
if (props.managementEvents) {
Expand All @@ -177,14 +177,14 @@ export class Trail extends Resource {
kmsKeyId: props.kmsKey && props.kmsKey.keyArn,
s3BucketName: s3bucket.bucketName,
s3KeyPrefix: props.s3KeyPrefix,
cloudWatchLogsLogGroupArn: logGroup && logGroup.logGroupArn,
cloudWatchLogsLogGroupArn: logGroup && logGroup.attrArn,
cloudWatchLogsRoleArn: logsRole && logsRole.roleArn,
snsTopicName: props.snsTopic,
eventSelectors: this.eventSelectors
});

this.trailArn = trail.trailArn;
this.trailSnsTopicArn = trail.trailSnsTopicArn;
this.trailArn = trail.attrArn;
this.trailSnsTopicArn = trail.attrSnsTopicArn;

const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
trail.node.addDependency(s3BucketPolicy);
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-cloudwatch/lib/alarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ export class Alarm extends Resource implements IAlarm {
...metricJson(props.metric)
});

this.alarmArn = alarm.alarmArn;
this.alarmName = alarm.alarmName;
this.alarmArn = alarm.attrArn;
this.alarmName = alarm.refAsString;
this.metric = props.metric;
this.annotation = {
// tslint:disable-next-line:max-line-length
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,8 +706,8 @@ export class Project extends ProjectBase {
});

const resourceIdentifiers = new ResourceIdentifiers(this, {
arn: resource.projectArn,
name: resource.projectName,
arn: resource.attrArn,
name: resource.refAsString,
arnComponents: {
service: 'codebuild',
resource: 'project',
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-codecommit/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,19 +284,19 @@ export class Repository extends RepositoryBase {
}

public get repositoryArn() {
return this.repository.repositoryArn;
return this.repository.attrArn;
}

public get repositoryCloneUrlHttp() {
return this.repository.repositoryCloneUrlHttp;
return this.repository.attrCloneUrlHttp;
}

public get repositoryCloneUrlSsh() {
return this.repository.repositoryCloneUrlSsh;
return this.repository.attrCloneUrlSsh;
}

public get repositoryName() {
return this.repository.repositoryName;
return this.repository.attrName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
autoRollbackConfiguration: cdk.Lazy.anyValue({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});

this.deploymentGroupName = resource.deploymentGroupName;
this.deploymentGroupName = resource.refAsString;
this.deploymentGroupArn = arnForDeploymentGroup(this.application.applicationName, this.deploymentGroupName);

if (props.preHook) {
Expand All @@ -179,7 +179,7 @@ export class LambdaDeploymentGroup extends cdk.Resource implements ILambdaDeploy
(props.alias.node.findChild('Resource') as lambda.CfnAlias).options.updatePolicy = {
codeDeployLambdaAliasUpdate: {
applicationName: this.application.applicationName,
deploymentGroupName: resource.deploymentGroupName,
deploymentGroupName: resource.refAsString,
beforeAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.preHook && this.preHook.functionName }),
afterAllowTrafficHook: cdk.Lazy.stringValue({ produce: () => this.postHook && this.postHook.functionName }),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export class ServerDeploymentGroup extends ServerDeploymentGroupBase {
autoRollbackConfiguration: cdk.Lazy.anyValue({ produce: () => renderAutoRollbackConfiguration(this.alarms, props.autoRollback) }),
});

this.deploymentGroupName = resource.deploymentGroupName;
this.deploymentGroupName = resource.refAsString;
this.deploymentGroupArn = arnForDeploymentGroup(this.application.applicationName, this.deploymentGroupName);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export class Pipeline extends PipelineBase {
this.artifactBucket.grantReadWrite(this.role);

this.pipelineName = codePipeline.refAsString;
this.pipelineVersion = codePipeline.pipelineVersion;
this.pipelineVersion = codePipeline.attrVersion;
this.crossRegionReplicationBuckets = props.crossRegionReplicationBuckets || {};
this.artifactStores = {};

Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-cognito/lib/user-pool-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ export class UserPoolClient extends Resource {
explicitAuthFlows: props.enabledAuthFlows
});

this.userPoolClientId = resource.userPoolClientId;
this.userPoolClientClientSecret = resource.userPoolClientClientSecret;
this.userPoolClientName = resource.userPoolClientName;
this.userPoolClientId = resource.refAsString;
this.userPoolClientClientSecret = resource.attrClientSecret;
this.userPoolClientName = resource.attrName;
}
}
}
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-cognito/lib/user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,10 @@ export class UserPool extends Resource implements IUserPool {
autoVerifiedAttributes: props.autoVerifiedAttributes,
lambdaConfig: Lazy.anyValue({ produce: () => this.triggers })
});
this.userPoolId = userPool.userPoolId;
this.userPoolArn = userPool.userPoolArn;
this.userPoolProviderName = userPool.userPoolProviderName;
this.userPoolProviderUrl = userPool.userPoolProviderUrl;
this.userPoolId = userPool.refAsString;
this.userPoolArn = userPool.attrArn;
this.userPoolProviderName = userPool.attrProviderName;
this.userPoolProviderUrl = userPool.attrProviderUrl;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions packages/@aws-cdk/aws-config/lib/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,10 @@ export class ManagedRule extends RuleNew {
}
});

this.configRuleName = rule.configRuleName;
this.configRuleArn = rule.configRuleArn;
this.configRuleId = rule.configRuleId;
this.configRuleComplianceType = rule.configRuleComplianceType;
this.configRuleName = rule.refAsString;
this.configRuleArn = rule.attrArn;
this.configRuleId = rule.attrConfigRuleId;
this.configRuleComplianceType = rule.attrComplianceType;

this.isManaged = true;
}
Expand Down Expand Up @@ -366,10 +366,10 @@ export class CustomRule extends RuleNew {
}
});

this.configRuleName = rule.configRuleName;
this.configRuleArn = rule.configRuleArn;
this.configRuleId = rule.configRuleId;
this.configRuleComplianceType = rule.configRuleComplianceType;
this.configRuleName = rule.refAsString;
this.configRuleArn = rule.attrArn;
this.configRuleId = rule.attrConfigRuleId;
this.configRuleComplianceType = rule.attrComplianceType;

if (props.configurationChanges) {
this.isCustomWithChanges = true;
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export class Table extends Resource {

if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); }

this.tableArn = this.table.tableArn;
this.tableName = this.table.tableName;
this.tableStreamArn = this.table.tableStreamArn;
this.tableArn = this.table.attrArn;
this.tableName = this.table.refAsString;
this.tableStreamArn = this.table.attrStreamArn;

this.scalingRole = this.makeScalingRole();

Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-ec2/lib/security-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ export class SecurityGroup extends SecurityGroupBase {
vpcId: props.vpc.vpcId,
});

this.securityGroupId = this.securityGroup.securityGroupId;
this.securityGroupVpcId = this.securityGroup.securityGroupVpcId;
this.securityGroupName = this.securityGroup.securityGroupName;
this.securityGroupId = this.securityGroup.attrGroupId;
this.securityGroupVpcId = this.securityGroup.attrVpcId;
this.securityGroupName = this.securityGroup.refAsString;

this.addDefaultEgressRule();
}
Expand Down
Loading