├── backend ├── backend-config.txt ├── state.tfplan ├── variables.tf └── main.tf ├── README.md ├── .gitignore └── LICENSE /backend/backend-config.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/state.tfplan: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/My-Azure-Projects/terraform-on-azure/HEAD/backend/state.tfplan -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-on-azure 2 | 3 | 4 | A project to learn terraform using AzureRM provider, and get hands on experience. 5 | -------------------------------------------------------------------------------- /backend/variables.tf: -------------------------------------------------------------------------------- 1 | variable "naming_prefix"{ 2 | type = string 3 | default = "learn" 4 | } 5 | variable "resource_group_name"{ 6 | type = string 7 | default = "learn-shared-rg" 8 | } 9 | variable "location"{ 10 | type = string 11 | default = "Australia East" 12 | } 13 | 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Rahul Sarkar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /backend/main.tf: -------------------------------------------------------------------------------- 1 | terraform{ 2 | required_version = ">= 0.13.3" 3 | } 4 | 5 | provider "azurerm"{ 6 | version = ">= 2.28.0" 7 | features {} 8 | } 9 | 10 | resource "random_integer" "sa_num"{ 11 | min = 10000 12 | max = 99999 13 | } 14 | 15 | resource "azurerm_resource_group" "backend_rg"{ 16 | name = var.resource_group_name 17 | location = var.location 18 | } 19 | 20 | resource "azurerm_storage_account" "backend_sa"{ 21 | name = "${lower(var.naming_prefix)}sa${random_integer.sa_num.result}" 22 | resource_group_name = azurerm_resource_group.backend_rg.name 23 | location = var.location 24 | account_tier = "Standard" 25 | account_replication_type = "LRS" 26 | } 27 | 28 | resource "azurerm_storage_container" "backend_ct"{ 29 | name = "${lower(var.naming_prefix)}-terraform-state-ct" 30 | storage_account_name = azurerm_storage_account.backend_sa.name 31 | } 32 | 33 | data "azurerm_storage_account_sas" "backend_state_token"{ 34 | connection_string = azurerm_storage_account.backend_sa.primary_connection_string 35 | https_only = true 36 | 37 | resource_types { 38 | service = true 39 | container = true 40 | object = true 41 | } 42 | 43 | services { 44 | blob = true 45 | queue = false 46 | table = false 47 | file = false 48 | } 49 | 50 | start = timestamp() 51 | expiry = timeadd(timestamp(),"168h") 52 | 53 | permissions { 54 | read = true 55 | write = true 56 | add = true 57 | create = true 58 | delete = true 59 | list = true 60 | process = false 61 | update = false 62 | } 63 | } 64 | 65 | ## PROVISIONERS 66 | resource "null_resource" "write_backend_config" { 67 | depends_on = [azurerm_storage_container.backend_ct] 68 | 69 | provisioner "local-exec" { 70 | command = <