Skip to content
This repository was archived by the owner on Mar 16, 2022. It is now read-only.

Commit 80dea0a

Browse files
committed
Merge branch 'master' into develop/v1-attribute
2 parents bc726ac + 05623a9 commit 80dea0a

File tree

125 files changed

+1999
-54
lines changed

Some content is hidden

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

125 files changed

+1999
-54
lines changed

.circleci/config.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: microsoft/dotnet:sdk
6+
working_directory: ~/AzureFunctionsIntroduction
7+
steps:
8+
- checkout
9+
- restore_cache:
10+
keys:
11+
- v1-nuget-cache-{{ arch }}-{{ .Branch }}-{{ checksum "v2/src/AzureFunctionsIntroduction/AzureFunctionsIntroduction.csproj" }}
12+
- run:
13+
name: Restore nuget
14+
command: dotnet restore
15+
working_directory: v2/src/AzureFunctionsIntroduction
16+
- save_cache:
17+
key: v1-nuget-cache-{{ arch }}-{{ .Branch }}-{{ checksum "v2/src/AzureFunctionsIntroduction/AzureFunctionsIntroduction.csproj" }}
18+
paths:
19+
- ~/.nuget
20+
- run:
21+
name: Build
22+
command: dotnet publish -c Release -o publish
23+
working_directory: v2/src/AzureFunctionsIntroduction
24+
25+
deploy:
26+
docker:
27+
- image: microsoft/dotnet:sdk
28+
working_directory: ~/AzureFunctionsIntroduction
29+
steps:
30+
- checkout
31+
- restore_cache:
32+
keys:
33+
- v1-nuget-cache-{{ arch }}-{{ .Branch }}-{{ checksum "v2/src/AzureFunctionsIntroduction/AzureFunctionsIntroduction.csproj" }}
34+
- run:
35+
name: Restore nuget
36+
command: dotnet restore
37+
working_directory: v2/src/AzureFunctionsIntroduction
38+
- save_cache:
39+
key: v1-nuget-cache-{{ arch }}-{{ .Branch }}-{{ checksum "v2/src/AzureFunctionsIntroduction/AzureFunctionsIntroduction.csproj" }}
40+
paths:
41+
- ~/.nuget
42+
- run:
43+
name: Build
44+
command: dotnet publish -c Release -o publish
45+
working_directory: v2/src/AzureFunctionsIntroduction
46+
- run:
47+
name: Install 7zip
48+
command: apt-get update && apt-get install -y p7zip-full
49+
- run:
50+
name: Pack to Zip
51+
command: 7z a artifact.zip ./publish/*
52+
working_directory: v2/src/AzureFunctionsIntroduction
53+
- run:
54+
name: Zipdeploy FunctionApp
55+
command: curl -X POST -u $SITE_USER:$SITE_PASS --data-binary @artifact.zip https://$FUNCTION_NAME.scm.azurewebsites.net/api/zipdeploy?isAsync=true
56+
working_directory: v2/src/AzureFunctionsIntroduction
57+
58+
workflows:
59+
version: 2
60+
build_V2:
61+
jobs:
62+
- build:
63+
filters:
64+
branches:
65+
only:
66+
- develop/v2
67+
build_and_deploy_v2:
68+
jobs:
69+
- deploy:
70+
filters:
71+
branches:
72+
only: release/v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,5 @@ launchSettings.json
272272
# Crash log files
273273
crash.log
274274

275-
.direnv
275+
.direnv
276+
appsettings.json

Terraform/README.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
## TL;DR
2+
3+
This terraform aim to run on both CloudShell and CI.
4+
5+
Environment | Description | Use case
6+
---- | ---- | ----
7+
CloudShell | Managed Console with MSI. | Each developer's cloud dev env.
8+
Local | az login credential | Each developer's local dev env.
9+
CI | Service Principal Id of application registration, terraform. | CI or any non-interactive env
10+
11+
## Notice
12+
13+
* terraform version : Will depends on what CloudShell supports. -> see terraform.tf
14+
* Env : ARM_ACCESS_KEY is required for terraform's backend blob authentication.
15+
* Env : ARM_USE_MSI will redirect your credential with local SP and CloudShell's MSI.
16+
17+
## Run on Local (already az login)
18+
19+
> SAMPLE : bashrc_local_azlogin
20+
21+
```bashrc
22+
export ARM_ACCESS_KEY=<....>
23+
export TF_VAR_SP_OBJECT_ID=<....>
24+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
25+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>
26+
```
27+
28+
29+
## Run on CI (service principal id for Terraform)
30+
31+
> SAMPLE : bashrc_serviceprincipal
32+
33+
```bashrc
34+
export ARM_ACCESS_KEY=<....>
35+
export ARM_SUBSCRIPTION_ID=<....>
36+
export ARM_CLIENT_ID=<....>
37+
export ARM_CLIENT_SECRET=<....>
38+
export ARM_TENANT_ID=<....>
39+
export TF_VAR_SP_OBJECT_ID=<....>
40+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
41+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>
42+
```
43+
44+
## Run on CloudShell
45+
46+
47+
[![Launch Cloud Shell](https://shell.azure.com/images/launchcloudshell.png "Launch Cloud Shell")](https://shell.azure.com)
48+
49+
### Prerequisite for CloudShell
50+
51+
Please create any blob storage you want to store your state.
52+
Run following at first time you logged in to CloudShell.
53+
54+
#### Public Repo
55+
56+
> SAMPLE : bashrc_cloudshell_public
57+
58+
```bashrc
59+
# load custom bashrc on startup
60+
$ echo "source bashrc" >> .bashrc
61+
$ cat << 'EOF' > bashrc
62+
export ARM_ACCESS_KEY=<....>
63+
export TF_VAR_SP_OBJECT_ID=<....>
64+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
65+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>
66+
EOF
67+
```
68+
69+
done! Let's try restart cloud shell.
70+
71+
#### Private Repo
72+
73+
if you are cloning from private repo, then use ssh auth.
74+
75+
> SAMPLE : bashrc_cloudshell_private
76+
77+
```bashrc
78+
# load custom bashrc on startup
79+
$ echo "source bashrc" >> .bashrc
80+
$ cat << 'EOF' > bashrc
81+
export ARM_ACCESS_KEY=<....>
82+
export TF_VAR_SP_OBJECT_ID=<....>
83+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
84+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>
85+
# ssh agent (for private repo only)
86+
eval $(ssh-agent -s)
87+
ssh-add .ssh/id_rsa
88+
ssh-add -l
89+
EOF
90+
```
91+
92+
Github Authentication with Generate SSH key.
93+
94+
> [Generating a new SSH key and adding it to the ssh-agent](https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/
95+
)
96+
97+
```shell
98+
$ ssh-keygen -t rsa -b 4096 -C "YOUR_USER_NAME@users.noreply.github.com"
99+
```
100+
101+
Copy ssh pub and paste to Github Public Key.
102+
103+
> https://github.com/YOUR_ACCOUNT/REPOSITORY/settings/keys
104+
105+
```bash
106+
$ cat ~/.ssh/id_rsa.pub
107+
```
108+
109+
done! Let's try restart cloud shell.
110+
You will find ssh-agen loaded with specified ssh key.
111+
112+
### Git Clone
113+
114+
Move to clouddrive and clone git repo.
115+
116+
```shell
117+
cd clouddrive
118+
```
119+
120+
* If you are using Public repo, you clone repo with https.
121+
* If you are using Private repo, you clone repo with ssh.
122+
123+
```shell
124+
$ git clone git clone https://github.com/guitarrapc/AzureFunctionsIntroduction.git
125+
```
126+
127+
You may required git config for git commit/push ops.
128+
129+
```
130+
$ git config --global user.name "John Doe"
131+
$ git config --global user.email johndoe@users.noreply.github.com
132+
```
133+
134+
## Terraform Ops
135+
136+
137+
move to repo's terraform directory.
138+
139+
```shell
140+
$ cd ~/clouddrive/AzureFunctionsIntroduction/Terraform/v2
141+
```
142+
143+
### tfstate Blob settings
144+
145+
If you chaned your blob, modify `terraform.tf` the remote state file.
146+
147+
```shell
148+
$ cat terraform.tf
149+
150+
terraform {
151+
required_version = "> 0.11.0"
152+
153+
backend "azurerm" {
154+
storage_account_name = "terraformguitarrapc"
155+
container_name = "azurefunctionsintroduction"
156+
key = "azure/v2/terraform.tfstate"
157+
resource_group_name = "terraform"
158+
}
159+
}
160+
```
161+
162+
### Terraform init
163+
164+
Operate with terraform init, plan, apply!
165+
166+
```shell
167+
$ terraform init
168+
169+
Initializing the backend...
170+
171+
Successfully configured the backend "azurerm"! Terraform will automatically
172+
use this backend unless the backend configuration changes.
173+
174+
Initializing provider plugins...
175+
- Checking for available provider plugins on https://releases.hashicorp.com...
176+
- Downloading plugin for provider "azurerm" (1.13.0)...
177+
178+
Terraform has been successfully initialized!
179+
180+
You may now begin working with Terraform. Try running "terraform plan" to see
181+
any changes that are required for your infrastructure. All Terraform commands
182+
should now work.
183+
184+
If you ever set or change modules or backend configuration for Terraform,
185+
rerun this command to reinitialize your working directory. If you forget, other
186+
commands will detect it and remind you to do so if necessary.
187+
```
188+
189+
190+
### Terraform plan and Apply
191+
192+
```shell
193+
$ terraform plan
194+
$ terraform apply
195+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export ARM_ACCESS_KEY=<....>
2+
export TF_VAR_SP_OBJECT_ID=<....>
3+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
4+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>
5+
# ssh agent (for private repo only)
6+
eval $(ssh-agent -s)
7+
ssh-add .ssh/id_rsa
8+
ssh-add -l

Terraform/bashrc_cloudshell_public

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ARM_ACCESS_KEY=<....>
2+
export TF_VAR_SP_OBJECT_ID=<....>
3+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
4+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>

Terraform/bashrc_local_azlogin

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export ARM_ACCESS_KEY=<....>
2+
export TF_VAR_SP_OBJECT_ID=<....>
3+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
4+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>

Terraform/bashrc_serviceprincipal

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export ARM_ACCESS_KEY=<....>
2+
export ARM_SUBSCRIPTION_ID=<....>
3+
export ARM_CLIENT_ID=<....>
4+
export ARM_CLIENT_SECRET=<....>
5+
export ARM_TENANT_ID=<....>
6+
export TF_VAR_SP_OBJECT_ID=<....>
7+
export TF_VAR_FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL=<....>
8+
export TF_VAR_FUNCTION_APP_SLACKINCOMINGWEBHOOKURL=<....>

Terraform/v1_attribute/datas.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ data "azurerm_resource_group" "current" {
1313
}
1414

1515
# key vault secret
16-
data "azurerm_key_vault_secret" "FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL" {
17-
name = "${azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL.name}"
18-
vault_uri = "${azurerm_key_vault.this.vault_uri}"
19-
}
16+
# data "azurerm_key_vault_secret" "FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL" {
17+
# name = "${azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL.name}"
18+
# vault_uri = "${azurerm_key_vault.this.vault_uri}"
19+
# }
20+
21+
22+
# data "azurerm_key_vault_secret" "FUNCTION_APP_SLACKINCOMINGWEBHOOKURL" {
23+
# name = "${azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL.name}"
24+
# vault_uri = "${azurerm_key_vault.this.vault_uri}"
25+
# }
2026

21-
data "azurerm_key_vault_secret" "FUNCTION_APP_SLACKINCOMINGWEBHOOKURL" {
22-
name = "${azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL.name}"
23-
vault_uri = "${azurerm_key_vault.this.vault_uri}"
24-
}

Terraform/v1_attribute/eventgrid.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
eventgrid_name = "eventgridtest"
2+
eventgrid_name = "function-v1-eventgrid"
33
}
44

55
resource "azurerm_resource_group" "eventgridtest" {

Terraform/v1_attribute/functionapp.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,17 @@ resource "azurerm_function_app" "function" {
3939
version = "~1"
4040

4141
app_settings {
42-
eventtrigger_slackchannel = "azurefunctions"
43-
eventtrigger_slackwebhookurl = "${data.azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL.value}"
44-
KeyVaultSecretUri = "${azurerm_key_vault.this.vault_uri}/secrets/${azurerm_key_vault_secret.test.name}"
45-
SlackIncomingWebhookUrl = "${data.azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL.value}"
42+
eventtrigger_slackchannel = "azurefunctions"
43+
eventtriggerSlackwebhookurlSecretUri = "${azurerm_key_vault.this.vault_uri}/secrets/${azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL.name}"
44+
KeyVaultSecretUri = "${azurerm_key_vault.this.vault_uri}/secrets/${azurerm_key_vault_secret.test.name}"
45+
slackIncomingWebhookUrlSecretUri = "${azurerm_key_vault.this.vault_uri}/secrets/${azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL.name}"
46+
47+
# eventtrigger_slackwebhookurl = "${data.azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL.value}"
48+
# SlackIncomingWebhookUrl = "${data.azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL.value}"
49+
}
50+
51+
identity = {
52+
type = "SystemAssigned"
4653
}
4754

4855
depends_on = ["azurerm_key_vault_secret.FUNCTION_APP_EVENTTRIGGER_SLACKWEBHOOKURL", "azurerm_key_vault_secret.FUNCTION_APP_SLACKINCOMINGWEBHOOKURL"]

0 commit comments

Comments
 (0)