From ea3d5e042503c5c3916f8f4f2a957766a88799e7 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 1 Jul 2022 15:39:50 +0100 Subject: [PATCH 1/4] change default aws linux instance type to t3.micro, reduce default template TTL --- cli/templatecreate.go | 2 +- examples/templates/aws-linux/main.tf | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/templatecreate.go b/cli/templatecreate.go index e7aad2d51305b..ec8d0e8e3db74 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 worksapces created from this template.") + cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 8*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/examples/templates/aws-linux/main.tf b/examples/templates/aws-linux/main.tf index 5377f2702d022..c5d3a85d0301f 100644 --- a/examples/templates/aws-linux/main.tf +++ b/examples/templates/aws-linux/main.tf @@ -130,7 +130,7 @@ EOT resource "aws_instance" "dev" { ami = data.aws_ami.ubuntu.id availability_zone = "${var.region}a" - instance_type = "t3.xlarge" + instance_type = "t3.micro" user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end tags = { From 9005e0df2f5ddb7f719d23728f358fc5ccc474e7 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 1 Jul 2022 16:43:08 +0100 Subject: [PATCH 2/4] Update cli/templatecreate.go --- cli/templatecreate.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/templatecreate.go b/cli/templatecreate.go index ec8d0e8e3db74..257c06d5cc2dc 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", "", 8*time.Hour, "Specify a maximum TTL for workspaces created from this template.") + cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 2*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") From b94a3ee2d821fe135f17f9aff089efe5c6aa2788 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 1 Jul 2022 22:43:02 +0100 Subject: [PATCH 3/4] - 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 257c06d5cc2dc..b3e8f6488e3af 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", "", 2*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 4c9739a70d267..ef4a07805a1a5 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 c5d3a85d0301f..058615251fb30 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 = "2C/1G: t3.micro" + validation { + condition = contains([ + "2C/1G: t3.micro", + "2C/2G: t3.small", + "2C/4G: t3.medium", + "2C/8G: t3.large", + "4C/16G: t3.xlarge", + "8C/32G: 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.micro" + instance_type = split(": ", "${var.instance_type}")[1] 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 9b82bbdad0dcc..fb5b45b65ee7e 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 = "2C/1G: t3.micro" + validation { + condition = contains([ + "2C/1G: t3.micro", + "2C/2G: t3.small", + "2C/4G: t3.medium", + "2C/8G: t3.large", + "4C/16G: t3.xlarge", + "8C/32G: 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 = split(": ", "${var.instance_type}")[1] count = 1 user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end From f4c0d93fa6a5590eed8d18d9d191c5f0ecae373d Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Tue, 12 Jul 2022 18:38:34 +0100 Subject: [PATCH 4/4] remove prefixes from instance types --- examples/templates/aws-linux/main.tf | 16 ++++++++-------- examples/templates/aws-windows/main.tf | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/templates/aws-linux/main.tf b/examples/templates/aws-linux/main.tf index 058615251fb30..31e1a36c8814c 100644 --- a/examples/templates/aws-linux/main.tf +++ b/examples/templates/aws-linux/main.tf @@ -38,15 +38,15 @@ variable "region" { variable "instance_type" { description = "What instance type should your workspace use?" - default = "2C/1G: t3.micro" + default = "t3.micro" validation { condition = contains([ - "2C/1G: t3.micro", - "2C/2G: t3.small", - "2C/4G: t3.medium", - "2C/8G: t3.large", - "4C/16G: t3.xlarge", - "8C/32G: t3.2xlarge", + "t3.micro", + "t3.small", + "t3.medium", + "t3.large", + "t3.xlarge", + "t3.2xlarge", ], var.instance_type) error_message = "Invalid instance type!" } @@ -146,7 +146,7 @@ EOT resource "aws_instance" "dev" { ami = data.aws_ami.ubuntu.id availability_zone = "${var.region}a" - instance_type = split(": ", "${var.instance_type}")[1] + 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 fb5b45b65ee7e..8ab300e39ee04 100644 --- a/examples/templates/aws-windows/main.tf +++ b/examples/templates/aws-windows/main.tf @@ -38,15 +38,15 @@ variable "region" { variable "instance_type" { description = "What instance type should your workspace use?" - default = "2C/1G: t3.micro" + default = "t3.micro" validation { condition = contains([ - "2C/1G: t3.micro", - "2C/2G: t3.small", - "2C/4G: t3.medium", - "2C/8G: t3.large", - "4C/16G: t3.xlarge", - "8C/32G: t3.2xlarge", + "t3.micro", + "t3.small", + "t3.medium", + "t3.large", + "t3.xlarge", + "t3.2xlarge", ], var.instance_type) error_message = "Invalid instance type!" } @@ -99,7 +99,7 @@ EOT resource "aws_instance" "dev" { ami = data.aws_ami.windows.id availability_zone = "${var.region}a" - instance_type = split(": ", "${var.instance_type}")[1] + instance_type = "${var.instance_type}" count = 1 user_data = data.coder_workspace.me.transition == "start" ? local.user_data_start : local.user_data_end