Skip to content

Commit

Permalink
Support terraform to run in Powershell. (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
hui1110 authored Feb 8, 2022
1 parent fa6ba6e commit 16be0a4
Show file tree
Hide file tree
Showing 59 changed files with 769 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ After login Azure CLI with your account, now you can use the terraform script to

Now you can use the terraform script to create Azure Resources.

#### Run with Bash

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
Expand All @@ -74,6 +76,18 @@ terraform -chdir=./terraform init
terraform -chdir=./terraform apply -auto-approve
```

#### Run with Powershell

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=terraform init

# Apply your Terraform Configuration
terraform -chdir=terraform apply -auto-approve

```

It may take around 15 minutes to run the script. After successful running, you will see prompt information like below:

```shell
Expand All @@ -97,10 +111,18 @@ You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser t
### Export Output to Your Local Environment
Running the command below to export environment values:

#### Run with Bash

```shell
source ./terraform/setup_env.sh
```

#### Run with Powershell

```shell
. terraform\setup_env.ps1
```

## Run Locally

In your terminal, run `mvn clean spring-boot:run`.
Expand Down Expand Up @@ -129,6 +151,14 @@ After running the sample, if you don't want to run the sample, remember to destr
The terraform destroy command terminates resources managed by your Terraform project.
To destroy the resources you created.

#### Run with Bash

```shell
terraform -chdir=./terraform destroy -auto-approve
```

#### Run with Powershell

```shell
terraform -chdir=terraform destroy -auto-approve
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$env:AZURE_SUBSCRIPTION_ID=$(terraform -chdir=terraform output -raw AZURE_SUBSCRIPTION_ID)
$env:AZURE_RESOURCE_GROUP=$(terraform -chdir=terraform output -raw AZURE_RESOURCE_GROUP)
$env:AZURE_CACHE_REDIS_NAME=$(terraform -chdir=terraform output -raw AZURE_CACHE_REDIS_NAME)

echo AZURE_SUBSCRIPTION_ID=$env:AZURE_SUBSCRIPTION_ID
echo AZURE_RESOURCE_GROUP=$env:AZURE_RESOURCE_GROUP
echo AZURE_CACHE_REDIS_NAME=$env:AZURE_CACHE_REDIS_NAME
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export AZURE_SUBSCRIPTION_ID=$(terraform -chdir=./terraform output -raw AZURE_SUBSCRIPTION_ID)
export AZURE_RESOURCE_GROUP=$(terraform -chdir=./terraform output -raw AZURE_RESOURCE_GROUP)
export AZURE_CACHE_REDIS_NAME=$(terraform -chdir=./terraform output -raw AZURE_CACHE_REDIS_NAME)

echo AZURE_SUBSCRIPTION_ID=$AZURE_SUBSCRIPTION_ID
echo AZURE_RESOURCE_GROUP=$AZURE_RESOURCE_GROUP
echo AZURE_CACHE_REDIS_NAME=$AZURE_CACHE_REDIS_NAME
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ az account set --subscription <your-subscription-id>

After login Azure CLI with your account, now you can use the terraform script to create Azure Resources.

#### Run with Bash

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
Expand All @@ -72,6 +74,18 @@ terraform -chdir=./terraform apply -auto-approve

```

#### Run with Powershell

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=terraform init

# Apply your Terraform Configuration
terraform -chdir=terraform apply -auto-approve

```

It may take a few minutes to run the script. After successful running, you will see prompt information like below:

```shell
Expand Down Expand Up @@ -99,10 +113,18 @@ You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser t
### Export Output to Your Local Environment
Running the command below to export environment values:

#### Run with Bash

```shell
source ./terraform/setup_env.sh
```

#### Run with Powershell

```shell
. terraform\setup_env.ps1
```

## Run Locally

In your terminal, run `mvn clean spring-boot:run`.
Expand Down Expand Up @@ -133,6 +155,14 @@ After running the sample, if you don't want to run the sample, remember to destr
The terraform destroy command terminates resources managed by your terraform project.
To destroy the resources you created.

#### Run with Bash

```shell
terraform -chdir=./terraform destroy -auto-approve
```

#### Run with Powershell

```shell
terraform -chdir=terraform destroy -auto-approve
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ output "azure_cosmos_account" {
description = "Azure Cosmos DB account created."
}

output "resource_group_name" {
value = azurerm_resource_group.main.name
description = "The Azure resource group name."
}

output "cosmos_application_id" {
value = azurerm_cosmosdb_account.application.id
description = "Azure Cosmos DB account application id."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
$env:AZURE_COSMOS_ENDPOINT=$(terraform -chdir=terraform output -raw azure_cosmos_endpoint)
$azure_cosmos_account=$(terraform -chdir=terraform output -raw azure_cosmos_account)
# resourceGroupName
$resourceGroupName=$(terraform -chdir=terraform output -raw resource_group_name)
$principalId=$(terraform -chdir=terraform output -raw object_id)
$readOnlyRoleDefinitionId=$(terraform -chdir=terraform output -raw cosmos_application_id)+"/sqlRoleDefinitions/00000000-0000-0000-0000-000000000001"
$writeOnlyRoleDefinitionId=$(terraform -chdir=terraform output -raw cosmos_application_id)+"/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002"
# assign current Cosmos DB Built-in Data Reader
# https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#using-the-azure-cli-1
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $readOnlyRoleDefinitionId
# assign current Cosmos DB Built-in Data Contributor
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId

echo AZURE_COSMOS_ENDPOINT=$env:AZURE_COSMOS_ENDPOINT
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ writeOnlyRoleDefinitionId=$(terraform -chdir=./terraform output -raw cosmos_appl
# https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#using-the-azure-cli-1
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $readOnlyRoleDefinitionId
# assign current Cosmos DB Built-in Data Contributor
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId

echo AZURE_COSMOS_ENDPOINT=$AZURE_COSMOS_ENDPOINT
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ az account set --subscription <your-subscription-id>

After login Azure CLI with your account, now you can use the terraform script to create Azure Resources.

#### Run with Bash

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
Expand All @@ -71,6 +73,17 @@ terraform -chdir=./terraform apply -auto-approve

```

#### Run with Powershell

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=terraform init

# Apply your Terraform Configuration
terraform -chdir=terraform apply -auto-approve

```

It may take a few minutes to run the script. After successful running, you will see prompt information like below:

Expand Down Expand Up @@ -100,10 +113,18 @@ You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser t
### Export Output to Your Local Environment
Running the command below to export environment values:

#### Run with Bash

```shell
source ./terraform/setup_env.sh
```

#### Run with Powershell

```shell
. terraform\setup_env.ps1
```

## Run Locally

In your terminal, run `mvn clean spring-boot:run`.
Expand Down Expand Up @@ -131,6 +152,14 @@ After running the sample, if you don't want to run the sample, remember to destr
The terraform destroy command terminates resources managed by your Terraform project.
To destroy the resources you created.

#### Run with Bash

```shell
terraform -chdir=./terraform destroy -auto-approve
```

#### Run with Powershell

```shell
terraform -chdir=terraform destroy -auto-approve
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ output "azure_cosmos_account" {
description = "Azure Cosmos DB account created."
}

output "resource_group_name" {
value = azurerm_resource_group.main.name
description = "The Azure resource group name."
}

output "cosmos_application_id" {
value = azurerm_cosmosdb_account.application.id
description = "Cosmos account application id."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$env:AZURE_COSMOS_ENDPOINT=$(terraform -chdir=terraform output -raw azure_cosmos_endpoint)
$env:COSMOS_DATABASE=$(terraform -chdir=terraform output -raw cosmos_database_name)
$azure_cosmos_account=$(terraform -chdir=terraform output -raw azure_cosmos_account)

# resourceGroupName
$resourceGroupName=$(terraform -chdir=terraform output -raw resource_group_name)
$principalId=$(terraform -chdir=terraform output -raw object_id)
$readOnlyRoleDefinitionId=$(terraform -chdir=terraform output -raw cosmos_application_id)+"/sqlRoleDefinitions/00000000-0000-0000-0000-000000000001"
$writeOnlyRoleDefinitionId=$(terraform -chdir=terraform output -raw cosmos_application_id)+"/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002"
# assign current Cosmos DB Built-in Data Reader
# https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#using-the-azure-cli-1
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $readOnlyRoleDefinitionId
# assign current Cosmos DB Built-in Data Contributor
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId

echo AZURE_COSMOS_ENDPOINT=$env:AZURE_COSMOS_ENDPOINT
echo COSMOS_DATABASE=$env:COSMOS_DATABASE
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ writeOnlyRoleDefinitionId=$(terraform -chdir=./terraform output -raw cosmos_appl
# https://docs.microsoft.com/azure/cosmos-db/how-to-setup-rbac#using-the-azure-cli-1
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $readOnlyRoleDefinitionId
# assign current Cosmos DB Built-in Data Contributor
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId
az cosmosdb sql role assignment create --account-name $azure_cosmos_account --resource-group $resourceGroupName --scope "/" --principal-id $principalId --role-definition-id $writeOnlyRoleDefinitionId

echo AZURE_COSMOS_ENDPOINT=$AZURE_COSMOS_ENDPOINT
echo COSMOS_DATABASE=$COSMOS_DATABASE
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ az account set --subscription <your-subscription-id>

After login Azure CLI with your account, now you can use the terraform script to create Azure Resources.

#### Run with Bash

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
Expand All @@ -72,8 +74,17 @@ terraform -chdir=./terraform apply -auto-approve

```

#### Run with Powershell

```shell
# In the root directory of the sample
# Initialize your Terraform configuration
terraform -chdir=terraform init

# Apply your Terraform Configuration
terraform -chdir=terraform apply -auto-approve

```

It may take a few minutes to run the script. After successful running, you will see prompt information like below:

Expand Down Expand Up @@ -113,10 +124,18 @@ You can go to [Azure portal](https://ms.portal.azure.com/) in your web browser t
### Export Output to Your Local Environment
Running the command below to export environment values:

#### Run with Bash

```shell
source ./terraform/setup_env.sh
```

#### Run with Powershell

```shell
. terraform\setup_env.ps1
```

## Run Locally

In your terminal, run `mvn clean spring-boot:run`.
Expand Down Expand Up @@ -149,10 +168,18 @@ After running the sample, if you don't want to run the sample, remember to destr
The terraform destroy command terminates resources managed by your Terraform project.
To destroy the resources you created.

#### Run with Bash

```shell
terraform -chdir=./terraform destroy -auto-approve
```

#### Run with Powershell

```shell
terraform -chdir=terraform destroy -auto-approve
```




Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$env:AZURE_EVENTHUBS_NAMESPACE=$(terraform -chdir=terraform output -raw AZURE_EVENTHUBS_NAMESPACE)
$env:AZURE_STORAGE_CONTAINER_NAME=$(terraform -chdir=terraform output -raw AZURE_STORAGE_CONTAINER_NAME)
$env:AZURE_STORAGE_ACCOUNT_NAME=$(terraform -chdir=terraform output -raw AZURE_STORAGE_ACCOUNT_NAME)

echo AZURE_EVENTHUBS_NAMESPACE=$env:AZURE_EVENTHUBS_NAMESPACE
echo AZURE_STORAGE_CONTAINER_NAME=$env:AZURE_STORAGE_CONTAINER_NAME
echo AZURE_STORAGE_ACCOUNT_NAME=$env:AZURE_STORAGE_ACCOUNT_NAME
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export AZURE_EVENTHUBS_NAMESPACE=$(terraform -chdir=./terraform output -raw AZURE_EVENTHUBS_NAMESPACE)
export AZURE_STORAGE_CONTAINER_NAME=$(terraform -chdir=./terraform output -raw AZURE_STORAGE_CONTAINER_NAME)
export AZURE_STORAGE_ACCOUNT_NAME=$(terraform -chdir=./terraform output -raw AZURE_STORAGE_ACCOUNT_NAME)
export AZURE_STORAGE_ACCOUNT_NAME=$(terraform -chdir=./terraform output -raw AZURE_STORAGE_ACCOUNT_NAME)

echo AZURE_EVENTHUBS_NAMESPACE=$AZURE_EVENTHUBS_NAMESPACE
echo AZURE_STORAGE_CONTAINER_NAME=$AZURE_STORAGE_CONTAINER_NAME
echo AZURE_STORAGE_ACCOUNT_NAME=$AZURE_STORAGE_ACCOUNT_NAME
Loading

0 comments on commit 16be0a4

Please sign in to comment.