Skip to content
Open

Test #56

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b6a08e4
chore: bump all provider versions, major versions 😬
julie-ng Apr 29, 2022
76c9455
provider(storage): remove deprecated property
julie-ng May 1, 2022
f9573e6
provider(aad): since v2 azure creates service principal passwords
julie-ng May 1, 2022
d606615
chore: remove unused code
julie-ng May 1, 2022
4fc3809
main-proj: specify dependency relationship
julie-ng May 1, 2022
b36c3b1
feat(initial-setup): bootstrap aad owners group, sp with terraform
julie-ng May 1, 2022
fb11def
style(comments)): prefer '===' to separate sections
julie-ng May 1, 2022
48ae651
module(service-principal): rename owners to owners_list to indicate type
julie-ng May 1, 2022
82938d8
style: comments headings use '==='
julie-ng May 1, 2022
9b289ff
chore(comments): rename RGs to ARM resources
julie-ng May 1, 2022
dd08602
feat(environments): can specify dev or prod vars
julie-ng May 1, 2022
62b7d64
chore(_override): improve doc
julie-ng May 1, 2022
74c0691
feat: diff vars per env
julie-ng May 1, 2022
fa871b5
ci-cd-bootstrap: assign owner role to GROUP not sp
julie-ng May 1, 2022
b4041a6
backend-sample: improve comment
julie-ng May 1, 2022
0cc400d
ci-cd-setup: add missing app role assignments, warning in readme
julie-ng May 1, 2022
2c8778a
providers: update aad provider
julie-ng May 1, 2022
6b8fa50
fix: missing dependency
julie-ng May 1, 2022
11c7f8d
style: space
julie-ng May 1, 2022
12dd35e
module(sp): remove no longer needed variable
julie-ng May 1, 2022
197f94e
cicd-setup: fix object id exports
julie-ng May 1, 2022
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
116 changes: 59 additions & 57 deletions .terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions _override.tf.sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# To deploy this project from a local machine, first remove
# the `.sample` extension from this file before running the
# To deploy this project from a local machine (without a Terraform backend),
# first remove the `.sample` extension from this file before running the
# `terraform init` command.
#
# For details see:
Expand Down
6 changes: 3 additions & 3 deletions backends/backend.hcl.sample
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
storage_account_name="STORAGE_ACCOUNT_NAME"
container_name="STORAGE_CONTAINER_NAME"
key="FILENAME.tfstate"
# To authenticate to the Storage account, pick and uncomment one of the options below:
# sas_token="?sv=2019-12-12…" # or account key
# access_key="…" # or SAS token
# To authenticate to the Storage account, pick and uncomment *one* of the options below:
# sas_token="?sv=2019-12-12…" # use SAS token
# access_key="…" # use Storage Account Access Key
14 changes: 14 additions & 0 deletions environments/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Environments Configuration (Optional)

Define specific variables per environment. Currently used for Azure Resource tags, e.g. `env=dev` vs `env=prod`.

These custom tags are merged into defaults defined in [`/variables.tf`](./../variables.tf)

### Usage example

These values need to be explicitly specified via `-var-file` flag.

```
terraform plan -var-file=environments/dev.tfvars
terraform apply -var-file=environments/dev.tfvars
```
6 changes: 6 additions & 0 deletions environments/dev.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
custom_tags = {
demo-version = "v0.5.0"
env = "dev"
devops-org = "julie-msft"
github = "azure/devops-governance"
}
6 changes: 6 additions & 0 deletions environments/prod.tfvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
custom_tags = {
demo-version = "v0.5.0"
env = "production"
devops-org = "julie-msft"
github = "azure/devops-governance"
}
62 changes: 37 additions & 25 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ------
# Config
# ------
# ========
# Config
# ========

data "azurerm_client_config" "current" {}

Expand All @@ -16,11 +16,12 @@ locals {
suffix = random_string.suffix.result
application_owners_ids = length(var.application_owners_ids) == 0 ? [data.azurerm_client_config.current.object_id] : var.application_owners_ids
superadmins_aad_object_id = var.superadmins_aad_object_id == "" ? data.azurerm_client_config.current.object_id : var.superadmins_aad_object_id # Default to current ARM client
tags = merge(var.default_tags, var.custom_tags)
}

# ---------------
# Azure AD Groups
# ---------------
# =================
# Azure AD Groups
# =================

