Skip to content

Commit

Permalink
feat: Expose cachedInContext flag to prevent instance recycling (#27)
Browse files Browse the repository at this point in the history
* feat: Expose cachedInContext flag to prevent instance recycling

* Pass false by default

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

* Doc tweak

* chore: self mutation

Signed-off-by: github-actions <[email protected]>

---------

Signed-off-by: github-actions <[email protected]>
Co-authored-by: JT <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
3 people authored Jan 15, 2025
1 parent 10b7459 commit 4363d90
Show file tree
Hide file tree
Showing 11 changed files with 1,259 additions and 996 deletions.
7 changes: 4 additions & 3 deletions .eslintrc.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: Hawxy
2 changes: 2 additions & 0 deletions .github/workflows/pull-request-lint.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions .mergify.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
authorAddress: '[email protected]',
cdkVersion: '2.80.0',
constructsVersion: '10.1.0',
jsiiVersion: '~5.5.0',
jsiiVersion: '~5.7.0',
majorVersion: 2,
defaultReleaseBranch: 'main',
name: 'cdk-tailscale-bastion',
Expand Down
16 changes: 16 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface TailscaleCredentials {
* Provides an auth key as a plaintext string.
* This option will expose the auth key in your CDK template and should only be used with non-reusable keys.
* Potentially useful for DevOps runbooks and temporary instances.
*
* The `cachedInContext` configuration option might be relevant to you if you use this parameter.
*/
readonly unsafeString?: string;
}
Expand Down Expand Up @@ -103,6 +105,14 @@ export interface TailscaleBastionProps {
* Advertise a custom route instead of using the VPC CIDR, used for Tailscale 4via6 support.
*/
readonly advertiseRoute?: string;
/**
* 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.
* Enable this if you'd like to use non-reusable Tailscale keys, or you'd prefer the instance to remain stable.
* Keep in mind that the AMI will grow old over time and is it your responsibility to evict it from the context.
*
* @default false
*/
readonly cachedInContext?: boolean;
}

export class TailscaleBastion extends Construct {
Expand All @@ -122,6 +132,7 @@ export class TailscaleBastion extends Construct {
incomingRoutes,
advertiseRoute,
cpuType,
cachedInContext,
} = props;

const authKeyCommand = this.computeTsKeyCli(tailscaleCredentials);
Expand All @@ -132,7 +143,7 @@ export class TailscaleBastion extends Construct {
instanceName: instanceName ?? 'BastionHostTailscale',
securityGroup,
instanceType,
machineImage: MachineImage.latestAmazonLinux2023({ cpuType: cpuType ?? AmazonLinuxCpuType.X86_64 }),
machineImage: MachineImage.latestAmazonLinux2023({ cpuType: cpuType ?? AmazonLinuxCpuType.X86_64, cachedInContext: cachedInContext ?? false }),
subnetSelection: subnetSelection ?? { subnetType: SubnetType.PUBLIC },
init: CloudFormationInit.fromElements(
// Configure IP forwarding
Expand Down
Loading

0 comments on commit 4363d90

Please sign in to comment.