diff --git a/.github/workflows/tfchecks.yml b/.github/workflows/tfchecks.yml index 9b2875c..96810d4 100644 --- a/.github/workflows/tfchecks.yml +++ b/.github/workflows/tfchecks.yml @@ -5,7 +5,12 @@ on: pull_request: workflow_dispatch: jobs: - tf-checks-example: + tf-checks-basic-example: uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@1.2.2 with: - working_directory: './_example/' \ No newline at end of file + working_directory: './example/basic' + + tf-checks-complete-example: + uses: clouddrove/github-shared-workflows/.github/workflows/tf-checks.yml@1.2.2 + with: + working_directory: './example/complete' \ No newline at end of file diff --git a/README.yaml b/README.yaml index 21316a4..9c58a0f 100644 --- a/README.yaml +++ b/README.yaml @@ -5,7 +5,7 @@ # # Name of this project -name : Terraform gcp subnet +name : Terraform GCP Subnet # License of this project license: "APACHE" @@ -15,18 +15,28 @@ github_repo: clouddrove/terraform-gcp-subnet # Badges to display badges: - - name: "Terraform" - image: "https://img.shields.io/badge/Terraform-v1.1.7-green" - url: "https://www.terraform.io" - - name: "Licence" - image: "https://img.shields.io/badge/License-APACHE-blue.svg" - url: "LICENSE.md" + - name: "Latest Release" + image: "https://img.shields.io/github/release/clouddrove/terraform-gcp-subnet.svg" + url: "https://github.com/clouddrove/terraform-gcp-subnet/releases/latest" - name: "tfsec" image: "https://github.com/clouddrove/terraform-gcp-subnet/actions/workflows/tfsec.yml/badge.svg" url: "https://github.com/clouddrove/terraform-gcp-subnet/actions/workflows/tfsec.yml" - - name: "static-checks" - image: "https://github.com/clouddrove/terraform-gcp-subnet/actions/workflows/terraform.yml/badge.svg" - url: "https://github.com/clouddrove/terraform-gcp-subnet/actions/workflows/terraform.yml" + - name: "Licence" + image: "https://img.shields.io/badge/License-APACHE-blue.svg" + url: "LICENSE.md" + - name: "Changelog" + image: "https://img.shields.io/badge/Changelog-blue" + url: "CHANGELOG.md" + +prerequesties: + - name: Terraform + url: https://learn.hashicorp.com/terraform/getting-started/install.html + version: ">= 1.4.6" + +providers: + - name: gcp + url: https://cloud.google.com/ + version: ">= 5.22.0" # description of this project description: |- diff --git a/_example/example.tf b/example/basic/example.tf similarity index 90% rename from _example/example.tf rename to example/basic/example.tf index f8305df..70b213f 100644 --- a/_example/example.tf +++ b/example/basic/example.tf @@ -9,14 +9,14 @@ module "vpc" { version = "1.0.0" name = "vpc" - environment = "test" + environment = "test-1" label_order = ["environment", "name"] google_compute_network_enabled = true } module "subnet" { - source = "../" + source = "../../" name = "dev" environment = var.environment @@ -31,7 +31,6 @@ module "subnet" { network = module.vpc.vpc_id project_id = "clouddrove" private_ip_google_access = true - allow = [{ "protocol" : "tcp", "ports" : ["1-65535"] }] source_ranges = ["10.10.0.0/16"] asn = 64514 nat_ip_allocate_option = "MANUAL_ONLY" @@ -51,4 +50,10 @@ module "subnet" { "ip_cidr_range" : "10.3.0.0/16" } ] + allow = [ + { + "protocol" : "tcp", + "ports" : ["1-65535"] + } + ] } diff --git a/_example/outputs.tf b/example/basic/outputs.tf similarity index 100% rename from _example/outputs.tf rename to example/basic/outputs.tf diff --git a/_example/varriables.tf b/example/basic/varriables.tf similarity index 100% rename from _example/varriables.tf rename to example/basic/varriables.tf diff --git a/_example/versions.tf b/example/basic/versions.tf similarity index 100% rename from _example/versions.tf rename to example/basic/versions.tf diff --git a/example/complete/example.tf b/example/complete/example.tf new file mode 100644 index 0000000..07f8f91 --- /dev/null +++ b/example/complete/example.tf @@ -0,0 +1,64 @@ +provider "google" { + project = var.gcp_project_id + region = var.gcp_region + zone = var.gcp_zone +} + +module "vpc" { + source = "clouddrove/vpc/gcp" + version = "1.0.0" + + name = "vpc" + environment = "test-1" + label_order = ["environment", "name"] + google_compute_network_enabled = true +} + + +module "subnet" { + source = "../../" + + name = "dev" + environment = var.environment + label_order = var.label_order + gcp_region = "us-central1" + + google_compute_subnetwork_enabled = true + google_compute_firewall_enabled = true + google_compute_router_nat_enabled = true + module_enabled = true + ipv6_access_type = "EXTERNAL" + network = module.vpc.vpc_id + project_id = "clouddrove" + private_ip_google_access = true + source_ranges = ["10.10.0.0/16"] + asn = 64514 + nat_ip_allocate_option = "MANUAL_ONLY" + source_subnetwork_ip_ranges_to_nat = "ALL_SUBNETWORKS_ALL_IP_RANGES" + filter = "ERRORS_ONLY" + dest_range = "0.0.0.0/0" + next_hop_gateway = "default-internet-gateway" + priority = 1000 + secondary_ip_ranges = [ + { + "range_name" : "services", + "ip_cidr_range" : "10.1.0.0/16" + }, + + { + "range_name" : "pods", + "ip_cidr_range" : "10.3.0.0/16" + } + ] + allow = [ + { + "protocol" : "tcp", + "ports" : ["1-65535"] + } + ] + log_config = { + aggregation_interval = "INTERVAL_15_MIN" + flow_sampling = 0 + metadata = "EXCLUDE_ALL_METADATA" + } +} diff --git a/example/complete/outputs.tf b/example/complete/outputs.tf new file mode 100644 index 0000000..1b01425 --- /dev/null +++ b/example/complete/outputs.tf @@ -0,0 +1,4 @@ +output "id" { + value = module.subnet[*].id + description = "The ID of the s3 bucket." +} \ No newline at end of file diff --git a/example/complete/varriables.tf b/example/complete/varriables.tf new file mode 100644 index 0000000..068d6c6 --- /dev/null +++ b/example/complete/varriables.tf @@ -0,0 +1,29 @@ +variable "environment" { + type = string + default = "subnetwork" + description = "Environment name" +} + +variable "label_order" { + type = list(any) + default = ["name", "environment"] + description = "Label order, e.g. `name`,`application`." +} + +variable "gcp_project_id" { + type = string + default = "clouddrove" + description = "Google Cloud project ID" +} + +variable "gcp_region" { + type = string + default = "europe-west3" + description = "Google Cloud region" +} + +variable "gcp_zone" { + type = string + default = "Europe-west3-c" + description = "Google Cloud zone" +} diff --git a/example/complete/versions.tf b/example/complete/versions.tf new file mode 100644 index 0000000..cf0d55e --- /dev/null +++ b/example/complete/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 0.14, < 2.0" + + required_providers { + google = { + source = "hashicorp/google" + version = ">= 3.50, < 5.0" + } + } +} \ No newline at end of file diff --git a/main.tf b/main.tf index 916c84d..7831685 100644 --- a/main.tf +++ b/main.tf @@ -32,11 +32,9 @@ resource "google_compute_subnetwork" "subnetwork" { for_each = var.log_config != null ? [var.log_config] : [] content { - aggregation_interval = try(log_config.value, "aggregation_interval", null) - flow_sampling = try(log_config.value, "flow_sampling", null) - metadata = try(log_config.value, "metadata", null) - metadata_fields = try(log_config.value, "metadata_fields", null) - filter_expr = try(log_config.value, "filter_expr", null) + aggregation_interval = log_config.value.aggregation_interval + flow_sampling = log_config.value.flow_sampling + metadata = log_config.value.metadata } } diff --git a/variables.tf b/variables.tf index dfbdc05..cbff942 100644 --- a/variables.tf +++ b/variables.tf @@ -46,9 +46,9 @@ variable "secondary_ip_ranges" { } variable "log_config" { - type = any - default = true - description = "(Optional) Logging options for the subnetwork flow logs. Setting this value to 'null' will disable them. See https://www.terraform.io/docs/providers/google/r/compute_subnetwork.html for more information and examples." + type = map(any) + default = null + description = "VPC flow logging options for this subnetwork" } variable "google_compute_subnetwork_enabled" { diff --git a/version.tf b/version.tf index 2d0541b..7344890 100644 --- a/version.tf +++ b/version.tf @@ -1,11 +1,11 @@ # Terraform version terraform { - required_version = ">= 1.6.6" + required_version = ">= 1.3" required_providers { google = { source = "hashicorp/google" - version = ">= 3.50, < 5.0" + version = ">= 4.64, < 6" } } } \ No newline at end of file