1 | import { ArnComponents } from './arn';
|
2 | import { CfnResource } from './cfn-resource';
|
3 | import { IConstruct, Construct as CoreConstruct } from './construct-compat';
|
4 | import { RemovalPolicy } from './removal-policy';
|
5 | import { Stack } from './stack';
|
6 | import { Construct } from 'constructs';
|
7 | /**
|
8 | * Represents the environment a given resource lives in.
|
9 | * Used as the return value for the {@link IResource.env} property.
|
10 | */
|
11 | export interface ResourceEnvironment {
|
12 | /**
|
13 | * The AWS account ID that this resource belongs to.
|
14 | * Since this can be a Token
|
15 | * (for example, when the account is CloudFormation's AWS::AccountId intrinsic),
|
16 | * make sure to use Token.compareStrings()
|
17 | * instead of just comparing the values for equality.
|
18 | */
|
19 | readonly account: string;
|
20 | /**
|
21 | * The AWS region that this resource belongs to.
|
22 | * Since this can be a Token
|
23 | * (for example, when the region is CloudFormation's AWS::Region intrinsic),
|
24 | * make sure to use Token.compareStrings()
|
25 | * instead of just comparing the values for equality.
|
26 | */
|
27 | readonly region: string;
|
28 | }
|
29 | /**
|
30 | * Interface for the Resource construct.
|
31 | */
|
32 | export interface IResource extends IConstruct {
|
33 | /**
|
34 | * The stack in which this resource is defined.
|
35 | */
|
36 | readonly stack: Stack;
|
37 | /**
|
38 | * The environment this resource belongs to.
|
39 | * For resources that are created and managed by the CDK
|
40 | * (generally, those created by creating new class instances like Role, Bucket, etc.),
|
41 | * this is always the same as the environment of the stack they belong to;
|
42 | * however, for imported resources
|
43 | * (those obtained from static methods like fromRoleArn, fromBucketName, etc.),
|
44 | * that might be different than the stack they were imported into.
|
45 | */
|
46 | readonly env: ResourceEnvironment;
|
47 | /**
|
48 | * Apply the given removal policy to this resource
|
49 | *
|
50 | * The Removal Policy controls what happens to this resource when it stops
|
51 | * being managed by CloudFormation, either because you've removed it from the
|
52 | * CDK application or because you've made a change that requires the resource
|
53 | * to be replaced.
|
54 | *
|
55 | * The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
|
56 | * account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
|
57 | */
|
58 | applyRemovalPolicy(policy: RemovalPolicy): void;
|
59 | }
|
60 | /**
|
61 | * Construction properties for {@link Resource}.
|
62 | */
|
63 | export interface ResourceProps {
|
64 | /**
|
65 | * The value passed in by users to the physical name prop of the resource.
|
66 | *
|
67 | * - `undefined` implies that a physical name will be allocated by
|
68 | * CloudFormation during deployment.
|
69 | * - a concrete value implies a specific physical name
|
70 | * - `PhysicalName.GENERATE_IF_NEEDED` is a marker that indicates that a physical will only be generated
|
71 | * by the CDK if it is needed for cross-environment references. Otherwise, it will be allocated by CloudFormation.
|
72 | *
|
73 | * @default - The physical name will be allocated by CloudFormation at deployment time
|
74 | */
|
75 | readonly physicalName?: string;
|
76 | /**
|
77 | * The AWS account ID this resource belongs to.
|
78 | *
|
79 | * @default - the resource is in the same account as the stack it belongs to
|
80 | */
|
81 | readonly account?: string;
|
82 | /**
|
83 | * The AWS region this resource belongs to.
|
84 | *
|
85 | * @default - the resource is in the same region as the stack it belongs to
|
86 | */
|
87 | readonly region?: string;
|
88 | /**
|
89 | * ARN to deduce region and account from
|
90 | *
|
91 | * The ARN is parsed and the account and region are taken from the ARN.
|
92 | * This should be used for imported resources.
|
93 | *
|
94 | * Cannot be supplied together with either `account` or `region`.
|
95 | *
|
96 | * @default - take environment from `account`, `region` parameters, or use Stack environment.
|
97 | */
|
98 | readonly environmentFromArn?: string;
|
99 | }
|
100 | /**
|
101 | * A construct which represents an AWS resource.
|
102 | */
|
103 | export declare abstract class Resource extends CoreConstruct implements IResource {
|
104 | /**
|
105 | * Check whether the given construct is a Resource
|
106 | */
|
107 | static isResource(construct: IConstruct): construct is CfnResource;
|
108 | readonly stack: Stack;
|
109 | readonly env: ResourceEnvironment;
|
110 | /**
|
111 | * Returns a string-encoded token that resolves to the physical name that
|
112 | * should be passed to the CloudFormation resource.
|
113 | *
|
114 | * This value will resolve to one of the following:
|
115 | * - a concrete value (e.g. `"my-awesome-bucket"`)
|
116 | * - `undefined`, when a name should be generated by CloudFormation
|
117 | * - a concrete name generated automatically during synthesis, in
|
118 | * cross-environment scenarios.
|
119 | *
|
120 | */
|
121 | protected readonly physicalName: string;
|
122 | private _physicalName;
|
123 | private readonly _allowCrossEnvironment;
|
124 | constructor(scope: Construct, id: string, props?: ResourceProps);
|
125 | /**
|
126 | * Called when this resource is referenced across environments
|
127 | * (account/region) to order to request that a physical name will be generated
|
128 | * for this resource during synthesis, so the resource can be referenced
|
129 | * through it's absolute name/arn.
|
130 | *
|
131 | * @internal
|
132 | */
|
133 | _enableCrossEnvironment(): void;
|
134 | /**
|
135 | * Apply the given removal policy to this resource
|
136 | *
|
137 | * The Removal Policy controls what happens to this resource when it stops
|
138 | * being managed by CloudFormation, either because you've removed it from the
|
139 | * CDK application or because you've made a change that requires the resource
|
140 | * to be replaced.
|
141 | *
|
142 | * The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
|
143 | * account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).
|
144 | */
|
145 | applyRemovalPolicy(policy: RemovalPolicy): void;
|
146 | protected generatePhysicalName(): string;
|
147 | /**
|
148 | * Returns an environment-sensitive token that should be used for the
|
149 | * resource's "name" attribute (e.g. `bucket.bucketName`).
|
150 | *
|
151 | * Normally, this token will resolve to `nameAttr`, but if the resource is
|
152 | * referenced across environments, it will be resolved to `this.physicalName`,
|
153 | * which will be a concrete name.
|
154 | *
|
155 | * @param nameAttr The CFN attribute which resolves to the resource's name.
|
156 | * Commonly this is the resource's `ref`.
|
157 | */
|
158 | protected getResourceNameAttribute(nameAttr: string): string;
|
159 | /**
|
160 | * Returns an environment-sensitive token that should be used for the
|
161 | * resource's "ARN" attribute (e.g. `bucket.bucketArn`).
|
162 | *
|
163 | * Normally, this token will resolve to `arnAttr`, but if the resource is
|
164 | * referenced across environments, `arnComponents` will be used to synthesize
|
165 | * a concrete ARN with the resource's physical name. Make sure to reference
|
166 | * `this.physicalName` in `arnComponents`.
|
167 | *
|
168 | * @param arnAttr The CFN attribute which resolves to the ARN of the resource.
|
169 | * Commonly it will be called "Arn" (e.g. `resource.attrArn`), but sometimes
|
170 | * it's the CFN resource's `ref`.
|
171 | * @param arnComponents The format of the ARN of this resource. You must
|
172 | * reference `this.physicalName` somewhere within the ARN in order for
|
173 | * cross-environment references to work.
|
174 | *
|
175 | */
|
176 | protected getResourceArnAttribute(arnAttr: string, arnComponents: ArnComponents): string;
|
177 | }
|