Skip to content

Commit

Permalink
chore: migrate constructs to use "constructs" module (#10606)
Browse files Browse the repository at this point in the history
This commits expands on a previous [commit]. The remaining
CDK modules have been migrated to use the `Construct` and
`IConstruct` from the "constructs" module instead of the
"@aws-cdk/core" module.

Migrating modules to use the "constructs" module, prevents merge
conflicts from arising in these files when the construct compatibility
layer in "@aws-cdk/core" module is removed in the v2 branch.

[commit]: c179699

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored Oct 1, 2020
1 parent 0331508 commit 60c782f
Show file tree
Hide file tree
Showing 179 changed files with 667 additions and 275 deletions.
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amplify/lib/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as codebuild from '@aws-cdk/aws-codebuild';
import * as iam from '@aws-cdk/aws-iam';
import { Construct, IResource, Lazy, Resource, SecretValue } from '@aws-cdk/core';
import { IResource, Lazy, Resource, SecretValue } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApp } from './amplify.generated';
import { BasicAuth } from './basic-auth';
import { Branch, BranchOptions } from './branch';
Expand Down
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-amplify/lib/basic-auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as kms from '@aws-cdk/aws-kms';
import * as secretsmanager from '@aws-cdk/aws-secretsmanager';
import { Construct, SecretValue } from '@aws-cdk/core';
import { SecretValue } from '@aws-cdk/core';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* Properties for a BasicAuth
Expand Down Expand Up @@ -78,7 +82,7 @@ export class BasicAuth {
/**
* Binds this Basic Auth configuration to an App
*/
public bind(scope: Construct, id: string): BasicAuthConfig {
public bind(scope: CoreConstruct, id: string): BasicAuthConfig {
const config = {
enableBasicAuth: true,
username: this.props.username,
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amplify/lib/branch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as codebuild from '@aws-cdk/aws-codebuild';
import { Construct, IResource, Lazy, Resource } from '@aws-cdk/core';
import { IResource, Lazy, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnBranch } from './amplify.generated';
import { IApp } from './app';
import { BasicAuth } from './basic-auth';
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-amplify/lib/domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Construct, Lazy, Resource, IResolvable } from '@aws-cdk/core';
import { Lazy, Resource, IResolvable } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDomain } from './amplify.generated';
import { IApp } from './app';
import { IBranch } from './branch';
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-amplify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
},
"cdk-build": {
"cloudformation": "AWS::Amplify",
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"keywords": [
"aws",
Expand Down
9 changes: 7 additions & 2 deletions packages/@aws-cdk/aws-appsync/lib/data-source.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { ITable } from '@aws-cdk/aws-dynamodb';
import { IGrantable, IPrincipal, IRole, Role, ServicePrincipal } from '@aws-cdk/aws-iam';
import { IFunction } from '@aws-cdk/aws-lambda';
import { Construct, IResolvable } from '@aws-cdk/core';
import { IResolvable } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnDataSource } from './appsync.generated';
import { IGraphqlApi } from './graphqlapi-base';
import { BaseResolverProps, Resolver } from './resolver';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* Base properties for an AppSync datasource
*/
Expand Down Expand Up @@ -83,7 +88,7 @@ export interface ExtendedDataSourceProps {
/**
* Abstract AppSync datasource implementation. Do not use directly but use subclasses for concrete datasources
*/
export abstract class BaseDataSource extends Construct {
export abstract class BaseDataSource extends CoreConstruct {
/**
* the name of the data source
*/
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { IUserPool } from '@aws-cdk/aws-cognito';
import { ManagedPolicy, Role, ServicePrincipal, Grant, IGrantable } from '@aws-cdk/aws-iam';
import { CfnResource, Construct, Duration, Expiration, IResolvable, Stack } from '@aws-cdk/core';
import { CfnResource, Duration, Expiration, IResolvable, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnApiKey, CfnGraphQLApi, CfnGraphQLSchema } from './appsync.generated';
import { IGraphqlApi, GraphqlApiBase } from './graphqlapi-base';
import { Schema } from './schema';
Expand Down
8 changes: 6 additions & 2 deletions packages/@aws-cdk/aws-appsync/lib/resolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Construct } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnResolver } from './appsync.generated';
import { BaseDataSource } from './data-source';
import { IGraphqlApi } from './graphqlapi-base';
import { MappingTemplate } from './mapping-template';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* Basic properties for an AppSync resolver
*/
Expand Down Expand Up @@ -56,7 +60,7 @@ export interface ResolverProps extends BaseResolverProps {
/**
* An AppSync resolver
*/
export class Resolver extends Construct {
export class Resolver extends CoreConstruct {
/**
* the ARN of the resolver
*/
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-appsync/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
},
"cdk-build": {
"cloudformation": "AWS::AppSync",
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"keywords": [
"aws",
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-autoscaling-hooktargets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
},
"maturity": "stable",
"cdk-build": {
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
}
}
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-backup/lib/plan.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Construct, IResource, Lazy, Resource } from '@aws-cdk/core';
import { IResource, Lazy, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnBackupPlan } from './backup.generated';
import { BackupPlanRule } from './rule';
import { BackupSelection, BackupSelectionOptions } from './selection';
Expand Down
11 changes: 8 additions & 3 deletions packages/@aws-cdk/aws-backup/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as dynamodb from '@aws-cdk/aws-dynamodb';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as efs from '@aws-cdk/aws-efs';
import * as rds from '@aws-cdk/aws-rds';
import { Construct, Stack } from '@aws-cdk/core';
import { Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* An operation that is applied to a key-value pair
Expand Down Expand Up @@ -129,11 +134,11 @@ export class BackupResource {
/**
* A construct
*/
public readonly construct?: Construct;
public readonly construct?: CoreConstruct;

constructor(resource?: string, tagCondition?: TagCondition, construct?: Construct) {
this.resource = resource;
this.tagCondition = tagCondition;
this.construct = construct;
this.construct = construct as CoreConstruct;
}
}
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-backup/lib/selection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as iam from '@aws-cdk/aws-iam';
import { Construct, Lazy, Resource, Aspects } from '@aws-cdk/core';
import { Lazy, Resource, Aspects } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnBackupSelection } from './backup.generated';
import { BackupableResourcesCollector } from './backupable-resources-collector';
import { IBackupPlan } from './plan';
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-backup/lib/vault.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as iam from '@aws-cdk/aws-iam';
import * as kms from '@aws-cdk/aws-kms';
import * as sns from '@aws-cdk/aws-sns';
import { Construct, IResource, RemovalPolicy, Resource } from '@aws-cdk/core';
import { IResource, RemovalPolicy, Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnBackupVault } from './backup.generated';

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-backup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@
},
"cdk-build": {
"cloudformation": "AWS::Backup",
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"keywords": [
"aws",
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-batch/lib/compute-environment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as iam from '@aws-cdk/aws-iam';
import { Construct, IResource, Resource, Stack } from '@aws-cdk/core';
import { IResource, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnComputeEnvironment } from './batch.generated';

/**
Expand Down
12 changes: 8 additions & 4 deletions packages/@aws-cdk/aws-batch/lib/job-definition-image-config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import * as ecs from '@aws-cdk/aws-ecs';
import * as iam from '@aws-cdk/aws-iam';
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { JobDefinitionContainer } from './job-definition';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* TaskDefinitionRole
*
Expand Down Expand Up @@ -57,14 +61,14 @@ export class JobDefinitionImageConfig {
*/
public readonly imageName: string;

constructor(scope: cdk.Construct, container: JobDefinitionContainer) {
constructor(scope: Construct, container: JobDefinitionContainer) {
const config = this.bindImageConfig(scope, container);

this.imageName = config.imageName;
}

private bindImageConfig(scope: cdk.Construct, container: JobDefinitionContainer): ecs.ContainerImageConfig {
return container.image.bind(scope, new ecs.ContainerDefinition(scope, 'Resource-Batch-Job-Container-Definition', {
private bindImageConfig(scope: Construct, container: JobDefinitionContainer): ecs.ContainerImageConfig {
return container.image.bind(scope as CoreConstruct, new ecs.ContainerDefinition(scope, 'Resource-Batch-Job-Container-Definition', {
command: container.command,
cpu: container.vcpus,
image: container.image,
Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-batch/lib/job-definition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as iam from '@aws-cdk/aws-iam';
import { Construct, Duration, IResource, Resource, Stack } from '@aws-cdk/core';
import { Duration, IResource, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnJobDefinition } from './batch.generated';
import { JobDefinitionImageConfig } from './job-definition-image-config';

Expand Down
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-batch/lib/job-queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Construct, IResource, Resource, Stack } from '@aws-cdk/core';
import { IResource, Resource, Stack } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnJobQueue } from './batch.generated';
import { IComputeEnvironment } from './compute-environment';

Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-batch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
},
"cdk-build": {
"cloudformation": "AWS::Batch",
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
},
"keywords": [
"aws",
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-cloudwatch-actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
},
"maturity": "stable",
"cdk-build": {
"jest": true
"jest": true,
"env": {
"AWSLINT_BASE_CONSTRUCT": true
}
}
}
11 changes: 7 additions & 4 deletions packages/@aws-cdk/aws-codebuild/lib/artifacts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import * as s3 from '@aws-cdk/aws-s3';
import { Construct } from '@aws-cdk/core';
import { CfnProject } from './codebuild.generated';
import { IProject } from './project';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* The type returned from {@link IArtifacts#bind}.
*/
Expand Down Expand Up @@ -35,7 +38,7 @@ export interface IArtifacts {
* @param scope a root Construct that allows creating new Constructs
* @param project the Project this Artifacts is used in
*/
bind(scope: Construct, project: IProject): ArtifactsConfig;
bind(scope: CoreConstruct, project: IProject): ArtifactsConfig;
}

/**
Expand Down Expand Up @@ -64,7 +67,7 @@ export abstract class Artifacts implements IArtifacts {
this.identifier = props.identifier;
}

public bind(_scope: Construct, _project: IProject): ArtifactsConfig {
public bind(_scope: CoreConstruct, _project: IProject): ArtifactsConfig {
return {
artifactsProperty: {
artifactIdentifier: this.identifier,
Expand Down Expand Up @@ -140,7 +143,7 @@ class S3Artifacts extends Artifacts {
super(props);
}

public bind(_scope: Construct, project: IProject): ArtifactsConfig {
public bind(_scope: CoreConstruct, project: IProject): ArtifactsConfig {
this.props.bucket.grantReadWrite(project);
const superConfig = super.bind(_scope, project);
return {
Expand Down
9 changes: 6 additions & 3 deletions packages/@aws-cdk/aws-codebuild/lib/file-location.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Construct } from '@aws-cdk/core';
import { CfnProject } from './codebuild.generated';
import { IProject } from './project';

// v2 - keep this import as a separate section to reduce merge conflict when forward merging with the v2 branch.
// eslint-disable-next-line
import { Construct as CoreConstruct } from '@aws-cdk/core';

/**
* The type returned from {@link IFileSystemLocation#bind}.
*/
Expand All @@ -22,7 +25,7 @@ export interface IFileSystemLocation {
* Called by the project when a file system is added so it can perform
* binding operations on this file system location.
*/
bind(scope: Construct, project: IProject): FileSystemConfig;
bind(scope: CoreConstruct, project: IProject): FileSystemConfig;
}

/**
Expand All @@ -44,7 +47,7 @@ export class FileSystemLocation {
class EfsFileSystemLocation implements IFileSystemLocation {
constructor(private readonly props: EfsFileSystemLocationProps) {}

public bind(_scope: Construct, _project: IProject): FileSystemConfig {
public bind(_scope: CoreConstruct, _project: IProject): FileSystemConfig {
return {
location: {
identifier: this.props.identifier,
Expand Down
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/pipeline-project.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as cdk from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CodePipelineArtifacts } from './codepipeline-artifacts';
import { CodePipelineSource } from './codepipeline-source';
import { CommonProjectProps, Project } from './project';
Expand All @@ -10,7 +10,7 @@ export interface PipelineProjectProps extends CommonProjectProps {
* A convenience class for CodeBuild Projects that are used in CodePipeline.
*/
export class PipelineProject extends Project {
constructor(scope: cdk.Construct, id: string, props?: PipelineProjectProps) {
constructor(scope: Construct, id: string, props?: PipelineProjectProps) {
super(scope, id, {
source: new CodePipelineSource(),
artifacts: new CodePipelineArtifacts(),
Expand Down
Loading

0 comments on commit 60c782f

Please sign in to comment.