diff --git a/images/aws-c9-editor.png b/images/aws-c9-editor.png new file mode 100644 index 0000000..ba7dd71 Binary files /dev/null and b/images/aws-c9-editor.png differ diff --git a/modules/cloud9/README.md b/modules/cloud9/README.md new file mode 100644 index 0000000..629fea2 --- /dev/null +++ b/modules/cloud9/README.md @@ -0,0 +1,28 @@ +# AWS Cloud9 +[AWS Cloud9](https://aws.amazon.com/cloud9/) is a cloud-based integrated development environment (IDE) that lets you write, run, and debug your code with just a browser. It includes a code editor, debugger, and terminal. Cloud9 comes prepackaged with essential tools for popular programming languages, including JavaScript, Python, PHP, and more, so you don’t need to install files or configure your development machine to start new projects. Since your Cloud9 IDE is cloud-based, you can work on your projects from your office, home, or anywhere using an internet-connected machine. Cloud9 also provides a seamless experience for developing serverless applications enabling you to easily define resources, debug, and switch between local and remote execution of serverless applications. Fore more details, please refer to [this page](https://aws.amazon.com/cloud9/details/). + +![aws-c9-editor](../../images/aws-c9-editor.png) + +## Setup +### Prerequisites +This module requires *terraform*. If you don't have the terraform tool in your environment, go to the main [page](https://github.com/Young-ook/terraform-aws-ssm) of this repository and follow the installation instructions. + +### Quickstart +``` +module "vpc" { + source = "Young-ook/vpc/aws" +} + +module "cloud9" { + source = "Young-ook/ssm/aws//modules/cloud9" + subnet = values(module.vpc.subnets["public"])[0] +} +``` + +Run terraform: +``` +terraform init +terraform apply +``` + +# Additional Resources diff --git a/modules/cloud9/default.tf b/modules/cloud9/default.tf new file mode 100644 index 0000000..21b967f --- /dev/null +++ b/modules/cloud9/default.tf @@ -0,0 +1,13 @@ +### default values + +module "aws" { + source = "Young-ook/spinnaker/aws//modules/aws-partitions" +} + +locals { + default_workspace = { + instance_type = "t2.micro" + connection_type = "CONNECT_SSM" # allowed values: CONNECT_SSH, CONNECT_SSM + automatic_stop_time_minutes = 30 + } +} diff --git a/modules/cloud9/labels.tf b/modules/cloud9/labels.tf new file mode 100644 index 0000000..ecb496e --- /dev/null +++ b/modules/cloud9/labels.tf @@ -0,0 +1,14 @@ +### frigga name +module "frigga" { + source = "Young-ook/spinnaker/aws//modules/frigga" + version = "3.0.0" + name = var.name == null || var.name == "" ? "c9" : var.name + petname = var.name == null || var.name == "" ? true : false +} + +locals { + name = module.frigga.name + default-tags = merge( + { "terraform.io" = "managed" }, + ) +} diff --git a/modules/cloud9/main.tf b/modules/cloud9/main.tf new file mode 100644 index 0000000..7f5cd1e --- /dev/null +++ b/modules/cloud9/main.tf @@ -0,0 +1,16 @@ +### integrated development environment +resource "aws_cloud9_environment_ec2" "ide" { + name = local.name + tags = merge(local.default-tags, var.tags) + instance_type = lookup(var.workspace, "instance_type", local.default_workspace.instance_type) + automatic_stop_time_minutes = lookup(var.workspace, "automatic_stop_time_minutes", local.default_workspace.automatic_stop_time_minutes) + connection_type = lookup(var.workspace, "connection_type", local.default_workspace.connection_type) + subnet_id = var.subnet +} + +data "aws_instance" "ide" { + filter { + name = "tag:aws:cloud9:environment" + values = [aws_cloud9_environment_ec2.ide.id] + } +} diff --git a/modules/cloud9/outputs.tf b/modules/cloud9/outputs.tf new file mode 100644 index 0000000..45a119d --- /dev/null +++ b/modules/cloud9/outputs.tf @@ -0,0 +1,6 @@ +### output variables + +output "cloud9_url" { + description = "URL to open AWS Cloud9 IDE" + value = "https://${module.aws.region.name}.console.aws.amazon.com/cloud9/ide/${aws_cloud9_environment_ec2.ide.id}" +} diff --git a/modules/cloud9/tests/defaults/main.tf b/modules/cloud9/tests/defaults/main.tf new file mode 100644 index 0000000..1ac2892 --- /dev/null +++ b/modules/cloud9/tests/defaults/main.tf @@ -0,0 +1,17 @@ +terraform { + required_providers { + test = { + source = "terraform.io/builtin/test" + } + } +} + +module "vpc" { + source = "Young-ook/vpc/aws" + version = "1.0.5" +} + +module "main" { + source = "../.." + subnet = values(module.vpc.subnets["public"])[0] +} diff --git a/modules/cloud9/variables.tf b/modules/cloud9/variables.tf new file mode 100644 index 0000000..ac4002b --- /dev/null +++ b/modules/cloud9/variables.tf @@ -0,0 +1,26 @@ +### network +variable "subnet" { + description = "The subnet ID to deploy your cloud9 environment" + type = string + default = null +} + +### workspace +variable "workspace" { + description = "Cloud9 workspace configuration" + default = {} +} + +### description +variable "name" { + description = "Resource name of your cloud id environment" + type = string + default = null +} + +### tags +variable "tags" { + description = "The key-value maps for tagging" + type = map(string) + default = {} +} diff --git a/modules/cloud9/versions.tf b/modules/cloud9/versions.tf new file mode 100644 index 0000000..8a7f490 --- /dev/null +++ b/modules/cloud9/versions.tf @@ -0,0 +1,13 @@ +## requirements + +terraform { + # Terraform test is an experimental features introduced in Terraform CLI v0.15.0. + # So, you'll need to upgrade to v0.15.0 or later to use terraform test. + required_version = ">= 0.15" + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 4.0" + } + } +}