resource "azuread_group" "groups" {
for_each = var.groups
Expand All @@ -29,22 +30,24 @@ resource "azuread_group" "groups" {
security_enabled = true
}

# ------------------
# Service Principals
# ------------------
# ====================
# Service Principals
# ====================

# TODO: document use for CI only. Apps should use diff. SP per PILP

module "service_principals" {
for_each = var.environments
source = "./modules/service-principal"
name = "${each.value.team}-${each.value.env}-${local.suffix}-ci-sp"
owners = local.application_owners_ids
for_each = var.environments
source = "./modules/service-principal"
name = "${each.value.team}-${each.value.env}-${local.suffix}-ci-sp"
owners_list = local.application_owners_ids
}

# ------------------------------
# Resource Groups ("Workspaces")
# ------------------------------
# ==============================
# ARM Resources ("Workspaces")
# ==============================

# Resource Group, Storage Account, and Key Vault

module "arm_environments" {
for_each = var.environments
Expand All @@ -54,19 +57,25 @@ module "arm_environments" {
admins_group_id = azuread_group.groups["${each.value.team}_admins"].id
superadmins_group_id = local.superadmins_aad_object_id
service_principal_id = module.service_principals["${each.value.team}_${each.value.env}"].principal_id
tags = local.tags
depends_on = [
azuread_group.groups,
module.service_principals
]
}

# ------------
# Azure DevOps
# ------------
# ==============
# Azure DevOps
# ==============

# The following section Bootstraps:
# - Projects: Team silos and shared projects
# - Security Group Assignments: like Role Assignments in ARM
# - Service Connections: service principal credentials created in code above

# Projects
# --------
# ==============
# ADO Projects
# ==============

# Team Projects

Expand Down Expand Up @@ -120,8 +129,9 @@ resource "azuredevops_project" "collaboration" {
}
}

# Security Group Assignments
# --------------------------
# ================================
# ADO Security Group Assignments
# ================================

# Teams Silo Projects - Security Group Assignments

Expand Down Expand Up @@ -191,8 +201,9 @@ module "ado_collaboration_permissions_veggies" {
]
}

# Service Connections
# -------------------
# =========================
# ADO Service Connections
# =========================

module "service_connections" {
for_each = module.arm_environments
Expand All @@ -203,6 +214,7 @@ module "service_connections" {

depends_on = [
azuread_group.groups,
azuredevops_project.team_projects,
module.arm_environments,
module.service_principals
]
Expand Down
2 changes: 1 addition & 1 deletion modules/azure-devops-permissions/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
version = ">=0.1.0"
version = ">=0.2.0"
}
}
}
1 change: 1 addition & 0 deletions modules/azure-devops-service-connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ resource "azuredevops_serviceendpoint_azurerm" "workspace_endpoint" {
azurerm_spn_tenantid = data.azurerm_client_config.current.tenant_id
azurerm_subscription_id = data.azurerm_client_config.current.subscription_id
azurerm_subscription_name = data.azurerm_subscription.current.display_name

credentials {
serviceprincipalid = var.service_principal_id
serviceprincipalkey = var.service_principal_secret
Expand Down
10 changes: 5 additions & 5 deletions modules/azure-devops-service-connection/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
version = ">=0.1.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.50.0"
version = ">=0.2.0"
}
# azurerm = {
# source = "hashicorp/azurerm"
# version = ">= 2.50.0"
# }
}
}
12 changes: 1 addition & 11 deletions modules/azure-resources/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ resource "azurerm_storage_account" "storage" {
location = azurerm_resource_group.workspace.location
account_tier = "Standard"
account_replication_type = "LRS"
allow_blob_public_access = false
tags = var.tags
}

Expand All @@ -39,15 +38,6 @@ resource "azurerm_key_vault" "kv" {
enable_rbac_authorization = true
}

# ------------------
# Service Principals
# ------------------

# module "workspace_sp" {
# source = "./../service-principal"
# name = "${local.name}-sp"
# }

# -----------------------
# RBAC - Role Assignments
# -----------------------
Expand Down Expand Up @@ -109,4 +99,4 @@ resource "azurerm_role_assignment" "kv_team_devs" {
# }

# Why does it take up to 10 minutes for Key Vault RBAC to propagate?
# See https://docs.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#known-limits-and-performance
# See https://docs.microsoft.com/en-us/azure/key-vault/general/rbac-guide?tabs=azure-cli#known-limits-and-performance
6 changes: 0 additions & 6 deletions modules/azure-resources/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ variable "client_object_id" {
variable "tags" {
description = "Tags to apply to Azure Resources"
type = map(string)
default = {
demo = "governance"
devops = "true"
oss = "terraform"
public = "true"
}
}

data "azurerm_client_config" "current" {}
Expand Down
Loading