Skip to content

Commit

Permalink
added cost-allocation to terraform in playground
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard87 committed Feb 6, 2024
1 parent b4888cb commit 6f20c22
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
2 changes: 1 addition & 1 deletion terraform/subscriptions/modules/mssqldatabase/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource "azurerm_mssql_database" "mssql_database" {
read_scale = var.read_scale
sku_name = var.sku_name
zone_redundant = var.zone_redundant
tags = var.tags
tags = var.database_tags
depends_on = [azurerm_mssql_server.sqlserver]
long_term_retention_policy {
monthly_retention = "PT0S"
Expand Down
8 changes: 6 additions & 2 deletions terraform/subscriptions/s941/dev/cost-allocation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ module "mssql-database" {
admin_federated_credentials = {
github-master = {
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-vulnerability-scanner:ref:refs/heads/master"
subject = "repo:equinor/radix-cost-allocation:ref:refs/heads/master"
}
github-release = {
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-vulnerability-scanner:ref:refs/heads/release"
subject = "repo:equinor/radix-cost-allocation:ref:refs/heads/release"
}
test = {
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-cost-allocation:pull_request"
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions terraform/subscriptions/s941/playground/cost-allocation/backend.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "<=3.69.0"
}
}

backend "azurerm" {
tenant_id = "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
subscription_id = "16ede44b-1f74-40a5-b428-46cca9a5741b"
resource_group_name = "s941-tfstate"
storage_account_name = "s941radixinfra"
container_name = "infrastructure"
key = "playground/cost-allocation/terraform.tfstate"
}
}

provider "azurerm" {
subscription_id = "16ede44b-1f74-40a5-b428-46cca9a5741b"
features {
}
}
34 changes: 34 additions & 0 deletions terraform/subscriptions/s941/playground/cost-allocation/input.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
locals {

external_outputs = {
common = data.terraform_remote_state.common.outputs
// keyvault = data.terraform_remote_state.keyvault.outputs.data
}

backend = {
resource_group_name = "s941-tfstate"
storage_account_name = "s941radixinfra"
container_name = "infrastructure"
subscription_id = "16ede44b-1f74-40a5-b428-46cca9a5741b"
}
}


data "terraform_remote_state" "common" {
backend = "azurerm"
config = merge(
local.backend,
{ key = "playground/common/terraform.tfstate" })
}

#data "terraform_remote_state" "keyvault" {
# backend = "azurerm"
# config = merge(
# local.backend,
# { key = "playground/key-vault/terraform.tfstate" })
#}
#
#
#


49 changes: 49 additions & 0 deletions terraform/subscriptions/s941/playground/cost-allocation/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module "resourcegroup" {
source = "../../../modules/resourcegroups"
name = "${var.resourse_group_name}-${local.external_outputs.common.data.enviroment}"
location = local.external_outputs.common.data.location
}
data "azurerm_key_vault" "keyvault" {
name = "radix-vault-dev"
resource_group_name = "common"
}
data "azurerm_key_vault_secret" "keyvault_secrets" {
name = var.keyvault_dbadmin_secret_name
key_vault_id = data.azurerm_key_vault.keyvault.id # local.external_outputs.keyvault.vault_id
}

# MS SQL Server
module "mssql-database" {
source = "../../../modules/mssqldatabase"
env = local.external_outputs.common.data.enviroment
database_name = "sqldb-radix-cost-allocation"
server_name = "sql-radix-cost-allocation-${local.external_outputs.common.data.enviroment}"
admin_adgroup = var.admin-adgroup
administrator_login = "radix"
administrator_password = data.azurerm_key_vault_secret.keyvault_secrets.value
rg_name = module.resourcegroup.data.name
location = local.external_outputs.common.data.location
public_network_access_enabled = false
zone_redundant = false
tags = {
displayName = "SqlServer"
}
database_tags = {
displayName = "Database"
}

admin_federated_credentials = {
github-master = {
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-cost-allocation:ref:refs/heads/master"
}
github-release = {
issuer = "https://token.actions.githubusercontent.com"
subject = "repo:equinor/radix-cost-allocation:ref:refs/heads/release"
}
}
}

output "mi-client-id" {
value = module.mssql-database.mi-admin
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "admin-adgroup" {
type = string
default = "Radix SQL server admin - playground"
}

variable "resourse_group_name" {
type = string
default = "cost-allocation"
}

variable "keyvault_dbadmin_secret_name" {
type = string
default = "radix-cost-allocation-db-admin"
}

0 comments on commit 6f20c22

Please sign in to comment.