Skip to content

Commit

Permalink
Test AI Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinbuss committed Oct 7, 2024
1 parent a4d1e36 commit a14a9ac
Show file tree
Hide file tree
Showing 7 changed files with 424 additions and 4 deletions.
239 changes: 239 additions & 0 deletions .github/workflows/_terraformEnvironmentTemplate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
name: Terraform Template

on:
workflow_call:
inputs:
environment:
required: true
type: string
description: "Specifies the environment of the deployment."
config:
required: true
type: string
description: "Specifies the configuration folder for the deployment."
terraform_version:
required: true
type: string
description: "Specifies the terraform version."
node_version:
required: true
type: number
description: "Specifies the node version."
working_directory:
required: true
type: string
description: "Specifies the working directory."
tenant_id:
required: true
type: string
description: "Specifies the tenant id of the deployment."
subscription_id:
required: true
type: string
description: "Specifies the subscription id of the deployment."
secrets:
CLIENT_ID:
required: true
description: "Specifies the client id."

permissions:
id-token: write
contents: read
pull-requests: write

jobs:
lint:
name: Terraform Lint
runs-on: [ubuntu-latest]
continue-on-error: false

steps:
# Setup Terraform
- name: Setup Terraform
id: terraform_setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform_version }}
terraform_wrapper: true

# Check Out Repository
- name: Check Out Repository
id: checkout_repository
uses: actions/checkout@v4

# Terraform Format
- name: Terraform Format
id: terraform_format
working-directory: ${{ inputs.working_directory }}
run: |
terraform fmt -check -recursive
# Add Pull Request Comment
- name: Add Pull Request Comment
uses: actions/github-script@v7
id: pr_comment
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Lint Results
* Terraform Version 📎\`${{ inputs.terraform_version }}\`
* Working Directory 📂\`${{ inputs.working_directory }}\`
* Terraform Format and Style 🖌\`${{ steps.terraform_format.outcome }}\``;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
plan:
name: Terraform Plan
runs-on: [self-hosted]
continue-on-error: false
environment: ${{ inputs.environment }}
needs: [lint]
concurrency:
group: terraform-${{ inputs.config }}-${{ inputs.environment }}
cancel-in-progress: false

env:
ARM_TENANT_ID: ${{ inputs.tenant_id }}
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
ARM_USE_OIDC: true

steps:
# Setup Node
- name: Setup Node
id: node_setup
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}

# Setup Terraform
- name: Setup Terraform
id: terraform_setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform_version }}
terraform_wrapper: true

# Check Out Repository
- name: Check Out Repository
id: checkout_repository
uses: actions/checkout@v4

# Terraform Init
- name: Terraform Init
id: terraform_init
working-directory: ${{ inputs.working_directory }}
run: |
terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend
env:
CONFIG: ${{ inputs.config }}

# Terraform Validate
- name: Terraform Validate
id: terraform_validate
working-directory: ${{ inputs.working_directory }}
run: |
terraform validate
# Terraform Plan
- name: Terraform Plan
id: terraform_plan
working-directory: ${{ inputs.working_directory }}
run: |
terraform plan -input=false
env:
CONFIG: ${{ inputs.config }}

# Add Pull Request Comment
- name: Add Pull Request Comment
id: pr_comment
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
continue-on-error: true
env:
PLAN: "terraform\n${{ steps.terraform_plan.outputs.stdout }}"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const output = `#### Terraform Validation & Plan Results
* Terraform Version 📎\`${{ inputs.terraform_version }}\`
* Working Directory 📂\`${{ inputs.working_directory }}\`
* Terraform Initialization ⚙️\`${{ steps.terraform_init.outcome }}\`
* Terraform Validation 🤖\`${{ steps.terraform_validate.outcome }}\`
* Terraform Plan 📖\`${{ steps.terraform_plan.outcome }}\`
<details><summary>Show Plan</summary>
\`\`\`\n
${process.env.PLAN}
\`\`\`
</details>`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})
apply:
name: Terraform Apply
runs-on: [self-hosted]
continue-on-error: false
environment: ${{ inputs.environment }}
# if: github.event_name == 'push' || github.event_name == 'release'
needs: [plan]
concurrency:
group: terraform-${{ inputs.config }}-${{ inputs.environment }}
cancel-in-progress: false

env:
ARM_TENANT_ID: ${{ inputs.tenant_id }}
ARM_SUBSCRIPTION_ID: ${{ inputs.subscription_id }}
ARM_CLIENT_ID: ${{ secrets.CLIENT_ID }}
ARM_USE_OIDC: true

