Skip to content

Commit 342eb62

Browse files
committed
Terraform Tutorial Azure
1 parent 3b490dd commit 342eb62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2417
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Terraform Apply
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
terraform:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
ARM_CLIENT_ID: ${{secrets.ARM_CLIENT_ID}}
14+
ARM_CLIENT_SECRET: ${{secrets.MYSUPERSECRETE}}
15+
ARM_SUBSCRIPTION_ID: ${{secrets.MYSBSCRIPTIONID}}
16+
ARM_TENANT_ID: ${{secrets.ARM_TENANT_ID}}
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Terraform
22+
uses: hashicorp/setup-terraform@v1
23+
24+
- name: Terraform Init
25+
run: terraform init
26+
27+
- name: Terraform Apply
28+
run: terraform apply -auto-approve
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Terraform Plan
2+
3+
on:
4+
push:
5+
branches:
6+
- FeatureBranch1
7+
8+
jobs:
9+
terraform:
10+
runs-on: ubuntu-latest
11+
12+
env:
13+
ARM_CLIENT_ID: ${{secrets.ARM_CLIENT_ID}}
14+
ARM_CLIENT_SECRET: ${{secrets.MYSUPERSECRETE}}
15+
ARM_SUBSCRIPTION_ID: ${{secrets.MYSBSCRIPTIONID}}
16+
ARM_TENANT_ID: ${{secrets.ARM_TENANT_ID}}
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Terraform
22+
uses: hashicorp/setup-terraform@v1
23+
24+
- name: Terraform Init
25+
run: terraform init
26+
27+
- name: Terraform Plan
28+
run: terraform plan

