Skip to content

Commit

Permalink
feature: add provisioner for devlabs task (#60)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting a Pull Request. Please fill out the
template below.-->
## Overview/Summary

This PR ensures that the DevLabs task is installed. If already installed
it will continue. If it fails to install it will fail.

## This PR fixes/adds/changes/removes

1. #37 

### Breaking Changes

1. None

## Testing Evidence

Tested locally and run e2e tests

## As part of this Pull Request I have

- [x] Checked for duplicate [Pull
Requests](https://github.com/Azure/alz-terraform-accelerator/pulls)
- [x] Associated it with relevant
[issues](https://github.com/Azure/alz-terraform-accelerator/issues), for
tracking and closure.
- [x] Ensured my code/branch is up-to-date with the latest changes in
the `main`
[branch](https://github.com/Azure/alz-terraform-accelerator/tree/main)
- [x] Performed testing and provided evidence.
- [x] Updated relevant and associated documentation.
  • Loading branch information
jaredfholgate authored Dec 2, 2023
1 parent 74b87a9 commit e2eb697
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions bootstrap/azuredevops/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ module "azure_devops" {
backend_azure_storage_account_container_name = local.resource_names.storage_container
approvers = var.apply_approvers
group_name = local.resource_names.version_control_system_group
version_control_system_access_token = var.version_control_system_access_token
}
41 changes: 41 additions & 0 deletions bootstrap/modules/azure_devops/extension-install.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
param(
[string]$patToken,
[string]$organizationName
)

# Install the Azure DevOps Terraform extension
Write-Host "Checking and Installing the Azure DevOps Microsoft DevLabs Terraform extension..."
$extensionName = "custom-terraform-tasks"
$extensionPublisher = "ms-devlabs"
$extensionInstallUrl = "https://extmgmt.dev.azure.com/${organizationName}/_apis/extensionmanagement/installedextensionsbyname/${extensionPublisher}/${extensionName}?api-version=7.0-preview.1"

$base64PatToken = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("`:$patToken"))

$headers=@{
"Authorization" = "Basic $base64PatToken"
}

Invoke-RestMethod -Uri $extensionInstallUrl `
-Method 'POST' `
-ContentType 'application/json' `
-Headers $headers `
-StatusCodeVariable statusCode `
-SkipHttpErrorCheck `
| Set-Variable result

if($statusCode -eq 409)
{
Write-Host "Extension already installed"
}
elseif($statusCode -eq 200)
{
Write-Host "Installed version $($result.version) of extension $($result.publisherName) $($result.extensionName)"
}
else
{
Write-Host "Failed to install extension. Status code: $statusCode"
Write-Host "Response: $result"
exit 1
}

exit 0
13 changes: 13 additions & 0 deletions bootstrap/modules/azure_devops/extension.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
resource "terraform_data" "dev_labs_extension" {
triggers_replace = [var.organization_name]

input = {
pat_token = var.version_control_system_access_token
organization_name = var.organization_name
}

provisioner "local-exec" {
command = "${path.module}/extension-install.ps1 -patToken \"${self.input.pat_token}\" -organizationName \"${self.input.organization_name}\""
interpreter = ["pwsh", "-Command"]
}
}
6 changes: 6 additions & 0 deletions bootstrap/modules/azure_devops/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
variable "version_control_system_access_token" {
description = "The personal access token for the version control system to use for the extension install"
type = string
sensitive = true
}

variable "authentication_scheme" {
type = string
validation {
Expand Down
1 change: 1 addition & 0 deletions docs/wiki/[User-Guide]-Quick-Start-Phase-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ You'll need to decide whether you are using GitHub or Azure DevOps and follow th
1. `Build`: `Read & execute`
1. `Code`: `Full`
1. `Environment`: `Read & manage`
1. `Extensions`: `Read & manage`
1. `Graph`: `Read & manage`
1. `Pipeline Resources`: `Use & manage`
1. `Project and Team`: `Read, write & manage`
Expand Down

0 comments on commit e2eb697

Please sign in to comment.