steps:
# Setup Node
- name: Setup Node
id: node_setup
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}

# Setup Terraform
- name: Setup Terraform
id: terraform_setup
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform_version }}
terraform_wrapper: true

# Check Out Repository
- name: Check Out Repository
id: checkout_repository
uses: actions/checkout@v4

# Terraform Init
- name: Terraform Init
working-directory: ${{ inputs.working_directory }}
run: |
terraform init -backend-config=../../config/${CONFIG}/azurerm.tfbackend
env:
CONFIG: ${{ inputs.config }}

# Terraform Apply
- name: Terraform Apply
working-directory: ${{ inputs.working_directory }}
run: |
terraform apply -auto-approve -input=false
env:
CONFIG: ${{ inputs.config }}
TF_VAR_my_secret: ${{ secrets.MY_SAMPLE_SECRET }}
30 changes: 30 additions & 0 deletions .github/workflows/terraform-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: appserviceplan tests
on:
push:
branches:
- main
paths:
- "modules/test/**"
- ".github/workflows/terraform-test.yml"

pull_request:
branches:
- main
paths:
- "modules/test/**"
- ".github/workflows/terraform-test.yml"

jobs:
terraform_dev:
uses: ./.github/workflows/_terraformEnvironmentTemplate.yml
name: "Dev"
with:
environment: "dev"
config: "PerfectThymeTech"
terraform_version: "1.9.6"
node_version: 20
working_directory: "./modules/test"
tenant_id: "37963dd4-f4e6-40f8-a7d6-24b97919e452"
subscription_id: "1fdab118-1638-419a-8b12-06c9543714a0"
secrets:
CLIENT_ID: ${{ secrets.CLIENT_ID }}
7 changes: 7 additions & 0 deletions config/PerfectThymeTech/azurerm.tfbackend
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
environment = "public"
subscription_id = "e82c5267-9dc4-4f45-ac13-abdd5e130d27"
resource_group_name = "rg-terraform"
storage_account_name = "terraformststg001"
container_name = "test"
key = "terraform.tfstate"
use_azuread_auth = true
5 changes: 3 additions & 2 deletions modules/aistudiohub/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "azapi_resource" "ai_studio_hub" {
type = "Microsoft.MachineLearningServices/workspaces@2024-04-01"
type = "Microsoft.MachineLearningServices/workspaces@2024-07-01-preview"
name = var.ai_studio_hub_name
location = var.location
parent_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.resource_group_name}"
Expand All @@ -23,6 +23,7 @@ resource "azapi_resource" "ai_studio_hub" {
body = {
kind = "Hub"
properties = {
allowRoleAssignmentOnRG = false
applicationInsights = var.application_insights_id
containerRegistry = var.container_registry_id
keyVault = var.key_vault_id
Expand Down Expand Up @@ -72,7 +73,7 @@ resource "azapi_resource" "ai_studio_hub" {
}

response_export_values = []
schema_validation_enabled = false # Can be reverted once this is closed: https://github.com/Azure/terraform-provider-azapi/issues/524
schema_validation_enabled = true # Can be reverted once this is closed: https://github.com/Azure/terraform-provider-azapi/issues/524
locks = []
ignore_casing = false
ignore_missing_property = true
Expand Down
4 changes: 2 additions & 2 deletions modules/aistudiooutboundrules/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource "azapi_resource_action" "ai_studio_hub_provision_managed_network" {

response_export_values = []
depends_on = [
azapi_update_resource.ai_studio_hub_outbound_rules,
azapi_resource_action.ai_studio_hub_outbound_rules,
]

timeouts {
Expand All @@ -58,7 +58,7 @@ resource "null_resource" "ai_studio_hub_private_endpoints_approval" {
}

depends_on = [
azapi_update_resource.ai_studio_hub_outbound_rules,
azapi_resource_action.ai_studio_hub_outbound_rules,
azapi_resource_action.ai_studio_hub_provision_managed_network,
]
}
6 changes: 6 additions & 0 deletions modules/aistudioproject/tests/setup/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ output "ai_studio_hub_id" {
value = module.ai_studio_hub.ai_studio_hub_id
sensitive = false
}

output "ai_studio_hub_storage_account_id" {
description = "Specifies the resource id of ai studio hub."
value = module.storage_account.storage_account_id
sensitive = false
}
Loading

0 comments on commit a14a9ac

Please sign in to comment.