From 5e6320163d56eb15541abb260006ce88d07612d8 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 12 Jul 2022 19:37:59 +0100 Subject: [PATCH] change default aws linux instance type to t3.micro, reduce default template TTL (#2776) - make default template max TTL 24 hours (still less than 168) - make default workspace autostop 2 hours unless specified otherwise - add instance type selector to aws templates --- cli/templatecreate.go | 2 +- coderd/workspaces.go | 2 +- examples/templates/aws-linux/main.tf | 18 +++++++++++++++++- examples/templates/aws-windows/main.tf | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cli/templatecreate.go b/cli/templatecreate.go index e3ba05e9cb..65ca968c9a 100644 --- a/cli/templatecreate.go +++ b/cli/templatecreate.go @@ -127,7 +127,7 @@ func templateCreate() *cobra.Command { cmd.Flags().StringVarP(&directory, "directory", "d", currentDirectory, "Specify the directory to create from") cmd.Flags().StringVarP(&provisioner, "test.provisioner", "", "terraform", "Customize the provisioner backend") cmd.Flags().StringVarP(¶meterFile, "parameter-file", "", "", "Specify a file path with parameter values.") - cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 168*time.Hour, "Specify a maximum TTL for workspaces created from this template.") + cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 24*time.Hour, "Specify a maximum TTL for workspaces created from this template.") cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", time.Hour, "Specify a minimum autostart interval for workspaces created from this template.") // This is for testing! err := cmd.Flags().MarkHidden("test.provisioner") diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 4c9739a70d..ef4a07805a 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -32,7 +32,7 @@ import ( "github.com/coder/coder/codersdk" ) -const workspaceDefaultTTL = 12 * time.Hour +const workspaceDefaultTTL = 2 * time.Hour func (api *API) workspace(rw http.ResponseWriter, r *http.Request) { workspace := httpmw.WorkspaceParam(r) diff --git a/examples/templates/aws-linux/main.tf b/examples/templates/aws-linux/main.tf index 5377f2702d..31e1a36c88 100644 --- a/examples/templates/aws-linux/main.tf +++ b/examples/templates/aws-linux/main.tf @@ -36,6 +36,22 @@ variable "region" { } } +variable "instance_type" { + description = "What instance type should your workspace use?" + default = "t3.micro" + validation { + condition = contains([ + "t3.micro", + "t3.small", + "t3.medium", + "t3.large", + "t3.xlarge", + "t3.2xlarge", + ], var.instance_type) + error_message = "Invalid instance type!" + } +} + provider "aws" { region = var.region } @@ -130,7 +146,7 @@ EOT resource "aws_instance" "dev" { ami = data.aws_ami.ubuntu.id availability_zone = "${var.region}a" - instance_type = "t3.xlarge" + instance_type = "${var.instance_type}" user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end tags = { diff --git a/examples/templates/aws-windows/main.tf b/examples/templates/aws-windows/main.tf index 9b82bbdad0..8ab300e39e 100644 --- a/examples/templates/aws-windows/main.tf +++ b/examples/templates/aws-windows/main.tf @@ -36,6 +36,22 @@ variable "region" { } } +variable "instance_type" { + description = "What instance type should your workspace use?" + default = "t3.micro" + validation { + condition = contains([ + "t3.micro", + "t3.small", + "t3.medium", + "t3.large", + "t3.xlarge", + "t3.2xlarge", + ], var.instance_type) + error_message = "Invalid instance type!" + } +} + provider "aws" { region = var.region } @@ -83,7 +99,7 @@ EOT resource "aws_instance" "dev" { ami = data.aws_ami.windows.id availability_zone = "${var.region}a" - instance_type = "t3.micro" + instance_type = "${var.instance_type}" count = 1 user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end