Terraform Tutorial Azure/AzureAPIM.tf

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
## RG creation
2+
resource "azurerm_resource_group" "CloudQuickPOCAPIMRG" {
3+
name = "CloudQuickPOCAPIMRG"
4+
location = "West Europe"
5+
}
6+
7+
## API Management creation
8+
resource "azurerm_api_management" "CloudQuickPOCAPIM" {
9+
name = "CloudQuickPOCsPIM"
10+
location = azurerm_resource_group.CloudQuickPOCAPIMRG.location
11+
resource_group_name = azurerm_resource_group.CloudQuickPOCAPIMRG.name
12+
publisher_name = "CloudQucikPOCs"
13+
publisher_email = "[email protected]"
14+
15+
sku_name = "Developer_1"
16+
}
17+
18+
## An API within APIM
19+
resource "azurerm_api_management_api" "CloudQuickPOCAPIMAPI" {
20+
name = "cloudquickpocsapim-api"
21+
resource_group_name = azurerm_resource_group.CloudQuickPOCAPIMRG.name
22+
api_management_name = azurerm_api_management.CloudQuickPOCAPIM.name
23+
revision = "1"
24+
display_name = "CloudQuickPOCsFirstAPI"
25+
path = ""
26+
protocols = ["https", "http"]
27+
service_url = "http://conferenceapi.azurewebsites.net"
28+
29+
import {
30+
content_format = "swagger-link-json"
31+
content_value = "http://conferenceapi.azurewebsites.net/?format=json"
32+
}
33+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Create Azure RG
2+
resource "azurerm_resource_group" "ABS" {
3+
name = "cloudquickpocs-Bastion-resources"
4+
location = "West Europe"
5+
}
6+
7+
# Create Azure Vnet
8+
resource "azurerm_virtual_network" "ABS" {
9+
name = "bastiondemovnet"
10+
address_space = ["192.168.1.0/24"]
11+
location = azurerm_resource_group.ABS.location
12+
resource_group_name = azurerm_resource_group.ABS.name
13+
}
14+
15+
# Create Azure subnet
16+
resource "azurerm_subnet" "ABS" {
17+
name = "AzureBastionSubnet"
18+
resource_group_name = azurerm_resource_group.ABS.name
19+
virtual_network_name = azurerm_virtual_network.ABS.name
20+
address_prefixes = ["192.168.1.224/27"]
21+
}
22+
23+
# Create Azure public IP
24+
resource "azurerm_public_ip" "ABS" {
25+
name = "bastiondemovnetpip"
26+
location = azurerm_resource_group.ABS.location
27+
resource_group_name = azurerm_resource_group.ABS.name
28+
allocation_method = "Static"
29+
sku = "Standard"
30+
}
31+
32+
# Create Azure bastion
33+
resource "azurerm_bastion_host" "ABS" {
34+
name = "cqpocsbastionfordemo"
35+
location = azurerm_resource_group.ABS.location
36+
resource_group_name = azurerm_resource_group.ABS.name
37+
38+
ip_configuration {
39+
name = "configuration"
40+
subnet_id = azurerm_subnet.ABS.id
41+
public_ip_address_id = azurerm_public_ip.ABS.id
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Create Azure RG
2+
resource "azurerm_resource_group" "rg" {
3+
name = "cloudquickpocscosmosdbrg"
4+
location = "East US"
5+
}
6+
7+
# Create Azure Cosmos DB Account
8+
resource "azurerm_cosmosdb_account" "acc" {
9+
name = "cloudquickpocscosmosdbaccount"
10+
location = "${azurerm_resource_group.rg.location}"
11+
resource_group_name = "${azurerm_resource_group.rg.name}"
12+
offer_type = "Standard"
13+
kind = "GlobalDocumentDB"
14+
enable_automatic_failover = true
15+
consistency_policy {
16+
consistency_level = "Session"
17+
}
18+
19+
geo_location {
20+
location = "West US"
21+
failover_priority = 1
22+
}
23+
geo_location {
24+
location = "${azurerm_resource_group.rg.location}"
25+
failover_priority = 0
26+
}
27+
}
28+
29+
# Azure Cosmos DB database
30+
resource "azurerm_cosmosdb_sql_database" "db" {
31+
name = "products"
32+
resource_group_name = "${azurerm_cosmosdb_account.acc.resource_group_name}"
33+
account_name = "${azurerm_cosmosdb_account.acc.name}"
34+
}
35+
36+
#Azure Cosmos DB database container
37+
resource "azurerm_cosmosdb_sql_container" "coll" {
38+
name = "Devices"
39+
resource_group_name = "${azurerm_cosmosdb_account.acc.resource_group_name}"
40+
account_name = "${azurerm_cosmosdb_account.acc.name}"
41+
database_name = "${azurerm_cosmosdb_sql_database.db.name}"
42+
partition_key_path = "/Devices"
43+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
provider "azurerm" {
2+
# The "feature" block is required for AzureRM provider 2.x.
3+
# If you're using version 1.x, the "features" block is not allowed.
4+
version = "~>2.0"
5+
features {}
6+
subscription_id = "YOUR_SUBSCRIPTION_ID"
7+
client_id = "YOUR_SPN_CLIENT_ID"
8+
client_secret = "YOUR_SPN_CLIENT_SECRETE"
9+
tenant_id = "YOUR_TENANT_ID"
10+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
#Create Custom RBAC using Terrafrom - CloudQuickPOCS
3+
resource "azurerm_role_definition" "CloudQuickPOCCustomRBAC" {
4+
name = "POC-Custom-RBAC"
5+
scope = "/subscriptions/49d3ec60-54b5-41c0-b240-c0cc7980a4f4"
6+
description = "Created for demo at CLoudQuickPOCs"
7+
8+
permissions {
9+
actions = [
10+
"Microsoft.Support/*"
11+
]
12+
not_actions = [
13+
14+
]
15+
}
16+
17+
assignable_scopes = [
18+
"/subscriptions/49d3ec60-54b5-41c0-b240-c0cc7980a4f4"
19+
]
20+
}
21+
22+
23+
#Assign Custom RBAC using Terrafrom - CloudQuickPOCS
24+
resource "azurerm_role_assignment" "CloudQuickPOCCustomRBACAssignment" {
25+
scope = "/subscriptions/49d3ec60-54b5-41c0-b240-c0cc7980a4f4"
26+
role_definition_id = azurerm_role_definition.CloudQuickPOCCustomRBAC.role_definition_resource_id
27+
principal_id = "ce85eae4-0769-4f77-b1b8-a253f34a6160"
28+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
#Create Custom RBAC using Terrafrom - CloudQuickPOCS
3+
Get-AzProviderOperation "Microsoft.Storage/*" | Select-Object OperationName, Operation, Description
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#Terraform Provider Block - CloudQuickPOCS
2+
provider "azurerm" {
3+
# The "feature" block is required for AzureRM provider 2.x.
4+
# If you're using version 1.x, the "features" block is not allowed.
5+
version = "~>2.0"
6+
features {}
7+
subscription_id = "your subscription_id"
8+
client_id = "your spn client id"
9+
client_secret = "your spn secrete"
10+
tenant_id = "your tenant id"
11+
}
Binary file not shown.

0 commit comments

Comments
 (0)