Skip to content

Commit

Permalink
Merge branch 'feature/WIP_terraform_app'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Rainey committed Mar 27, 2019
2 parents 08b8f6f + 28f797a commit eb441b4
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -328,3 +328,15 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# VSCode Files
.vscode/

# Terraform Files
**/.terraform/
**/terraform.tfstate.*
**/terraform.tfstate
**/.terraform.tfstate.lock.info

# ENV files
**/.env
116 changes: 116 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,118 @@
<<<<<<< HEAD

# Setup

The artifacts used to deploy this project include bash scripts and Terraform templates. The sections below provide guidance to deploy this project into your Azure environment.

> The setup instructions below assume the following requirements:
> - bash v4.0 (or newer)
> - **NOTE FOR MAC!** The default version of bash installed on Mac is older than 4.0. Be sure to update bash using brew before executing the script. Instructions to update bash can be found [here](http://macappstore.org/bash/).
> - Terraform v0.11.13 (or newer)

## Setup the Azure Container Registry and Service Principals

1. Open a bash command prompt.
2. Navigate to the `./setup` folder.
3. Run `acr-sp-init.sh`. For example, the command below will provdision an Azure Container Registry (ACR) in East US and configure the two service principals in Azure Active Directory; one with AcrPush permission and another with AcrPull permission scoped to the ACR. The company name parameter ( `-c` ) is used to construct the name of the resource group, ACR, and service principals.

``` bash
$ ./acr-sp-init.sh -c Cobalt -l eastus
```

> Note: The script configures service principals in Azure AD and therefore requires elevated privileges. As such, it is recommended that an interactive user with permissions to configure Azure AD run the script.


## Setup Shared / Core Infrastructure

### Requirements

- Azure Subscription User (with deployment rights)
- [Terraform](https://www.terraform.io/downloads.html)

### Resources

The following respources will be deployed
- Azure Resource Group

### Deployment

1. Authenticate using your Azure Principal or an Azure account with privileges to deploy resource groups.

``` bash
$ az login
```

2. Execute the following commands:

``` bash
$ cd ./shared
$ terraform init
$ terraform apply
```

### Environmental Variables

To stop the command line from prompting questions use a .env file with the following environmental variables:

```
export TF_VAR_app_name=cblt
export TF_VAR_org=cse
export TF_VAR_env=dev
export TF_VAR_location=eastus
```
After saving the file set environment using:
``` bash
. .env
```

Alternative use the variable.tf files in the directories and add the default key on the file as shown on the example below:

``` json
variable "location" {
type = "string"
description = "The name of the target location"
default = "eastus"
}
variable "env" {
type = "string",
description = "The short name of the target env (i.e. dev, staging, or prod)"
defailt = "dev"
}
variable "org" {
type = "string",
description = "The short name of the organization"
default = "cse"
}
variable "app_name" {
type = "string",
description = "The short name of the application"
default = "cblt"
}

```

## Setup Application Infrastructure

> Coming soon!

# Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
=======

# Setup

Expand Down Expand Up @@ -44,3 +159,4 @@ provided by the bot. You will only need to do this once across all repos using o
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
>>>>>>> master
70 changes: 70 additions & 0 deletions shared/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Infrastructure deployment

## Requirements

- Azure Subscription User (with deployment rights)
- [Terraform](https://www.terraform.io/downloads.html)

## Resources

The following respources will be deployed
- Azure Resource Group

## Deployment

1. Authenticate using your Azure Principal or an Azure account with privileges to deploy resource groups.

``` bash
$ az login
```

2. Execute the following commands:

``` bash
$ cd ./shared
$ terraform init
$ terraform apply
```

## Environmental Variables

To stop the command line from prompting questions use a .env file with the following environmental variables:

```
export TF_VAR_app_name=cblt
export TF_VAR_org=cse
export TF_VAR_env=dev
export TF_VAR_location=eastus
```

After saving the file set environment using:

``` bash
. .env
```

Alternative use the variable.tf files in the directories and add the default key on the file as shown on the example below:

``` json
variable "location" {
type = "string"
description = "The name of the target location"
default = "eastus"
}
variable "env" {
type = "string",
description = "The short name of the target env (i.e. dev, staging, or prod)"
defailt = "dev"
}
variable "org" {
type = "string",
description = "The short name of the organization"
default = "cse"
}
variable "app_name" {
type = "string",
description = "The short name of the application"
default = "cblt"
}

```
11 changes: 11 additions & 0 deletions shared/azure/provider/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
provider "azurerm" {
version = "~>1.21.0"
}

provider "null" {
version = "~>2.0.0"
}

terraform {
required_version = "~> 0.11.11"
}
47 changes: 47 additions & 0 deletions shared/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module "azure-provider" {
source = "./azure/provider"
}

locals {
location_suffixes = {
eastasia = "asea",
southeastasia = "assw",
centralus = "usce",
eastus = "usea",
eastus2 = "use2",
westus = "uswe",
westus2 = "usw2",
northcentralus = "usnc",
southcentralus = "ussc",
westcentralus = "uswc",
northeurope = "euno",
westeurope = "euwe",
japanwest = "jawe",
japaneast = "jaea",
brazilsouth = "brso",
australiaeast = "auea",
australiasoutheast = "ause",
southindia = "inso",
centralindia = "ince",
westindia = "inwe",
canadacentral = "cace",
canadaeast = "caea",
uksouth = "ukso",
ukwest = "ukwe",
koreacentral = "koce",
koreasouth = "koso",
francecentral = "frce",
francesouth = "frso",
australiacentral = "auce",
australiacentral2 = "auc2",
southafricanorth= "sano",
southafricawest = "sawe",
}
location_suffix = "${local.location_suffixes[var.location]}"
suffix = "${var.app_name}-${var.env}-${local.location_suffix}-${var.org}"
}

resource "azurerm_resource_group" "rg_core" {
name = "rg-${local.suffix}"
location = "${var.location}"
}
17 changes: 17 additions & 0 deletions shared/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "location" {
type = "string"
description = "The name of the target location"
}
variable "env" {
type = "string",
description = "The short name of the target env (i.e. dev, staging, or prod)"
}
variable "org" {
type = "string",
description = "The short name of the organization"
}
variable "app_name" {
type = "string",
description = "The short name of the application"
}

0 comments on commit eb441b4

Please sign in to comment.