Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Support for using existing / requiring existing resource group(s). (#549
Browse files Browse the repository at this point in the history
)

Add bring your own resource group support - closes #474
  • Loading branch information
jmspring authored Aug 21, 2019
1 parent 82911dc commit 6e0bb1d
Show file tree
Hide file tree
Showing 65 changed files with 376 additions and 312 deletions.
13 changes: 12 additions & 1 deletion cluster/azure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ Beyond these, you'll only need the Azure `az` command line tool installed (used

Bedrock provides different templates to start from when building your deployment environment. Each template has a set of common and specific requirements that must be met in order to deploy them.

Common across templates, it is required that the resource group(s) needed by the enviornment be created prior to deploying. For how to create a resource group, see [here](#Creating-Resource-Groups).

The following templates are currently available for deployment:

- [azure-common-infra](../environments/azure-common-infra): Common infrastructure deployment template.

- [azure-simple](../environments/azure-simple/): Single cluster deployment.
- [azure-single-keyvault](../environments/azure-single-keyvault): Single cluster with Azure Keyvault integration through flex volumes template.
- [azure-multiple-clusters](../environments/azure-multiple-clusters/): Multiple cluster deployment with Traffic Manager.
Expand All @@ -41,6 +42,16 @@ The common steps necessary to deploy a cluster are:
- [Configure `kubectl` to see your new AKS cluster](#configure-kubectl-to-see-your-new-aks-cluster)
- [Verify that your AKS cluster is healthy](#verify-that-your-aks-cluster-is-healthy)

### Creating Resource Groups

Resource groups can be created throug the [Azure portal](https://portal.azure.com) or via the Azure CLI as follows:

```bash
$ az group create -n <resource group name> -l <resource group location>
```

Within each environment, the required resource groups that need to be created are documented.

### Create an Azure Service Principal

You can generate an Azure Service Principal using the [`az ad sp create-for-rbac`](https://docs.microsoft.com/en-us/cli/azure/ad/sp?view=azure-cli-latest#az-ad-sp-create) command with `--skip-assignment` option. The `--skip-assignment` parameter limits any additional permissions from being assigned the default [`Contributor`](https://docs.microsoft.com/en-us/azure/role-based-access-control/rbac-and-directory-admin-roles#azure-rbac-roles) role in Azure subscription.
Expand Down
7 changes: 5 additions & 2 deletions cluster/azure/aks-gitops/main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
data "azurerm_resource_group" "aksgitops" {
name = "${var.resource_group_name}"
}

module "aks" {
source = "../../azure/aks"

resource_group_name = "${var.resource_group_name}"
resource_group_location = "${var.resource_group_location}"
resource_group_name = "${data.azurerm_resource_group.aksgitops.name}"
cluster_name = "${var.cluster_name}"
agent_vm_count = "${var.agent_vm_count}"
agent_vm_size = "${var.agent_vm_size}"
Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/aks-gitops/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ variable "resource_group_name" {
type = "string"
}

variable "resource_group_location" {
type = "string"
}

variable "service_principal_id" {
type = "string"
}
Expand Down
17 changes: 8 additions & 9 deletions cluster/azure/aks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ module "azure-provider" {
source = "../provider"
}

resource "azurerm_resource_group" "cluster" {
data "azurerm_resource_group" "cluster" {
name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
}

resource "random_id" "workspace" {
keepers = {
group_name = "${azurerm_resource_group.cluster.name}"
group_name = "${data.azurerm_resource_group.cluster.name}"
}

byte_length = 8
}

resource "azurerm_log_analytics_workspace" "workspace" {
name = "bedrock-k8s-workspace-${random_id.workspace.hex}"
location = "${azurerm_resource_group.cluster.location}"
resource_group_name = "${azurerm_resource_group.cluster.name}"
location = "${data.azurerm_resource_group.cluster.location}"
resource_group_name = "${data.azurerm_resource_group.cluster.name}"
sku = "PerGB2018"
}

resource "azurerm_log_analytics_solution" "solution" {
solution_name = "ContainerInsights"
location = "${azurerm_resource_group.cluster.location}"
resource_group_name = "${azurerm_resource_group.cluster.name}"
location = "${data.azurerm_resource_group.cluster.location}"
resource_group_name = "${data.azurerm_resource_group.cluster.name}"
workspace_resource_id = "${azurerm_log_analytics_workspace.workspace.id}"
workspace_name = "${azurerm_log_analytics_workspace.workspace.name}"

Expand All @@ -37,8 +36,8 @@ resource "azurerm_log_analytics_solution" "solution" {

resource "azurerm_kubernetes_cluster" "cluster" {
name = "${var.cluster_name}"
location = "${azurerm_resource_group.cluster.location}"
resource_group_name = "${azurerm_resource_group.cluster.name}"
location = "${data.azurerm_resource_group.cluster.location}"
resource_group_name = "${data.azurerm_resource_group.cluster.name}"
dns_prefix = "${var.dns_prefix}"
kubernetes_version = "${var.kubernetes_version}"

Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/aks/variables.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
variable "resource_group_location" {
type = "string"
}

variable "resource_group_name" {
type = "string"
}
Expand Down
7 changes: 3 additions & 4 deletions cluster/azure/keyvault/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ module "azure-provider" {
source = "../provider"
}

resource "azurerm_resource_group" "keyvault" {
data "azurerm_resource_group" "keyvault" {
name = "${var.resource_group_name}"
location = "${var.location}"
}

data "azurerm_client_config" "current" {}

resource "azurerm_key_vault" "keyvault" {
name = "${var.keyvault_name}"
location = "${azurerm_resource_group.keyvault.location}"
resource_group_name = "${azurerm_resource_group.keyvault.name}"
location = "${data.azurerm_resource_group.keyvault.location}"
resource_group_name = "${data.azurerm_resource_group.keyvault.name}"
tenant_id = "${data.azurerm_client_config.current.tenant_id}"

sku_name = "${var.keyvault_sku}"
Expand Down
5 changes: 0 additions & 5 deletions cluster/azure/keyvault/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ variable "resource_group_name" {
description = "Default resource group name that the network will be created in."
default = "myapp-rg"
}

variable "location" {
description = "The location/region where the core network will be created. The full list of Azure regions can be found at https://azure.microsoft.com/regions"
type = "string"
}
15 changes: 12 additions & 3 deletions cluster/azure/tm-endpoint-ip/main.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
data "azurerm_resource_group" "pip" {
name = "${var.resource_group_name}"
}

data "azurerm_resource_group" "tmgr" {
name = "${var.traffic_manager_resource_group_name}"
}

resource "azurerm_public_ip" "pip" {
name = "${var.public_ip_name}-ip"
location = "${var.resource_location}"
resource_group_name = "${var.resource_group_name}"
location = "${data.azurerm_resource_group.pip.location}"
resource_group_name = "${data.azurerm_resource_group.pip.name}"

allocation_method = "${var.allocation_method}"
domain_name_label = "${var.public_ip_name}-dns"
tags = "${var.tags}"
}

resource "azurerm_traffic_manager_endpoint" "endpoint" {
name = "${var.endpoint_name}-ep"
resource_group_name = "${var.traffic_manager_resource_group_name}"
resource_group_name = "${data.azurerm_resource_group.tmgr.name}"
profile_name = "${var.traffic_manager_profile_name}"
target = "${var.endpoint_name}-dns"
target_resource_id = "${azurerm_public_ip.pip.id}"
Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/tm-endpoint-ip/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ variable "resource_group_name" {
type = "string"
}

variable "resource_location" {
type = "string"
}

variable "ip_address_out_filename" {
type = "string"
default = "bedrock_public_ip_address"
Expand Down
5 changes: 2 additions & 3 deletions cluster/azure/tm-profile/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
resource "azurerm_resource_group" "tmrg" {
data "azurerm_resource_group" "tmrg" {
name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
}

# Creates Azure Traffic Manager Profile
resource "azurerm_traffic_manager_profile" "profile" {
name = "${var.traffic_manager_profile_name}"
resource_group_name = "${azurerm_resource_group.tmrg.name}"
resource_group_name = "${data.azurerm_resource_group.tmrg.name}"
traffic_routing_method = "Weighted"

dns_config {
Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/tm-profile/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ variable "resource_group_name" {
type = "string"
}

variable "resource_group_location" {
type = "string"
}

variable "traffic_manager_monitor_protocol" {
type = "string"
default = "http"
Expand Down
9 changes: 4 additions & 5 deletions cluster/azure/vnet/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
resource "azurerm_resource_group" "vnet" {
data "azurerm_resource_group" "vnet" {
name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
}

resource "azurerm_virtual_network" "vnet" {
name = "${var.vnet_name}"
location = "${azurerm_resource_group.vnet.location}"
location = "${data.azurerm_resource_group.vnet.location}"
address_space = ["${var.address_space}"]
resource_group_name = "${azurerm_resource_group.vnet.name}"
resource_group_name = "${data.azurerm_resource_group.vnet.name}"
dns_servers = "${var.dns_servers}"
tags = "${var.tags}"
}
Expand All @@ -16,7 +15,7 @@ resource "azurerm_subnet" "subnet" {
count = "${length(var.subnet_names)}"
name = "${var.subnet_names[count.index]}"
virtual_network_name = "${azurerm_virtual_network.vnet.name}"
resource_group_name = "${azurerm_resource_group.vnet.name}"
resource_group_name = "${data.azurerm_resource_group.vnet.name}"

address_prefix = "${var.subnet_prefixes[count.index]}"
service_endpoints = "${var.subnet_service_endpoints[count.index]}"
Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/vnet/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ variable "resource_group_name" {
default = "myapp-rg"
}

variable "resource_group_location" {
description = "Default resource group location that the resource group will be created in. The full list of Azure regions can be found at https://azure.microsoft.com/regions"
}

variable "address_space" {
description = "The address space that is used by the virtual network."
default = "10.10.0.0/16"
Expand Down
7 changes: 3 additions & 4 deletions cluster/azure/waf/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
resource "azurerm_resource_group" "wafrg" {
data "azurerm_resource_group" "wafrg" {
name = "${var.resource_group_name}"
location = "${var.resource_group_location}"
}

resource "azurerm_application_gateway" "waf" {
name = "${var.wafname}-waf"
resource_group_name = "${azurerm_resource_group.wafrg.name}"
location = "${azurerm_resource_group.wafrg.location}"
resource_group_name = "${data.azurerm_resource_group.wafrg.name}"
location = "${data.azurerm_resource_group.wafrg.location}"

# WAF configuration
sku {
Expand Down
4 changes: 0 additions & 4 deletions cluster/azure/waf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ variable "resource_group_name" {
type = "string"
}

variable resource_group_location {
type = "string"
}

variable wafname {
type = "string"
}
Expand Down
6 changes: 4 additions & 2 deletions cluster/environments/azure-common-infra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ The `azure-common-infra` environment is a production ready template to setup com

When this is complete, proceed with the following steps to complete the `azure-common-infra` deployment.

## Resource Group Requirement

This environment requires a single resource group be created. The requisite variable is `resource_group_name`. To use the Azure CLI to create the resource group, see [here](../../azure/README.md).

### Create Storage Account in Azure

Before attempting to deploy the infrastructure environments, you will also need to create an Azure Storage Account. You can do this in Azure Portal, or by using the Azure CLI:
Expand Down Expand Up @@ -83,8 +87,6 @@ keyvault_name = "mykeyvault"

global_resource_group_name = "my-rg"

global_resource_group_location = "westus2"

service_principal_id = "<appId"

tenant_id = "<tenantId>"
Expand Down
3 changes: 1 addition & 2 deletions cluster/environments/azure-common-infra/keyvault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module "keyvault" {
source = "github.com/microsoft/bedrock?ref=master//cluster/azure/keyvault"

keyvault_name = "${var.keyvault_name}"
resource_group_name = "${var.global_resource_group_name}"
location = "${var.global_resource_group_location}"
resource_group_name = "${data.azurerm_resource_group.global_rg.name}"
}

module "keyvault_access_policy_default" {
Expand Down
3 changes: 1 addition & 2 deletions cluster/environments/azure-common-infra/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module "provider" {
source = "github.com/microsoft/bedrock?ref=master//cluster/azure/provider"
}

resource "azurerm_resource_group" "global_rg" {
data "azurerm_resource_group" "global_rg" {
name = "${var.global_resource_group_name}"
location = "${var.global_resource_group_location}"
}
4 changes: 0 additions & 4 deletions cluster/environments/azure-common-infra/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ variable "global_resource_group_name" {
type = "string"
}

variable "global_resource_group_location" {
type = "string"
}

variable "service_principal_id" {
type = "string"
}
Expand Down
3 changes: 1 addition & 2 deletions cluster/environments/azure-common-infra/vnet.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ module "vnet" {
address_space = "${var.address_space}"
subnet_prefixes = ["${var.subnet_prefix}"]

resource_group_name = "${azurerm_resource_group.global_rg.name}"
resource_group_location = "${azurerm_resource_group.global_rg.location}"
resource_group_name = "${data.azurerm_resource_group.global_rg.name}"
subnet_names = ["${var.subnet_name}"]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ The template also creates an API management service which is an enterprise grade
You can deploy the `azure-multiple-cluster-waf-tm-apimgmt` using a Service Principal that has Owner privileges on the Azure Subscription.
To deploy this environment, follow the [common steps](https://github.com/microsoft/bedrock/blob/master/cluster/azure) for deploying a cluster with the following modifications:

## Resource Group Requirement

The Azure Multiple Container w/ API Management and WAF environment requires the creation of a resource group per cluster deployment as well as a resource group for traffic manager. The current set of groups that need to be created and the requisite variables are:

- Central US Cluster - `central_resource_group_name`
- East US Cluster - `east_resource_group_name`
- West US Cluster - `west_resource_group_name`
- Traffice Manager - `traffic_manager_resource_group_name`

To use the Azure CLI to create the resource group, see [here](../../azure/README.md).

# Getting Started

Expand All @@ -23,14 +33,12 @@ To deploy this environment, follow the [common steps](https://github.com/microso
* Application Gateway configuration
- `Prefix`: prefix to be added in web application firewall name service.
- `location`: Azure Region for web application firewall
- `resource_group_name_<region>`: Name of the resource group for the Web application firewall.
- `vnet_<region>`: virtual network location for Web application firewall.

* Traffic Manager configuration
- `traffic_manager_profile_name`: Name of the Azure Traffic Manager Profile.
- `traffic_manager_dns_name`: DNS name for accessing the traffic manager url from the internet. For ex: `http://<dnsname>.trafficmanager.net`.
- `traffic_manager_resource_group_name`: Name of the resource group for the Traffic Manager.
- `traffic_manager_resource_group_location`: Azure region the Traffic Manager resource group.
* Common configuration for all Kubernetes clusters
- `cluster_name`: The name of the Kubernetes cluster. The location will be added as a suffix.
- `agent_vm_count`: The number of agents VMs in the the node pool.
Expand All @@ -43,15 +51,12 @@ To deploy this environment, follow the [common steps](https://github.com/microso
- `gitops_ssh_key`: Path to the *private key file* that was configured to work with the GitOps repository.
* West Cluster
- `west_resource_group_name`: Name of the resource group for the cluster.
- `west_resource_group_location`: Location of the Azure region. For ex: `westus2`.
- `gitops_west_path`: Path to a subdirectory, or folder in a git repo
* Central cluster
- `central_resource_group_name`: Name of the resource group for the cluster.
- `central_resource_group_location`: Location of the Azure region. For ex: `centralus`.
- `gitops_central_path`: Path to a subdirectory, or folder in a git repo
* East Cluster
- `east_resource_group_name`: Name of the resource group for the cluster.
- `east_resource_group_locatio`: Location of the Azure region. For ex: `eastus2`.
- `gitops_east_path`: Path to a subdirectory, or folder in a git repo
3. Configure Terraform backend. It is optional, but a best practice for production environments

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ variable "central_resource_group_name" {
type = "string"
}

variable "central_resource_group_location" {
type = "string"
}

variable "gitops_central_path" {
type = "string"
}
Expand Down
Loading

0 comments on commit 6e0bb1d

Please sign in to comment.