-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add module and Fix #36
- Loading branch information
Showing
11 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Module:powerbi-embedded | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
branches: | ||
- main | ||
paths: | ||
- '.github/workflows/powerbi-embedded.yml' | ||
- 'terraform/powerbi-embedded/**' | ||
- '.github/actions/**' | ||
|
||
env: | ||
terraform_workingdir: "terraform/powerbi-embedded" | ||
GH_TOKEN: ${{ secrets.GH_TOKEN }} | ||
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }} | ||
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }} | ||
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }} | ||
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }} | ||
|
||
jobs: | ||
terraform-lint: | ||
name: Run Terraform lint | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: "${{ env.terraform_workingdir }}" | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: hashicorp/setup-terraform@v2 | ||
|
||
- name: Terraform fmt | ||
id: fmt | ||
run: terraform fmt -check | ||
continue-on-error: false | ||
|
||
terraform-sec: | ||
name: Run Terraform tfsec | ||
needs: | ||
- terraform-lint | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@main | ||
|
||
- name: Run tfsec with reviewdog output on the PR | ||
uses: ./.github/actions/run-terraform-sec | ||
|
||
terratest: | ||
name: Run Terratest | ||
needs: | ||
- terraform-sec | ||
runs-on: ubuntu-latest | ||
|
||
defaults: | ||
run: | ||
working-directory: "${{ env.terraform_workingdir }}/test" | ||
|
||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.18.2 | ||
|
||
- name: Setup Dependencies | ||
run: go mod init test && go mod tidy | ||
env: | ||
GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" | ||
|
||
- name: Unit-test | ||
run: go test -v -timeout 45m | ||
env: | ||
GOPATH: "/home/runner/work/azure-labs-modules/azure-labs-modules/${{ env.terraform_workingdir }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/powerbi_embedded | ||
|
||
locals { | ||
safe_basename = replace(var.basename, "-", "") | ||
} | ||
|
||
resource "azurerm_powerbi_embedded" "adl_pbi" { | ||
name = "pbi${local.safe_basename}" | ||
location = var.location | ||
resource_group_name = var.rg_name | ||
sku_name = var.sku_name | ||
|
||
administrators = var.administrators | ||
mode = var.mode | ||
|
||
count = var.module_enabled ? 1 : 0 | ||
tags = var.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
output "id" { | ||
value = ( | ||
length(azurerm_powerbi_embedded.adl_pbi) > 0 ? | ||
azurerm_powerbi_embedded.adl_pbi[0].id : "" | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
locals { | ||
tags = { | ||
Project = "Azure/azure-data-labs-modules" | ||
Module = "powerbi-embedded" | ||
Toolkit = "Terraform" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "id" { | ||
value = module.powerbi_embedded.id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module "powerbi_embedded" { | ||
source = "../" | ||
|
||
basename = random_string.postfix.result | ||
rg_name = module.local_rg.name | ||
location = var.location | ||
|
||
administrators = ["aimurg@microsoft.com"] | ||
|
||
tags = {} | ||
} | ||
|
||
# Modules dependencies | ||
|
||
module "local_rg" { | ||
source = "../../resource-group" | ||
|
||
basename = random_string.postfix.result | ||
location = var.location | ||
|
||
tags = local.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
terraform { | ||
backend "azurerm" { | ||
resource_group_name = "rg-adl-terraform-state" | ||
storage_account_name = "stadltfstate" | ||
container_name = "default" | ||
key = "powerbiembedded.terraform.tfstate" | ||
} | ||
|
||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "= 3.36.0" | ||
} | ||
} | ||
|
||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestModule(t *testing.T) { | ||
t.Parallel() | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./", | ||
// VarFiles: []string{"terraform_unitest.tfvars"}, | ||
} | ||
|
||
// At the end of the test, run `terraform destroy` to clean up any resources that were created | ||
defer terraform.Destroy(t, terraformOptions) | ||
|
||
// Is used mainly for debugging, fail early if plan is not possible | ||
terraform.InitAndPlan(t, terraformOptions) | ||
|
||
// This will run `terraform init` and `terraform apply` and fail the test if there are any errors | ||
terraform.InitAndApply(t, terraformOptions) | ||
|
||
// Check if the outputs exist | ||
assert := assert.New(t) | ||
id := terraform.Output(t, terraformOptions, "id") | ||
assert.NotNil(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
resource "random_string" "postfix" { | ||
length = 8 | ||
special = false | ||
upper = false | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
default = "North Europe" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
variable "basename" { | ||
type = string | ||
description = "Basename of the module" | ||
} | ||
|
||
variable "rg_name" { | ||
type = string | ||
description = "Resource group name" | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
description = "Location of the resource group" | ||
} | ||
|
||
variable "tags" { | ||
type = map(string) | ||
default = {} | ||
description = "A mapping of tags which should be assigned to the deployed resource" | ||
} | ||
|
||
variable "module_enabled" { | ||
type = bool | ||
description = "Variable to enable or disable the module" | ||
default = true | ||
} | ||
|
||
variable "sku_name" { | ||
type = string | ||
description = "Sets the PowerBI Embedded's pricing level's SKU" | ||
default = "A1" | ||
} | ||
|
||
variable "administrators" { | ||
type = list(string) | ||
description = "A set of administrator user identities, which manages the Power BI Embedded and must be a member user or a service principal in your AAD tenant" | ||
} | ||
|
||
variable "mode" { | ||
type = string | ||
description = "Sets the PowerBI Embedded's mode" | ||
default = "Gen1" | ||
} |