Skip to content

Commit

Permalink
Merge pull request aztfmod#1718 from arnaudlh/AL-pipelines
Browse files Browse the repository at this point in the history
Pipeline, rover, example updates
  • Loading branch information
LaurentLesle authored Jul 26, 2023
2 parents 38953ef + 576fc37 commit 5e723aa
Show file tree
Hide file tree
Showing 33 changed files with 313 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
version: '3.7'
services:
rover:
image: aztfmod/rover:1.5.2-2307.0508
image: aztfmod/rover:1.5.3-2307.2007
user: vscode

labels:
Expand Down
74 changes: 74 additions & 0 deletions .github/scripts/azuread_latest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
)

func getLatestVersion() (string, error) {
resp, err := http.Get("https://api.github.com/repos/hashicorp/terraform-provider-azuread/releases/latest")
if err != nil {
return "", err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

versionRegex := regexp.MustCompile(`"tag_name"\s*:\s*"v?(.*?)"`)
match := versionRegex.FindStringSubmatch(string(body))
if len(match) < 2 {
return "", nil
}

return match[1], nil
}

func updateVersion(filename, currentVersion, newVersion string) error {
content, err := ioutil.ReadFile(filename)
if err != nil {
return err
}

updatedContent := strings.ReplaceAll(string(content), currentVersion, newVersion)

err = ioutil.WriteFile(filename, []byte(updatedContent), 0644)
if err != nil {
return err
}

return nil
}

func main() {
filename := "main.tf"
currentVersionRegex := regexp.MustCompile(`source\s*=\s*"hashicorp/azuread"\s*\n\s*version\s*=\s*"~>\s*v?(\d+\.\d+\.\d+)"`)

content, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}

matches := currentVersionRegex.FindStringSubmatch(string(content))
if len(matches) < 2 {
log.Fatal("No azuread provider version found in the file.")
}

currentVersion := matches[1]
latestVersion, err := getLatestVersion()
if err != nil {
log.Fatal("Failed to retrieve the latest version from GitHub releases.")
}

err = updateVersion(filename, currentVersion, latestVersion)
if err != nil {
log.Fatal(err)
}

log.Printf("Successfully updated azuread provider version from %s to %s.", currentVersion, latestVersion)
}
74 changes: 74 additions & 0 deletions .github/scripts/azurerm_latest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
)

func getLatestVersion() (string, error) {
resp, err := http.Get("https://api.github.com/repos/hashicorp/terraform-provider-azurerm/releases/latest")
if err != nil {
return "", err
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}

versionRegex := regexp.MustCompile(`"tag_name"\s*:\s*"v?(.*?)"`)
match := versionRegex.FindStringSubmatch(string(body))
if len(match) < 2 {
return "", nil
}

return match[1], nil
}

func updateVersion(filename, currentVersion, newVersion string) error {
content, err := ioutil.ReadFile(filename)
if err != nil {
return err
}

updatedContent := strings.ReplaceAll(string(content), currentVersion, newVersion)

err = ioutil.WriteFile(filename, []byte(updatedContent), 0644)
if err != nil {
return err
}

return nil
}

func main() {
filename := "main.tf"
currentVersionRegex := regexp.MustCompile(`version\s*=\s*"~>\s*v?(\d+\.\d+\.\d+)"`)

content, err := ioutil.ReadFile(filename)
if err != nil {
log.Fatal(err)
}

matches := currentVersionRegex.FindStringSubmatch(string(content))
if len(matches) < 2 {
log.Fatal("No azurerm provider version found in the file.")
}

currentVersion := matches[1]
latestVersion, err := getLatestVersion()
if err != nil {
log.Fatal("Failed to retrieve the latest version from GitHub releases.")
}

err = updateVersion(filename, currentVersion, latestVersion)
if err != nil {
log.Fatal(err)
}

log.Printf("Successfully updated azurerm provider version from %s to %s.", currentVersion, latestVersion)
}
2 changes: 1 addition & 1 deletion .github/workflows/landingzone-scenarios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
needs: [job]

container:
image: aztfmod/rover:1.4.6-2305.1701
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rover.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
needs: rover_setup

container:
image: aztfmod/rover:1.4.6-2305.1701
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

env:
Expand Down
152 changes: 152 additions & 0 deletions .github/workflows/standalone-compute.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
#
# Copyright (c) Microsoft Corporation
# Licensed under the MIT License.
#

name: standalone-compute

on:
push:
paths:
- 'compute_*'
- 'modules/compute/**'
- 'examples/compute/**'
- '.github/workflows/*compute.*'

env:
TF_CLI_ARGS: "-no-color"
TF_CLI_ARGS_destroy: "-auto-approve -refresh=false"
ARM_CLIENT_SECRET: ${{ secrets.ARM_CLIENT_SECRET }}
ARM_CLIENT_ID: ${{ secrets.ARM_CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.ARM_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.ARM_TENANT_ID }}
TF_REGISTRY_DISCOVERY_RETRY: 5
TF_REGISTRY_CLIENT_TIMEOUT: 15
ROVER_RUNNER: true

jobs:
load_scenarios:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.load_scenarios.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- id: load_scenarios
run: |
cases=$(cat ./.github/workflows/standalone-compute.json | jq -c .)
echo "matrix=${cases}" >> $GITHUB_OUTPUT
testcases:
name: test
runs-on: ubuntu-latest
needs: load_scenarios

strategy:
fail-fast: false
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

