Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static fromAwsManagedPolicyName(managedPolicyName: string): IManagedPolicy {
class AwsManagedPolicy implements IManagedPolicy {
public readonly managedPolicyArn = Lazy.stringValue({
produce(ctx: IResolveContext) {
return Stack.of(ctx.scope).formatArn({
service: "iam",
region: "", // no region for managed policy
account: "aws", // the account for a managed policy is 'aws'
resource: "policy",
resourceName: managedPolicyName
});
}
});
}
return new AwsManagedPolicy();
}
this.addSecondaryArtifact(secondaryArtifact);
}
this.validateCodePipelineSettings(artifacts);
const resource = new CfnProject(this, 'Resource', {
description: props.description,
source: {
...sourceConfig.sourceProperty,
buildSpec: buildSpec && buildSpec.toBuildSpec()
},
artifacts: artifactsConfig.artifactsProperty,
serviceRole: this.role.roleArn,
environment: this.renderEnvironment(props.environment, environmentVariables),
// lazy, because we have a setter for it in setEncryptionKey
encryptionKey: Lazy.stringValue({ produce: () => this._encryptionKey && this._encryptionKey.keyArn }),
badgeEnabled: props.badge,
cache: cache._toCloudFormation(),
name: this.physicalName,
timeoutInMinutes: props.timeout && props.timeout.toMinutes(),
secondarySources: Lazy.anyValue({ produce: () => this.renderSecondarySources() }),
secondaryArtifacts: Lazy.anyValue({ produce: () => this.renderSecondaryArtifacts() }),
triggers: sourceConfig.buildTriggers,
vpcConfig: this.configureVpc(props),
});
this.addVpcRequiredPermissions(props, resource);
this.projectArn = this.getResourceArnAttribute(resource.attrArn, {
service: 'codebuild',
resource: 'project',
resourceName: this.physicalName,
this.availabilityZone = props.availabilityZone;
const subnet = new CfnSubnet(this, 'Subnet', {
vpcId: props.vpcId,
cidrBlock: props.cidrBlock,
availabilityZone: props.availabilityZone,
mapPublicIpOnLaunch: props.mapPublicIpOnLaunch,
});
this.subnetId = subnet.ref;
this.subnetVpcId = subnet.attrVpcId;
this.subnetAvailabilityZone = subnet.attrAvailabilityZone;
this.subnetIpv6CidrBlocks = subnet.attrIpv6CidrBlocks;
// subnet.attrNetworkAclAssociationId is the default ACL after the subnet
// was just created. However, the ACL can be replaced at a later time.
this._networkAcl = NetworkAcl.fromNetworkAclId(this, 'Acl', subnet.attrNetworkAclAssociationId);
this.subnetNetworkAclAssociationId = Lazy.stringValue({ produce: () => this._networkAcl.networkAclId });
this.node.defaultChild = subnet;
const table = new CfnRouteTable(this, 'RouteTable', {
vpcId: props.vpcId,
});
this.routeTable = { routeTableId: table.ref };
// Associate the public route table for this subnet, to this subnet
new CfnSubnetRouteTableAssociation(this, 'RouteTableAssociation', {
subnetId: this.subnetId,
routeTableId: table.ref
});
this.internetConnectivityEstablished = this._internetConnectivityEstablished;
}
this.role = props.role || new iam.Role(this, 'InstanceRole', {
roleName: PhysicalName.GENERATE_IF_NEEDED,
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
this.grantPrincipal = this.role;
const iamProfile = new iam.CfnInstanceProfile(this, 'InstanceProfile', {
roles: [ this.role.roleName ]
});
// use delayed evaluation
const imageConfig = props.machineImage.getImage(this);
this.userData = props.userData || imageConfig.userData || ec2.UserData.forOperatingSystem(imageConfig.osType);
const userDataToken = Lazy.stringValue({ produce: () => Fn.base64(this.userData.render()) });
const securityGroupsToken = Lazy.listValue({ produce: () => this.securityGroups.map(sg => sg.securityGroupId) });
const launchConfig = new CfnLaunchConfiguration(this, 'LaunchConfig', {
imageId: imageConfig.imageId,
keyName: props.keyName,
instanceType: props.instanceType.toString(),
securityGroups: securityGroupsToken,
iamInstanceProfile: iamProfile.ref,
userData: userDataToken,
associatePublicIpAddress: props.associatePublicIpAddress,
spotPrice: props.spotPrice,
blockDeviceMappings: (props.blockDevices !== undefined ? props.blockDevices.map(
({deviceName, volume, mappingEnabled}) => {
const {virtualName, ebsDevice: ebs} = volume;
if (ebs) {
function stringifyNumber(x: number) {
if (Token.isUnresolved(x)) {
return Lazy.stringValue({ produce: context => `${context.resolve(x)}` });
} else {
return `${x}`;
}
}
function artifactAttribute(artifact: Artifact, attributeName: string) {
const lazyArtifactName = Lazy.stringValue({ produce: () => artifact.artifactName });
return Token.asString({ 'Fn::GetArtifactAtt': [lazyArtifactName, attributeName] });
}
constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
super(scope, id, {
physicalName: props.vpcLinkName ||
Lazy.stringValue({ produce: () => this.node.uniqueId }),
});
const cfnResource = new CfnVpcLink(this, 'Resource', {
name: this.physicalName,
description: props.description,
targetArns: Lazy.listValue({ produce: () => this.renderTargets() })
});
this.vpcLinkId = cfnResource.ref;
if (props.targets) {
this.addTargets(...props.targets);
}
}
constructor(scope: Construct, id: string, props: RuleProps = { }) {
super(scope, id, {
physicalName: props.ruleName,
});
this.description = props.description;
const resource = new CfnRule(this, 'Resource', {
name: this.physicalName,
description: this.description,
state: props.enabled == null ? 'ENABLED' : (props.enabled ? 'ENABLED' : 'DISABLED'),
scheduleExpression: Lazy.stringValue({ produce: () => this.scheduleExpression }),
eventPattern: Lazy.anyValue({ produce: () => this.renderEventPattern() }),
targets: Lazy.anyValue({ produce: () => this.renderTargets() }),
});
this.ruleArn = this.getResourceArnAttribute(resource.attrArn, {
service: 'events',
resource: 'rule',
resourceName: this.physicalName,
});
this.addEventPattern(props.eventPattern);
this.scheduleExpression = props.schedule && props.schedule.expressionString;
for (const target of props.targets || []) {
this.addTarget(target);
}
constructor(scope: Construct, id: string, props: CloudFormationStackDriftDetectionCheckProps = {}) {
super(scope, id, {
...props,
identifier: 'CLOUDFORMATION_STACK_DRIFT_DETECTION_CHECK',
inputParameters: {
cloudformationRoleArn: Lazy.stringValue({ produce: () => this.role.roleArn })
}
});
this.scopeToResource('AWS::CloudFormation::Stack', props.ownStackOnly ? Stack.of(this).stackId : undefined);
this.role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('config.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('ReadOnlyAccess')
]
});
}
}