From d945eb35dfdcc613907692568c4e85b24265ee44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Gwizda=C5=82a?= <57432150+maciejgwizdala@users.noreply.github.com> Date: Tue, 9 Nov 2021 08:15:28 +0100 Subject: [PATCH] Feat: Add Terraform Azure Storage Account (#2646) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Feat: Add Terraform Azure Storage Account * Fix: Added resource group creation for tests * Feat: Added EOF for tf azure storage account Co-authored-by: Maciej GwizdaƂa --- .../vela-core/templates/addons/terraform.yaml | 104 ++++++++++++++++++ vela-templates/addons/auto-gen/terraform.yaml | 104 ++++++++++++++++++ .../terraform-azure-storage-account.yaml | 100 +++++++++++++++++ 3 files changed, 308 insertions(+) create mode 100644 vela-templates/addons/terraform/definitions/terraform-azure-storage-account.yaml diff --git a/charts/vela-core/templates/addons/terraform.yaml b/charts/vela-core/templates/addons/terraform.yaml index 9f29c0156..138ba709f 100644 --- a/charts/vela-core/templates/addons/terraform.yaml +++ b/charts/vela-core/templates/addons/terraform.yaml @@ -329,6 +329,110 @@ data: apiVersion: terraform.core.oam.dev/v1beta1 kind: Configuration type: raw + - name: azure-storage-account + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for Azure Blob Storage + Account + provider: azure + labels: + type: terraform + name: azure-storage-account + namespace: vela-system + spec: + schematic: + terraform: + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "rsg" { + count = var.create_rsg ? 1 : 0 + name = var.resource_group_name + location = var.location + } + + resource "azurerm_storage_account" "sa" { + name = var.name + resource_group_name = var.create_rsg ? azurerm_resource_group.rsg[0].name : var.resource_group_name + location = var.location + account_tier = "Standard" + account_replication_type = "GRS" + enable_https_traffic_only = true + + dynamic "static_website" { + for_each = var.static_website + content { + index_document = static_website.value["index_document"] + error_404_document = static_website.value["error_404_document"] + } + } + + tags = var.tags + } + + variable "create_rsg" { + description = "Conditional if resource group should be created. Defaults to 'true'." + type = bool + default = true + } + + variable "resource_group_name" { + description = "Name of resource group. Defaults to 'rsg'." + type = string + default = "rsg" + } + + variable "name" { + description = "Name of storage account. Defaults to 'storageaccount'." + type = string + default = "storageaccount" + } + + variable "location" { + description = "Location of storage account. Defaults to 'West Europe'." + type = string + default = "West Europe" + } + + variable "tags" { + description = "Tags for storage account. Defaults to '{}'." + type = map(string) + default = {} + } + + variable "static_website" { + description = "Static website configuration. Defaults to disabled." + type = list(map(string)) + default = [{ + index_document = null + error_404_document = null + }] + } + + output "BLOB_CONNECTION_STRING" { + description = "Blob storage connection string" + sensitive = true + value = azurerm_storage_account.sa.primary_connection_string + } + + output "BLOB_WEB_ENDPOINT" { + description = "Blob storage static web endpoint" + value = azurerm_storage_account.sa.primary_web_endpoint + } + providerRef: + name: azure + namespace: default + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw workflow: steps: - name: checking-depends-on diff --git a/vela-templates/addons/auto-gen/terraform.yaml b/vela-templates/addons/auto-gen/terraform.yaml index 23eddd8de..f52753377 100644 --- a/vela-templates/addons/auto-gen/terraform.yaml +++ b/vela-templates/addons/auto-gen/terraform.yaml @@ -326,6 +326,110 @@ spec: apiVersion: terraform.core.oam.dev/v1beta1 kind: Configuration type: raw + - name: azure-storage-account + properties: + apiVersion: core.oam.dev/v1alpha2 + kind: ComponentDefinition + metadata: + annotations: + definition.oam.dev/description: Terraform configuration for Azure Blob Storage + Account + provider: azure + labels: + type: terraform + name: azure-storage-account + namespace: vela-system + spec: + schematic: + terraform: + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "rsg" { + count = var.create_rsg ? 1 : 0 + name = var.resource_group_name + location = var.location + } + + resource "azurerm_storage_account" "sa" { + name = var.name + resource_group_name = var.create_rsg ? azurerm_resource_group.rsg[0].name : var.resource_group_name + location = var.location + account_tier = "Standard" + account_replication_type = "GRS" + enable_https_traffic_only = true + + dynamic "static_website" { + for_each = var.static_website + content { + index_document = static_website.value["index_document"] + error_404_document = static_website.value["error_404_document"] + } + } + + tags = var.tags + } + + variable "create_rsg" { + description = "Conditional if resource group should be created. Defaults to 'true'." + type = bool + default = true + } + + variable "resource_group_name" { + description = "Name of resource group. Defaults to 'rsg'." + type = string + default = "rsg" + } + + variable "name" { + description = "Name of storage account. Defaults to 'storageaccount'." + type = string + default = "storageaccount" + } + + variable "location" { + description = "Location of storage account. Defaults to 'West Europe'." + type = string + default = "West Europe" + } + + variable "tags" { + description = "Tags for storage account. Defaults to '{}'." + type = map(string) + default = {} + } + + variable "static_website" { + description = "Static website configuration. Defaults to disabled." + type = list(map(string)) + default = [{ + index_document = null + error_404_document = null + }] + } + + output "BLOB_CONNECTION_STRING" { + description = "Blob storage connection string" + sensitive = true + value = azurerm_storage_account.sa.primary_connection_string + } + + output "BLOB_WEB_ENDPOINT" { + description = "Blob storage static web endpoint" + value = azurerm_storage_account.sa.primary_web_endpoint + } + providerRef: + name: azure + namespace: default + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + type: raw workflow: steps: - name: checking-depends-on diff --git a/vela-templates/addons/terraform/definitions/terraform-azure-storage-account.yaml b/vela-templates/addons/terraform/definitions/terraform-azure-storage-account.yaml new file mode 100644 index 000000000..cca7beded --- /dev/null +++ b/vela-templates/addons/terraform/definitions/terraform-azure-storage-account.yaml @@ -0,0 +1,100 @@ +apiVersion: core.oam.dev/v1alpha2 +kind: ComponentDefinition +metadata: + name: azure-storage-account + namespace: vela-system + annotations: + definition.oam.dev/description: Terraform configuration for Azure Blob Storage Account + provider: azure + labels: + type: terraform +spec: + workload: + definition: + apiVersion: terraform.core.oam.dev/v1beta1 + kind: Configuration + schematic: + terraform: + providerRef: + name: azure + namespace: default + configuration: | + # Configure the Microsoft Azure Provider + provider "azurerm" { + features {} + } + + resource "azurerm_resource_group" "rsg" { + count = var.create_rsg ? 1 : 0 + name = var.resource_group_name + location = var.location + } + + resource "azurerm_storage_account" "sa" { + name = var.name + resource_group_name = var.create_rsg ? azurerm_resource_group.rsg[0].name : var.resource_group_name + location = var.location + account_tier = "Standard" + account_replication_type = "GRS" + enable_https_traffic_only = true + + dynamic "static_website" { + for_each = var.static_website + content { + index_document = static_website.value["index_document"] + error_404_document = static_website.value["error_404_document"] + } + } + + tags = var.tags + } + + variable "create_rsg" { + description = "Conditional if resource group should be created. Defaults to 'true'." + type = bool + default = true + } + + variable "resource_group_name" { + description = "Name of resource group. Defaults to 'rsg'." + type = string + default = "rsg" + } + + variable "name" { + description = "Name of storage account. Defaults to 'storageaccount'." + type = string + default = "storageaccount" + } + + variable "location" { + description = "Location of storage account. Defaults to 'West Europe'." + type = string + default = "West Europe" + } + + variable "tags" { + description = "Tags for storage account. Defaults to '{}'." + type = map(string) + default = {} + } + + variable "static_website" { + description = "Static website configuration. Defaults to disabled." + type = list(map(string)) + default = [{ + index_document = null + error_404_document = null + }] + } + + output "BLOB_CONNECTION_STRING" { + description = "Blob storage connection string" + sensitive = true + value = azurerm_storage_account.sa.primary_connection_string + } + + output "BLOB_WEB_ENDPOINT" { + description = "Blob storage static web endpoint" + value = azurerm_storage_account.sa.primary_web_endpoint + }