-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add provisioner for devlabs task (#60)
<!-- 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
1 parent
74b87a9
commit e2eb697
Showing
5 changed files
with
62 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
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,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 |
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,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"] | ||
} | ||
} |
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