container:
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Create environment variables
run: |
cd ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }}
FILE_NAME=$(echo ${{ matrix.config_files }} | sed 's./..g' | xargs)
echo STATE_FILE=${TF_DATA_DIR}/tfstates/${FILE_NAME}.tfstate >> $GITHUB_ENV
echo PLAN_FILE=${TF_DATA_DIR}/tfstates/${FILE_NAME}.plan >> $GITHUB_ENV
echo CURRENT_FOLDER=${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} >> $GITHUB_ENV
echo PARAMETER_FILES=$(find ${GITHUB_WORKSPACE}/examples/${{ matrix.config_files }} | grep .tfvars | sed 's/.*/-var-file=&/' | xargs) >> $GITHUB_ENV
- name: Login azure
run: |
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Terraform Init example
id: tf_init
run: |
terraform -chdir=${GITHUB_WORKSPACE}/examples \
init -upgrade=true | grep -P '^- (?=Downloading|Using|Finding|Installing)|^[^-]'
- name: Terraform Plan example
id: tf_plan
run: |
terraform -chdir=${GITHUB_WORKSPACE}/examples \
plan \
${{ env.PARAMETER_FILES }} \
-var tags='{testing_job_id='"${{ github.run_id }}"'}' \
-var var_folder_path=${{ env.CURRENT_FOLDER }} \
-refresh=true \
-input=false \
-state=${{ env.STATE_FILE }} \
-out=${{ env.PLAN_FILE }}
- name: Terraform Apply example
id: tf_apply
if: steps.tf_plan.outcome == 'success'
run: |
terraform -chdir=${GITHUB_WORKSPACE}/examples \
apply \
-parallelism=30 \
-state=${{ env.STATE_FILE }} \
${{ env.PLAN_FILE }}
- name: Terraform Destroy planning example
id: tf_destroy_plan
if: steps.tf_plan.outcome == 'success'
run: |
terraform -chdir=${GITHUB_WORKSPACE}/examples \
plan \
${{ env.PARAMETER_FILES }} \
-var tags='{testing_job_id='"${{ github.run_id }}"'}' \
-var var_folder_path=${{ env.CURRENT_FOLDER }} \
-refresh=true \
-input=false \
-destroy \
-state=${{ env.STATE_FILE }} \
-out=${{ env.PLAN_FILE }}-destroy
- name: Terraform Destroy apply example
id: tf_destroy_apply
if: steps.tf_destroy_plan.outcome == 'success'
run: |
terraform -chdir=${GITHUB_WORKSPACE}/examples \
apply \
-refresh=false \
-parallelism=30 \
-auto-approve \
-state=${{ env.STATE_FILE }} \
${{ env.PLAN_FILE }}-destroy
purge:
name: purge
runs-on: ubuntu-latest
if: ${{ failure() || cancelled() }}

needs: [testcases]

container:
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
- name: Login azure
run: |
az login --service-principal -u '${{ env.ARM_CLIENT_ID }}' -p '${{ env.ARM_CLIENT_SECRET }}' --tenant '${{ env.ARM_TENANT_ID }}'
az account set -s ${{ env.ARM_SUBSCRIPTION_ID }}
- name: Complete purge
run: |
for i in `az monitor diagnostic-settings subscription list -o tsv --query "value[?contains(name, '${{ github.run_id }}' )].name"`; do echo "purging subscription diagnostic-settings: $i" && $(az monitor diagnostic-settings subscription delete --name $i --yes); done
for i in `az monitor log-profiles list -o tsv --query '[].name'`; do az monitor log-profiles delete --name $i; done
for i in `az ad group list --query "[?contains(displayName, '${{ github.run_id }}')].id" -o tsv`; do echo "purging Azure AD group: $i" && $(az ad group delete --verbose --group $i || true); done
for i in `az ad app list --query "[?contains(displayName, '${{ github.run_id }}')].appId" -o tsv`; do echo "purging Azure AD app: $i" && $(az ad app delete --verbose --id $i || true); done
for i in `az keyvault list-deleted --query "[?tags.testing_job_id=='${{ github.run_id }}'].name" -o tsv`; do az keyvault purge --name $i; done
for i in `az group list --query "[?tags.testing_job_id=='${{ github.run_id }}'].name" -o tsv`; do echo "purging resource group: $i" && $(az group delete -n $i -y --no-wait || true); done
for i in `az role assignment list --query "[?contains(roleDefinitionName, '${{ github.run_id }}')].roleDefinitionName" -o tsv`; do echo "purging role assignment: $i" && $(az role assignment delete --role $i || true); done
for i in `az role definition list --query "[?contains(roleName, '${{ github.run_id }}')].roleName" -o tsv`; do echo "purging custom role definition: $i" && $(az role definition delete --name $i || true); done
4 changes: 2 additions & 2 deletions .github/workflows/standalone-networking.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
needs: [testcases]

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/standalone-regressor-tf100.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down Expand Up @@ -178,7 +178,7 @@ jobs:
needs: [testcases]

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/standalone-tf100.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
matrix: ${{fromJSON(needs.load_scenarios.outputs.matrix)}}

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
needs: [testcases]

container:
image: aztfmod/rover:1.4.6-2305.1807
image: aztfmod/rover:1.5.3-2307.2007
options: --user 0

steps:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dedicated_hosts = {
dedicated_host_group_key = "dhg1"
#lz_key = "remote landing zone key"
region = "region1"
sku_name = "DSv3-Type1"
sku_name = "DSv3-Type3"
platform_fault_domain = 1
auto_replace_on_failure = true
# license_type = "Windows_Server_Hybrid"
Expand Down
Loading

0 comments on commit 5e723aa

Please sign in to comment.