From e3c66ca15dca8bb6cb84e87bb54536c3ceefc890 Mon Sep 17 00:00:00 2001 From: hezijie Date: Mon, 29 Aug 2022 17:03:29 +0800 Subject: [PATCH] Sort all variables, outputs, arguments and blocks in resource block. Adjust code file's style. Add `numeric = false` for `random_string.name` in `201-mysql-fs-db` module as the name is used as `azurerm_mysql_flexible_server.default`'s `administrator_login` and the login name doesn't support a name start with number. Add minimum constraints for `random_password.password` in `201-mysql-fs-db` module as the password required a minimum complexity. --- quickstart/101-attestation-provider/main.tf | 9 ++- .../101-attestation-provider/outputs.tf | 2 +- .../101-attestation-provider/providers.tf | 3 +- .../101-attestation-provider/variables.tf | 18 ++--- quickstart/101-resource-group/main.tf | 4 +- quickstart/101-resource-group/providers.tf | 3 +- quickstart/101-resource-group/variables.tf | 10 +-- .../201-k8s-cluster-with-tf-and-aks/main.tf | 38 +++++----- .../outputs.tf | 27 ++++--- .../providers.tf | 1 - .../terraform.tfvars | 3 +- .../variables.tf | 72 +++++++++---------- quickstart/201-mysql-fs-db/main.tf | 51 ++++++------- quickstart/201-mysql-fs-db/mysql-fs-db.tf | 4 +- quickstart/201-mysql-fs-db/outputs.tf | 8 +-- quickstart/201-mysql-fs-db/providers.tf | 2 +- quickstart/201-mysql-fs-db/variables.tf | 10 +-- 17 files changed, 128 insertions(+), 137 deletions(-) diff --git a/quickstart/101-attestation-provider/main.tf b/quickstart/101-attestation-provider/main.tf index 36091ab7..fc2fd724 100644 --- a/quickstart/101-attestation-provider/main.tf +++ b/quickstart/101-attestation-provider/main.tf @@ -3,14 +3,13 @@ resource "random_pet" "rg_name" { } resource "azurerm_resource_group" "rg" { - name = random_pet.rg_name.id location = var.resource_group_location + name = random_pet.rg_name.id } resource "azurerm_attestation_provider" "corp_attestation" { - name = var.attestation_provider_name - resource_group_name = azurerm_resource_group.rg.name - location = azurerm_resource_group.rg.location - + location = azurerm_resource_group.rg.location + name = var.attestation_provider_name + resource_group_name = azurerm_resource_group.rg.name policy_signing_certificate_data = file(var.policy_file) } \ No newline at end of file diff --git a/quickstart/101-attestation-provider/outputs.tf b/quickstart/101-attestation-provider/outputs.tf index 62816bd7..c765da63 100644 --- a/quickstart/101-attestation-provider/outputs.tf +++ b/quickstart/101-attestation-provider/outputs.tf @@ -1,3 +1,3 @@ output "resource_group_name" { value = azurerm_resource_group.rg.name -} +} \ No newline at end of file diff --git a/quickstart/101-attestation-provider/providers.tf b/quickstart/101-attestation-provider/providers.tf index ba3e0dc7..5343d826 100644 --- a/quickstart/101-attestation-provider/providers.tf +++ b/quickstart/101-attestation-provider/providers.tf @@ -6,7 +6,6 @@ terraform { source = "hashicorp/azurerm" version = "~>2.0" } - random = { source = "hashicorp/random" version = "~>3.0" @@ -16,4 +15,4 @@ terraform { provider "azurerm" { features {} -} +} \ No newline at end of file diff --git a/quickstart/101-attestation-provider/variables.tf b/quickstart/101-attestation-provider/variables.tf index 7c14fc2b..d10d70d2 100644 --- a/quickstart/101-attestation-provider/variables.tf +++ b/quickstart/101-attestation-provider/variables.tf @@ -1,6 +1,9 @@ -variable "resource_group_name_prefix" { - default = "rg" - description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +variable "attestation_provider_name" { + default = "attestationprovider007" +} + +variable "policy_file" { + default = "~/.certs/cert.pem" } variable "resource_group_location" { @@ -8,10 +11,7 @@ variable "resource_group_location" { description = "Location of the resource group." } -variable "policy_file" { - default = "~/.certs/cert.pem" -} - -variable "attestation_provider_name" { - default = "attestationprovider007" +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." } \ No newline at end of file diff --git a/quickstart/101-resource-group/main.tf b/quickstart/101-resource-group/main.tf index b312f1af..ab4f9a5e 100644 --- a/quickstart/101-resource-group/main.tf +++ b/quickstart/101-resource-group/main.tf @@ -3,6 +3,6 @@ resource "random_pet" "rg_name" { } resource "azurerm_resource_group" "rg" { - name = random_pet.rg_name.id location = var.resource_group_location -} + name = random_pet.rg_name.id +} \ No newline at end of file diff --git a/quickstart/101-resource-group/providers.tf b/quickstart/101-resource-group/providers.tf index ba3e0dc7..5343d826 100644 --- a/quickstart/101-resource-group/providers.tf +++ b/quickstart/101-resource-group/providers.tf @@ -6,7 +6,6 @@ terraform { source = "hashicorp/azurerm" version = "~>2.0" } - random = { source = "hashicorp/random" version = "~>3.0" @@ -16,4 +15,4 @@ terraform { provider "azurerm" { features {} -} +} \ No newline at end of file diff --git a/quickstart/101-resource-group/variables.tf b/quickstart/101-resource-group/variables.tf index 19f4680c..e8396125 100644 --- a/quickstart/101-resource-group/variables.tf +++ b/quickstart/101-resource-group/variables.tf @@ -1,9 +1,9 @@ -variable "resource_group_name_prefix" { - default = "rg" - description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." -} - variable "resource_group_location" { default = "eastus" description = "Location of the resource group." } + +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} \ No newline at end of file diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf index bace6bb2..0069ac6f 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf @@ -4,8 +4,8 @@ resource "random_pet" "rg_name" { } resource "azurerm_resource_group" "rg" { - name = random_pet.rg_name.id location = var.resource_group_location + name = random_pet.rg_name.id } resource "random_id" "log_analytics_workspace_name_suffix" { @@ -13,32 +13,40 @@ resource "random_id" "log_analytics_workspace_name_suffix" { } resource "azurerm_log_analytics_workspace" "test" { + location = var.log_analytics_workspace_location # The WorkSpace name has to be unique across the whole of azure, not just the current subscription/tenant. name = "${var.log_analytics_workspace_name}-${random_id.log_analytics_workspace_name_suffix.dec}" - location = var.log_analytics_workspace_location resource_group_name = azurerm_resource_group.rg.name sku = var.log_analytics_workspace_sku } resource "azurerm_log_analytics_solution" "test" { - solution_name = "ContainerInsights" location = azurerm_log_analytics_workspace.test.location resource_group_name = azurerm_resource_group.rg.name - workspace_resource_id = azurerm_log_analytics_workspace.test.id + solution_name = "ContainerInsights" workspace_name = azurerm_log_analytics_workspace.test.name + workspace_resource_id = azurerm_log_analytics_workspace.test.id plan { - publisher = "Microsoft" product = "OMSGallery/ContainerInsights" + publisher = "Microsoft" } } resource "azurerm_kubernetes_cluster" "k8s" { - name = var.cluster_name location = azurerm_resource_group.rg.location + name = var.cluster_name resource_group_name = azurerm_resource_group.rg.name dns_prefix = var.dns_prefix + tags = { + Environment = "Development" + } + default_node_pool { + name = "agentpool" + vm_size = "Standard_D2_v2" + node_count = var.agent_count + } linux_profile { admin_username = "ubuntu" @@ -46,24 +54,12 @@ resource "azurerm_kubernetes_cluster" "k8s" { key_data = file(var.ssh_public_key) } } - - default_node_pool { - name = "agentpool" - node_count = var.agent_count - vm_size = "Standard_D2_v2" + network_profile { + network_plugin = "kubenet" + load_balancer_sku = "standard" } - service_principal { client_id = var.aks_service_principal_app_id client_secret = var.aks_service_principal_client_secret } - - network_profile { - load_balancer_sku = "standard" - network_plugin = "kubenet" - } - - tags = { - Environment = "Development" - } } diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf index e9d185bf..b41d7ae1 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/outputs.tf @@ -1,5 +1,6 @@ -output "resource_group_name" { - value = azurerm_resource_group.rg.name +output "client_certificate" { + value = azurerm_kubernetes_cluster.k8s.kube_config[0].client_certificate + sensitive = true } output "client_key" { @@ -7,23 +8,23 @@ output "client_key" { sensitive = true } -output "client_certificate" { - value = azurerm_kubernetes_cluster.k8s.kube_config[0].client_certificate - sensitive = true -} - output "cluster_ca_certificate" { value = azurerm_kubernetes_cluster.k8s.kube_config[0].cluster_ca_certificate sensitive = true } +output "cluster_password" { + value = azurerm_kubernetes_cluster.k8s.kube_config[0].password + sensitive = true +} + output "cluster_username" { value = azurerm_kubernetes_cluster.k8s.kube_config[0].username sensitive = true } -output "cluster_password" { - value = azurerm_kubernetes_cluster.k8s.kube_config[0].password +output "host" { + value = azurerm_kubernetes_cluster.k8s.kube_config[0].host sensitive = true } @@ -32,8 +33,6 @@ output "kube_config" { sensitive = true } -output "host" { - value = azurerm_kubernetes_cluster.k8s.kube_config[0].host - sensitive = true -} - \ No newline at end of file +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} \ No newline at end of file diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf index 0d51fc35..74dc62e1 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/providers.tf @@ -6,7 +6,6 @@ terraform { source = "hashicorp/azurerm" version = "~>3.0" } - random = { source = "hashicorp/random" version = "~>3.0" diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars b/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars index 5c82a505..866eb921 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/terraform.tfvars @@ -1,3 +1,2 @@ aks_service_principal_app_id = "" - -aks_service_principal_client_secret = "" +aks_service_principal_client_secret = "" \ No newline at end of file diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf index 61a5f3f6..c90da17d 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/variables.tf @@ -1,43 +1,7 @@ -variable "resource_group_name_prefix" { - default = "rg" - description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." -} - -variable "resource_group_location" { - default = "eastus" - description = "Location of the resource group." -} - variable "agent_count" { default = 3 } -variable "ssh_public_key" { - default = "~/.ssh/id_rsa.pub" -} - -variable "dns_prefix" { - default = "k8stest" -} - -variable "cluster_name" { - default = "k8stest" -} - -variable "log_analytics_workspace_name" { - default = "testLogAnalyticsWorkspaceName" -} - -# Refer to https://azure.microsoft.com/global-infrastructure/services/?products=monitor for available Log Analytics regions. -variable "log_analytics_workspace_location" { - default = "eastus" -} - -# Refer to https://azure.microsoft.com/pricing/details/monitor/ for Log Analytics pricing -variable "log_analytics_workspace_sku" { - default = "PerGB2018" -} - # The following two variable declarations are placeholder references. # Set the values for these variable in terraform.tfvars variable "aks_service_principal_app_id" { @@ -47,3 +11,39 @@ variable "aks_service_principal_app_id" { variable "aks_service_principal_client_secret" { default = "" } + +variable "cluster_name" { + default = "k8stest" +} + +variable "dns_prefix" { + default = "k8stest" +} + +# Refer to https://azure.microsoft.com/global-infrastructure/services/?products=monitor for available Log Analytics regions. +variable "log_analytics_workspace_location" { + default = "eastus" +} + +variable "log_analytics_workspace_name" { + default = "testLogAnalyticsWorkspaceName" +} + +# Refer to https://azure.microsoft.com/pricing/details/monitor/ for Log Analytics pricing +variable "log_analytics_workspace_sku" { + default = "PerGB2018" +} + +variable "resource_group_location" { + default = "eastus" + description = "Location of the resource group." +} + +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "ssh_public_key" { + default = "~/.ssh/id_rsa.pub" +} diff --git a/quickstart/201-mysql-fs-db/main.tf b/quickstart/201-mysql-fs-db/main.tf index 9f6c3960..6d6a1238 100644 --- a/quickstart/201-mysql-fs-db/main.tf +++ b/quickstart/201-mysql-fs-db/main.tf @@ -4,50 +4,54 @@ resource "random_pet" "rg_name" { } resource "azurerm_resource_group" "rg" { - name = random_pet.rg_name.id location = var.resource_group_location + name = random_pet.rg_name.id } # Generate random value for the name resource "random_string" "name" { length = 8 - upper = false lower = true + numeric = false special = false + upper = false } # Generate random value for the login password resource "random_password" "password" { length = 8 - upper = true lower = true - special = true - numeric = false + min_lower = 1 + min_numeric = 1 + min_special = 1 + min_upper = 1 + numeric = true override_special = "_" + special = true + upper = true } # Manages the Virtual Network resource "azurerm_virtual_network" "default" { - name = "vnet-${random_string.name.result}" - location = azurerm_resource_group.rg.location - resource_group_name = azurerm_resource_group.rg.name address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.rg.location + name = "vnet-${random_string.name.result}" + resource_group_name = azurerm_resource_group.rg.name } # Manages the Subnet resource "azurerm_subnet" "default" { + address_prefixes = ["10.0.2.0/24"] name = "subnet-${random_string.name.result}" resource_group_name = azurerm_resource_group.rg.name virtual_network_name = azurerm_virtual_network.default.name - address_prefixes = ["10.0.2.0/24"] service_endpoints = ["Microsoft.Storage"] delegation { name = "fs" service_delegation { - name = "Microsoft.DBforMySQL/flexibleServers" - + name = "Microsoft.DBforMySQL/flexibleServers" actions = [ "Microsoft.Network/virtualNetworks/subnets/join/action", ] @@ -65,41 +69,38 @@ resource "azurerm_private_dns_zone" "default" { resource "azurerm_private_dns_zone_virtual_network_link" "default" { name = "mysqlfsVnetZone${random_string.name.result}.com" private_dns_zone_name = azurerm_private_dns_zone.default.name - virtual_network_id = azurerm_virtual_network.default.id resource_group_name = azurerm_resource_group.rg.name + virtual_network_id = azurerm_virtual_network.default.id } # Manages the MySQL Flexible Server resource "azurerm_mysql_flexible_server" "default" { + location = azurerm_resource_group.rg.location name = "mysqlfs-${random_string.name.result}" resource_group_name = azurerm_resource_group.rg.name - location = azurerm_resource_group.rg.location administrator_login = random_string.name.result administrator_password = random_password.password.result - zone = "1" - version = "8.0.21" backup_retention_days = 7 + delegated_subnet_id = azurerm_subnet.default.id geo_redundant_backup_enabled = false - - storage { - size_gb = 20 - iops = 360 - } - - delegated_subnet_id = azurerm_subnet.default.id - private_dns_zone_id = azurerm_private_dns_zone.default.id - sku_name = "GP_Standard_D2ds_v4" + private_dns_zone_id = azurerm_private_dns_zone.default.id + sku_name = "GP_Standard_D2ds_v4" + version = "8.0.21" + zone = "1" high_availability { mode = "ZoneRedundant" standby_availability_zone = "2" } - maintenance_window { day_of_week = 0 start_hour = 8 start_minute = 0 } + storage { + iops = 360 + size_gb = 20 + } depends_on = [azurerm_private_dns_zone_virtual_network_link.default] } diff --git a/quickstart/201-mysql-fs-db/mysql-fs-db.tf b/quickstart/201-mysql-fs-db/mysql-fs-db.tf index 51598667..4ed02a76 100644 --- a/quickstart/201-mysql-fs-db/mysql-fs-db.tf +++ b/quickstart/201-mysql-fs-db/mysql-fs-db.tf @@ -1,8 +1,8 @@ # Manages the MySQL Flexible Server Database resource "azurerm_mysql_flexible_database" "default" { + charset = "utf8" + collation = "utf8_unicode_ci" name = "mysqlfsdb_${random_string.name.result}" resource_group_name = azurerm_resource_group.rg.name server_name = azurerm_mysql_flexible_server.default.name - charset = "utf8" - collation = "utf8_unicode_ci" } diff --git a/quickstart/201-mysql-fs-db/outputs.tf b/quickstart/201-mysql-fs-db/outputs.tf index dca1b176..74fb49c0 100644 --- a/quickstart/201-mysql-fs-db/outputs.tf +++ b/quickstart/201-mysql-fs-db/outputs.tf @@ -1,7 +1,3 @@ -output "resource_group_name" { - value = azurerm_resource_group.rg.name -} - output "azurerm_mysql_flexible_server" { value = azurerm_mysql_flexible_server.default.name } @@ -9,3 +5,7 @@ output "azurerm_mysql_flexible_server" { output "mysql_flexible_server_database_name" { value = azurerm_mysql_flexible_database.default.name } + +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} \ No newline at end of file diff --git a/quickstart/201-mysql-fs-db/providers.tf b/quickstart/201-mysql-fs-db/providers.tf index 0d51fc35..31d1f491 100644 --- a/quickstart/201-mysql-fs-db/providers.tf +++ b/quickstart/201-mysql-fs-db/providers.tf @@ -16,4 +16,4 @@ terraform { provider "azurerm" { features {} -} +} \ No newline at end of file diff --git a/quickstart/201-mysql-fs-db/variables.tf b/quickstart/201-mysql-fs-db/variables.tf index 19f4680c..e8396125 100644 --- a/quickstart/201-mysql-fs-db/variables.tf +++ b/quickstart/201-mysql-fs-db/variables.tf @@ -1,9 +1,9 @@ -variable "resource_group_name_prefix" { - default = "rg" - description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." -} - variable "resource_group_location" { default = "eastus" description = "Location of the resource group." } + +variable "resource_group_name_prefix" { + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} \ No newline at end of file