Skip to content

Commit b5c4f6e

Browse files
committed
naming conventions
1 parent c17b6bc commit b5c4f6e

File tree

4 files changed

+38
-66
lines changed

4 files changed

+38
-66
lines changed

.terraform.lock.hcl

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ and this project adheres to [Semantic Versioning v2.0.0](https://semver.org/spec
2323
- Add default values to tf variables
2424
- Fix encoding script
2525
- Add public key and password files mocks CI
26+
- Adopt naming conventions
27+
- Utilize azure naming module for terraform

README.md

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Includes pre-commit hooks that lint the terraform code and generate module's
55
documentation as part of README file.
66
Contains examples of terraform CI/CD pipelines for GitHub Actions and Azure Pipelines.
77

8+
## Azure naming conventions
9+
10+
- [Define your naming convention](https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-naming)
11+
- [Azure naming module](https://registry.terraform.io/modules/Azure/naming/azurerm/latest)
12+
813
## Terraform Init
914

1015
- Create and configure Azure Storage Account for Terraform state
@@ -19,8 +24,9 @@ Contains examples of terraform CI/CD pipelines for GitHub Actions and Azure Pipe
1924

2025
## Module referencing
2126

22-
- Bitbucket: `git::git@bitbucket.org:kolosovpetro/terraform.git//modules/storage`
23-
- Github: `git::git@github.com:kolosovpetro/terraform.git//modules/storage`
27+
- Bitbucket SSH: `git::git@bitbucket.org:kolosovpetro/terraform.git//modules/storage`
28+
- Github SSH: `git::git@github.com:kolosovpetro/terraform.git//modules/storage`
29+
- Github HTTP: `github.com/kolosovpetro/AzureLinuxVMTerraform.git//modules/ubuntu-vm-key-auth-no-pip?ref=master`
2430

2531
## Pre-commit configuration
2632

@@ -46,57 +52,6 @@ Contains examples of terraform CI/CD pipelines for GitHub Actions and Azure Pipe
4652
- https://terraform-docs.io/user-guide/installation/
4753
- https://pre-commit.com/
4854

49-
## Storage account configuration file
50-
51-
```bash
52-
storage_account_name = "storage_account_name"
53-
container_name = "container_name"
54-
key = "terraform.tfstate"
55-
sas_token = "sas_token"
56-
```
57-
5855
## Deploy storage account for terraform state
5956

6057
- See [CreateAzureStorageAccount.ps1](./CreateAzureStorageAccount.ps1)
61-
62-
# Module documentation
63-
64-
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
65-
66-
## Requirements
67-
68-
| Name | Version |
69-
|---------------------------------------------------------------------|---------|
70-
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | =3.71.0 |
71-
72-
## Providers
73-
74-
| Name | Version |
75-
|---------------------------------------------------------------|---------|
76-
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.71.0 |
77-
78-
## Modules
79-
80-
| Name | Source | Version |
81-
|----------------------------------------------------------------------------------|-----------------------------|---------|
82-
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | ./modules/example_submodule | n/a |
83-
84-
## Resources
85-
86-
| Name | Type |
87-
|-----------------------------------------------------------------------------------------------------------------------------------|-------------|
88-
| [azurerm_resource_group.public](https://registry.terraform.io/providers/hashicorp/azurerm/3.71.0/docs/resources/resource_group) | resource |
89-
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.71.0/docs/data-sources/client_config) | data source |
90-
91-
## Inputs
92-
93-
| Name | Description | Type | Default | Required |
94-
|-------------------------------------------------------------------------------------------------------------|--------------------------|----------|---------|:--------:|
95-
| <a name="input_prefix"></a> [prefix](#input\_prefix) | Prefix for all resources | `string` | n/a | yes |
96-
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Resource group location | `string` | n/a | yes |
97-
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | Resource group name | `string` | n/a | yes |
98-
99-
## Outputs
100-
101-
No outputs.
102-
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

main.tf

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
data "azurerm_client_config" "current" {}
22
data "azurerm_subscription" "current" {}
33

4+
module "naming" {
5+
source = "Azure/naming/azurerm"
6+
suffix = ["template", var.prefix]
7+
}
8+
49
#################################################################################################################
510
# LOCALS
611
#################################################################################################################
@@ -18,7 +23,7 @@ locals {
1823

1924
resource "azurerm_resource_group" "public" {
2025
location = var.location
21-
name = "rg-tf-template-${var.prefix}"
26+
name = module.naming.resource_group.name_unique
2227
tags = var.tags
2328
}
2429

@@ -27,14 +32,14 @@ resource "azurerm_resource_group" "public" {
2732
#################################################################################################################
2833

2934
resource "azurerm_virtual_network" "public" {
30-
name = "vnet-${var.prefix}"
35+
name = module.naming.virtual_network.name
3136
address_space = local.vnet_cidr
3237
location = azurerm_resource_group.public.location
3338
resource_group_name = azurerm_resource_group.public.name
3439
}
3540

3641
resource "azurerm_subnet" "vm" {
37-
name = "snet-vm-${var.prefix}"
42+
name = module.naming.subnet.name_unique
3843
resource_group_name = azurerm_resource_group.public.name
3944
virtual_network_name = azurerm_virtual_network.public.name
4045
address_prefixes = local.vm_subnet_cidr
@@ -53,13 +58,3 @@ resource "azurerm_subnet" "bastion_snet" {
5358
virtual_network_name = azurerm_virtual_network.public.name
5459
address_prefixes = local.bastion_subnet_cidr
5560
}
56-
57-
#################################################################################################################
58-
# MODULE CALL EXAMPLE
59-
#################################################################################################################
60-
61-
module "resource_group" {
62-
source = "./modules/module"
63-
resource_group_location = var.location
64-
resource_group_name = "rg-from-module-${var.prefix}"
65-
}

0 commit comments

Comments
 (0)