From 6c3b09d2a0488223ebb276f536eb93a08478ee2c Mon Sep 17 00:00:00 2001 From: Chris Ball <39441998+chrisba11@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:37:17 -0800 Subject: [PATCH] adds examples and updates README to reflect actual --- README.md | 12 +++++--- _example/aws/lambda.md | 12 ++++---- _example/azure/.gitkeep | 0 _example/azure/vnet.md | 61 +++++++++++++++++++++++++++++++++++++++++ _example/gcp/.gitkeep | 0 _example/gcp/lb.md | 54 ++++++++++++++++++++++++++++++++++++ 6 files changed, 129 insertions(+), 10 deletions(-) delete mode 100644 _example/azure/.gitkeep create mode 100644 _example/azure/vnet.md delete mode 100644 _example/gcp/.gitkeep create mode 100644 _example/gcp/lb.md diff --git a/README.md b/README.md index 2487d98..33731ea 100644 --- a/README.md +++ b/README.md @@ -48,19 +48,23 @@ Getting started with fusion is as simple as naming the type of cloud resource yo See available commands with `--help` ``` -fusion —help +fusion —-help Usage: fusion Generate secure by default cloud infrastructure configuration Flags: - -h, --help Show context-sensitive help. - -v, --verbose Enable verbose logging - -n, --no-color Disable colorful output ($NO_COLOR) + -h, --help Show context-sensitive help. + --version Show version information + -v, --verbose Enable verbose logging + -n, --no-color Disable colorful output ($NO_COLOR) + --no-format Disable code formatting ($NO_FORMAT) + --config=CONFIG-FLAG Provide a JSON file which will populate flags and their values Commands: new Create new cloud resources with Terraform + gen Generate snippets and shell completions Run "fusion --help" for more information on a command. ``` diff --git a/_example/aws/lambda.md b/_example/aws/lambda.md index 0233292..e4d0e1f 100644 --- a/_example/aws/lambda.md +++ b/_example/aws/lambda.md @@ -7,7 +7,7 @@ ```shell # Create a new default lambda -fusion new aws lambda +fusion new aws resource lambda ``` ## Output @@ -34,13 +34,13 @@ EOF } resource "aws_lambda_function" "my_lambda" { - filename = "foo.zip" - function_name = "MyLambda" + filename = "my_lambda.zip" + function_name = "my_lambda" role = aws_iam_role.iam_for_lambda.arn - handler = "handler.index" - source_code_hash = filebase64sha256("foo.zip") + handler = "handler.index.js" + source_code_hash = filebase64sha256("my_lambda.zip") - runtime = "NODE_14.x" + runtime = "nodejs14.x" environment { variables = {} diff --git a/_example/azure/.gitkeep b/_example/azure/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/_example/azure/vnet.md b/_example/azure/vnet.md new file mode 100644 index 0000000..e6f3090 --- /dev/null +++ b/_example/azure/vnet.md @@ -0,0 +1,61 @@ +# Example - Create a vnet + +> Create a new azure virtual network + + +## Command + +```shell +# Create a new default vnet +fusion new azure vnet +``` + +## Output + +```json +resource "azurerm_resource_group" "this" { + name = "resource_group_name" + location = "centralus" +} + +resource "azurerm_virtual_network" "this" { + name = "vnet_name" + resource_group_name = azurerm_resource_group.this.name + location = azurerm_resource_group.this.location + address_space = ["0.0.0.0/0"] +} + +resource "azurerm_subnet" "this" { + for_each = { for subnet in var.virtual_network_settings.subnets : subnet.name => subnet } + name = each.value["name"] + resource_group_name = azurerm_resource_group.this.name + virtual_network_name = azurerm_virtual_network.this.name + address_prefixes = [each.value["cidr_block"]] + dynamic "delegation" { + for_each = each.value.delegation_name != null ? [1] : [] + content { + name = each.value.delegation_name + service_delegation { + name = each.value.service_delegation_name + } + } + } +} + +## The following variable should be separated out into a different file (ex. variables.tf) +variable "virtual_network_settings" { + description = "An object map of lists that contains the network CIDR block, and subnets" + type = object({ + address_space = list(string) + subnets = list( + object({ + name = string + cidr_block = string + security_group = string + delegation_name = string + service_delegation_name = string + }) + ) + }) +} +``` diff --git a/_example/gcp/.gitkeep b/_example/gcp/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/_example/gcp/lb.md b/_example/gcp/lb.md new file mode 100644 index 0000000..ff15d1c --- /dev/null +++ b/_example/gcp/lb.md @@ -0,0 +1,54 @@ +# Example - Create a load-balancer + +> Create a new gcp load-balancer + + +## Command + +```shell +# Create a new default load-balancer +fusion new gcp lb +``` + +## Output + +```json +resource "google_compute_forwarding_rule" "default" { + name = "internal-loadbalancer" + region = "us-central1" + + load_balancing_scheme = "INTERNAL" + backend_service = google_compute_region_backend_service.backend.id + all_ports = true + network = google_compute_network.default.name + subnetwork = google_compute_subnetwork.default.name +} + +resource "google_compute_region_backend_service" "backend" { + name = "backend_service" + region = "us-central1" + health_checks = [google_compute_health_check.hc.id] +} + +resource "google_compute_health_check" "hc" { + name = "health_check" + check_interval_sec = 1 + timeout_sec = 1 + + tcp_health_check { + port = "80" + } +} + +resource "google_compute_network" "default" { + name = "network" + auto_create_subnetworks = false +} + +resource "google_compute_subnetwork" "default" { + name = "subnet" + ip_cidr_range = "0.0.0.0/0" + region = "us-central1" + network = google_compute_network.default.id +} +```