Skip to content

Commit 4363d90

Browse files
Hawxygithub-actions
andauthored
feat: Expose cachedInContext flag to prevent instance recycling (#27)
* feat: Expose cachedInContext flag to prevent instance recycling * Pass false by default * chore: self mutation Signed-off-by: github-actions <github-actions@github.com> * Doc tweak * chore: self mutation Signed-off-by: github-actions <github-actions@github.com> --------- Signed-off-by: github-actions <github-actions@github.com> Co-authored-by: JT <Hawxy@users.noreply.github.com> Co-authored-by: github-actions <github-actions@github.com>
1 parent 10b7459 commit 4363d90

File tree

11 files changed

+1259
-996
lines changed

11 files changed

+1259
-996
lines changed

.eslintrc.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: Hawxy

.github/workflows/pull-request-lint.yml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mergify.yml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/deps.json

Lines changed: 11 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
55
authorAddress: 'Hawxy@users.noreply.github.com',
66
cdkVersion: '2.80.0',
77
constructsVersion: '10.1.0',
8-
jsiiVersion: '~5.5.0',
8+
jsiiVersion: '~5.7.0',
99
majorVersion: 2,
1010
defaultReleaseBranch: 'main',
1111
name: 'cdk-tailscale-bastion',

API.md

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export interface TailscaleCredentials {
3838
* Provides an auth key as a plaintext string.
3939
* This option will expose the auth key in your CDK template and should only be used with non-reusable keys.
4040
* Potentially useful for DevOps runbooks and temporary instances.
41+
*
42+
* The `cachedInContext` configuration option might be relevant to you if you use this parameter.
4143
*/
4244
readonly unsafeString?: string;
4345
}
@@ -103,6 +105,14 @@ export interface TailscaleBastionProps {
103105
* Advertise a custom route instead of using the VPC CIDR, used for Tailscale 4via6 support.
104106
*/
105107
readonly advertiseRoute?: string;
108+
/**
109+
* Setting this to true will result in the Amazon Linux AMI being cached in `cdk.context.json` and prevent the instance being replaced when the image is updated.
110+
* Enable this if you'd like to use non-reusable Tailscale keys, or you'd prefer the instance to remain stable.
111+
* Keep in mind that the AMI will grow old over time and is it your responsibility to evict it from the context.
112+
*
113+
* @default false
114+
*/
115+
readonly cachedInContext?: boolean;
106116
}
107117

108118
export class TailscaleBastion extends Construct {
@@ -122,6 +132,7 @@ export class TailscaleBastion extends Construct {
122132
incomingRoutes,
123133
advertiseRoute,
124134
cpuType,
135+
cachedInContext,
125136
} = props;
126137

127138
const authKeyCommand = this.computeTsKeyCli(tailscaleCredentials);
@@ -132,7 +143,7 @@ export class TailscaleBastion extends Construct {
132143
instanceName: instanceName ?? 'BastionHostTailscale',
133144
securityGroup,
134145
instanceType,
135-
machineImage: MachineImage.latestAmazonLinux2023({ cpuType: cpuType ?? AmazonLinuxCpuType.X86_64 }),
146+
machineImage: MachineImage.latestAmazonLinux2023({ cpuType: cpuType ?? AmazonLinuxCpuType.X86_64, cachedInContext: cachedInContext ?? false }),
136147
subnetSelection: subnetSelection ?? { subnetType: SubnetType.PUBLIC },
137148
init: CloudFormationInit.fromElements(
138149
// Configure IP forwarding

0 commit comments

Comments
 (0)