Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorganization terraform module #3

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Maciej Michalski
Copyright (c) 2024 ThinkCube

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.15 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.3.0 |
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.4 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | 3.94.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.3.0 |
| <a name="provider_azurerm"></a> [azurerm](#provider\_azurerm) | 3.94.0 |

## Modules

Expand All @@ -20,9 +20,9 @@ No modules.

| Name | Type |
|------|------|
| [azurerm_container_registry.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/resources/container_registry) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.rg](https://registry.terraform.io/providers/hashicorp/azurerm/3.3.0/docs/data-sources/resource_group) | data source |
| [azurerm_container_registry.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/resources/container_registry) | resource |
| [azurerm_client_config.current](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/client_config) | data source |
| [azurerm_resource_group.main](https://registry.terraform.io/providers/hashicorp/azurerm/3.94.0/docs/data-sources/resource_group) | data source |

## Inputs

Expand All @@ -31,10 +31,11 @@ No modules.
| <a name="input_acr_admin_enabled"></a> [acr\_admin\_enabled](#input\_acr\_admin\_enabled) | Specifies whether the admin user is enabled. Defaults to false. | `string` | `"false"` | no |
| <a name="input_acr_name"></a> [acr\_name](#input\_acr\_name) | Specifies the name of the Container Registry. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_acr_tier"></a> [acr\_tier](#input\_acr\_tier) | The SKU name of the container registry. Possible values are Basic, Standard and Premium. Classic (which was previously Basic) is supported only for existing resources. | `string` | `"Basic"` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map` | n/a | yes |
| <a name="input_envirioment"></a> [envirioment](#input\_envirioment) | Specifies the name of the envirioment | `string` | n/a | yes |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | The location of the resource group in which to create the Container Registry. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the Container Registry. Changing this forces a new resource to be created. | `string` | n/a | yes |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A mapping of tags to assign to the resource. | `map(any)` | <pre>{<br> "ManagedByTerraform": "True"<br>}</pre> | no |
| <a name="input_environment"></a> [environment](#input\_environment) | Variable that defines the name of the environment. | `string` | `"dev"` | no |
| <a name="input_region"></a> [region](#input\_region) | Region in which resources are deployed. | `string` | `"weu"` | no |
| <a name="input_resource_group_location"></a> [resource\_group\_location](#input\_resource\_group\_location) | Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created. | `string` | `"West Europe"` | no |
| <a name="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name) | The name of the resource group in which to create the container registry component. Changing this forces a new resource to be created. | `string` | n/a | yes |

## Outputs

Expand Down
13 changes: 6 additions & 7 deletions acr.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
resource "azurerm_container_registry" "main" {
name = "${var.envirioment}${var.acr_name}"
resource_group_name = "${data.azurerm_resource_group.rg.name}"
location = "${data.azurerm_resource_group.rg.location}"
sku = "${var.acr_tier}"
admin_enabled = "${var.acr_admin_enabled}"

tags = "${var.default_tags}"
name = "${var.environment}${var.acr_name}"
resource_group_name = data.azurerm_resource_group.rg.name
location = data.azurerm_resource_group.rg.location
sku = var.acr_tier
admin_enabled = var.acr_admin_enabled
tags = var.default_tags
}
8 changes: 4 additions & 4 deletions backend.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.3.0"
source = "hashicorp/azurerm"
version = "3.94.0"
}
}
required_version = ">= 0.15"
}
required_version = ">= 1.6.4"
}
61 changes: 44 additions & 17 deletions examples/azure_acr/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
## How to use
# Terraform Module: Azure Container Registry (ACR)

```
This Terraform module provisions an Azure Container Registry (ACR) in Azure.

## Usage

```hcl
provider "azurerm" {
features {}
}

module "acr" {
source = "spy86/acr/azure"
version = "1.0.4"

envirioment = "dev"
acr_name = "registry4test"
resource_group_name = "weu-test-rg"
module "container_registry" {
source = "Think-Cube/container-registry/azure"
version = "1.0.0"
envirioment = "dev"
acr_name = "registry4test"
resource_group_name = "weu-test-rg"
resource_group_location = "West Europe"
acr_tier = "Basic"
acr_admin_enabled = "true"

acr_tier = "Basic"
acr_admin_enabled = "true"
default_tags = {
Administrator = "Someone"
Department = "IT"
CostCentre = "ABC123"
ContactPerson = "Someone@example.com"
Administrator = "John Doe"
Department = "IT"
CostCentre = "CC123"
ContactPerson = "Jane Smith"
ManagedByTerraform = "True"
}
}
```
```

### Variables

* `environment`: The environment name (e.g., dev, stage, prod).
* `acr_name`: The name of the Azure Container Registry.
* `resource_group_name`: The name of the resource group in which to create the ACR.
* `resource_group_location`: The location of the resource group.
* `acr_tier`: The pricing tier for the ACR.
* `acr_admin_enabled`: Whether admin user should be enabled for the ACR.
* `default_tags`: Default tags to be applied to all resources.

### Outputs

* `id`: The ID of the Container Registry.
* `login_server`: The URL that can be used to log into the container registry.
* `admin_username`: The Username associated with the Container Registry Admin account.
* `admin_password`: The Password associated with the Container Registry Admin account.

## License

This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).

## Contribution

Feel free to contribute by opening issues or pull requests. Your feedback and improvements are highly appreciated!
13 changes: 6 additions & 7 deletions examples/azure_acr/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ features {}
}

module "acr" {
source = "spy86/acr/azure"
version = "1.0.4"
source = "Think-Cube/container-registry/azure"
version = "1.0.0"

envirioment = "dev"
acr_name = "registry4test"
resource_group_name = "weu-test-rg"
resource_group_location = "West Europe"
acr_tier = "Basic"
acr_admin_enabled = "true"

default_tags = {
Administrator = "Someone"
Department = "IT"
CostCentre = "ABC123"
ContactPerson = "Someone@example.com"
Administrator = "John Doe"
Department = "IT"
CostCentre = "CC123"
ContactPerson = "Jane Smith"
ManagedByTerraform = "True"
}
}
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "azurerm_client_config" "current" {}

data "azurerm_resource_group" "rg" {
name = "${var.resource_group_name}"
data "azurerm_resource_group" "main" {
name = var.resource_group_name
}
8 changes: 4 additions & 4 deletions output.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
output "id" {
description = "The ID of the Container Registry."
value = "${azurerm_container_registry.main.id}"
value = azurerm_container_registry.main.id
sensitive = false
}
output "login_server" {
description = "The URL that can be used to log into the container registry."
value = "${azurerm_container_registry.main.login_server}"
value = azurerm_container_registry.main.login_server
sensitive = false
}
output "admin_username" {
description = "The Username associated with the Container Registry Admin account - if the admin account is enabled."
value = "${azurerm_container_registry.main.admin_username}"
value = azurerm_container_registry.main.admin_username
sensitive = true
}
output "admin_password" {
description = "The Password associated with the Container Registry Admin account - if the admin account is enabled."
value = "${azurerm_container_registry.main.admin_password}"
value = azurerm_container_registry.main.admin_password
sensitive = true
}
61 changes: 38 additions & 23 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
############################
#Common vars
############################
variable "envirioment" {
description = "Specifies the name of the envirioment"
type = string
###########################
# Common vars
###########################
variable "environment" {
description = "Variable that defines the name of the environment."
type = string
default = "dev"
}
variable "default_tags" {
description = "A mapping of tags to assign to the resource."
type = map
type = map(any)
default = {
"ManagedByTerraform" = "True"
}
}
variable "region" {
description = "Region in which resources are deployed."
type = string
default = "weu"
}

############################
#Resource gropus vars
############################
###########################
# Resource groups vars
###########################
variable "resource_group_location" {
description = "The location of the resource group in which to create the Container Registry. Changing this forces a new resource to be created."
type = string
description = "Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created."
default = "West Europe"
type = string
}
variable "resource_group_name" {
description = "The name of the resource group in which to create the Container Registry. Changing this forces a new resource to be created."
type = string
description = "The name of the resource group in which to create the container registry component. Changing this forces a new resource to be created."
type = string
}
############################
#ACR variable
#Container registry variable
############################
variable "acr_tier" {
description = "The SKU name of the container registry. Possible values are Basic, Standard and Premium. Classic (which was previously Basic) is supported only for existing resources."
type = string
default = "Basic"
description = "The SKU name of the container registry. Possible values are Basic, Standard and Premium. Classic (which was previously Basic) is supported only for existing resources."
type = string
default = "Basic"

validation {
condition = can(regex("^(Basic|Premium)$", var.acr_tier))
error_message = "Invalid value for acr_tier. Valid values are Basic or Premium."
}
}
variable "acr_name" {
description = "Specifies the name of the Container Registry. Changing this forces a new resource to be created."
type = string
description = "Specifies the name of the Container Registry. Changing this forces a new resource to be created."
type = string
}
variable "acr_admin_enabled" {
description = "Specifies whether the admin user is enabled. Defaults to false."
type = string
default = "false"
description = "Specifies whether the admin user is enabled. Defaults to false."
type = string
default = "false"
}
Loading