Skip to content

Commit

Permalink
Merge pull request #2 from devwithkrishna/feature/tf-module-for-api-mgmt
Browse files Browse the repository at this point in the history
Feature/tf module for api mgmt
  • Loading branch information
githubofkrishnadhas authored Jul 30, 2024
2 parents 3507741 + 094ff7e commit c869720
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Generate terraform docs
on:
pull_request:
types:
- closed
branches:
- main

permissions:
contents: write

jobs:
generate-terraform-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Render terraform docs and push changes back to PR
uses: terraform-docs/gh-actions@main
with:
recursive: true
config-file: .terraform-docs.yml
output-file: README.md
output-method: inject
git-push: "true"
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ override.tf.json
terraform.rc
# Ignore hcl file
**/*.hcl

# Ignore terraform docs generated readme
.git\README.md
.github\README.md
README.md
70 changes: 70 additions & 0 deletions .terraform-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
formatter: "markdown table" # this is required
version: "0.18"
header-from: main.tf
footer-from: ""
recursive:
enabled: true
path: "."
# - "api-management"
recursive-include-main: false
# enabled: false
sections:
hide: []
show: []
hide-all: false # deprecated in v0.13.0, removed in v0.15.0
show-all: true # deprecated in v0.13.0, removed in v0.15.0
content: |-
{{ .Requirements }}
## Usage
Basic usage of this module is as follows:
```hcl
module "example" {
{{"\t"}} source = "<module-path>"
{{- if .Module.RequiredInputs }}
{{"\n\t"}} # Required variables
{{- range .Module.RequiredInputs }}
{{"\t"}} {{ .Name }} = {{ .GetValue }}
{{- end }}
{{- end }}
{{- if .Module.OptionalInputs }}
{{"\n\t"}} # Optional variables
{{- range .Module.OptionalInputs }}
{{"\t"}} {{ .Name }} = {{ .GetValue | printf "%s" }}
{{- end }}
{{- end }}
}
````
{{ .Resources }}
{{ .Inputs }}
{{ .Outputs }}
output:
file: README.md
mode: inject
template: |-
<!-- BEGIN_AUTOMATED_TF_DOCS_BLOCK -->
{{ .Content }}
<!-- END_AUTOMATED_TF_DOCS_BLOCK -->
output-values:
enabled: false
from: ""
sort:
enabled: true
by: name
settings:
anchor: true
color: true
default: false
description: true
escape: false
hide-empty: false
html: false
indent: 2
lockfile: true
read-comments: true
required: true
sensitive: true
type: true
pretty: true
14 changes: 14 additions & 0 deletions api-management/apim.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "azurerm_resource_group" "rg" {
name = var.resource_group_name
location = var.location
}

resource "azurerm_api_management" "apim" {
name = var.api_management_name
location = var.location
resource_group_name = azurerm_resource_group.rg.name
publisher_name = tostring(var.publisher_name)
publisher_email = tostring(var.publisher_email)

sku_name = "${var.sku_name_part1}_${var.sku_name_part2}"
}
29 changes: 29 additions & 0 deletions api-management/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
output "azure_resource_group_name" {
description = "Azure resource group name"
value = azurerm_resource_group.rg.name
}

output "azure_api_management_name" {
description = "Azure API management name"
value = azurerm_api_management.apim.name
}

output "azure_api_management_location" {
description = "Azure API management location"
value = azurerm_api_management.apim.location
}

output "azure_api_management_publisher_name" {
description = "Azure API management"
value = azurerm_api_management.apim.publisher_name
}

output "azure_api_management_publisher_emailids" {
description = "Azure API management publisher emails"
value = azurerm_api_management.apim.publisher_email
}

output "azure_api_management_sku" {
description = "Azure API management SKU"
value = azurerm_api_management.apim.sku_name
}
46 changes: 46 additions & 0 deletions api-management/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
variable "resource_group_name" {
type = string
description = "Azure Storage Account Rg"
}

variable "location" {
type = string
description = "Azure storage account location"
}

variable "api_management_name" {
description = "Azure api management name"
type = string
}

variable "publisher_name" {
description = "Publisher of API"
type = list(string)
validation {
condition = can(index(var.publisher_name, 0))
error_message = "A value is required for Publisher name."
}
}

variable "publisher_email" {
description = "Email ID of API publishers"
type = list(string)
validation {
condition = can(index(var.publisher_email, 0))
error_message = "At least one Publisher email is required."
}
}

variable "sku_name_part1" {
description = "SKU name of API management "
type = string
validation {
condition = contains(["Consumption","Developer","Basic","Standard", "Premium"], var.sku_name_part1)
error_message = "SKU name should be one among Consumption, Developer,Basic,Standard,Premium."
}
}

variable "sku_name_part2" {
description = "Sku capacity part"
type = string
}
7 changes: 7 additions & 0 deletions storage-account/output.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
output "azurerm_resource_group" {
description = "Azure resource group name"
value = azurerm_resource_group.storage_rg.name
}

output "storage_account_name" {
description = "Azure storage account name"
value = azurerm_storage_account.storage.name
}

output "storage_account_location" {
description = "Azure storage account location"
value = azurerm_storage_account.storage.location
}

output "storage_account_delete_retention_policy" {
description = "Azure blob retention policy"
value = azurerm_storage_account.storage.blob_properties[0].delete_retention_policy
}

output "storage_account_tier" {
description = "Azure storage account tier"
value = azurerm_storage_account.storage.access_tier
}

output "storage_account_replication_type" {
description = "Azure storage account replication type"
value = azurerm_storage_account.storage.account_replication_type
}

output "storage_account_tags" {
description = "Azure storage account tags"
value = azurerm_storage_account.storage.tags
}

0 comments on commit c869720

Please sign in to comment.