Terraform list as input variable in Azure DevOps - azure-devops

I am trying to pass list as variable to Azure DevOps release pipeline.
My variable declaration:
variable "allowed_audiences" {
description = "Allowed audiences"
type = list(string)
default = ["xyz", "abc"]
}
Then, in azure devops i am trying to pass value that i am storing in variable group:
["\"test\""]
In task, i am passing that variable like that:
-var="allowed_audiences=$(allowed_audience)" -var="environment=$(Release.EnvironmentName)"
But it still failes whatever i tried.
2023-02-06T08:48:17.5412282Z [31m│[0m [0m[1m[31mError: [0m[0m[1mInvalid character[0m
2023-02-06T08:48:17.5412838Z [31m│[0m [0m
2023-02-06T08:48:17.5413184Z [31m│[0m [0m[0m on <value for var.allowed_audiences> line 1:
2023-02-06T08:48:17.5413540Z [31m│[0m [0m (source code not available)
2023-02-06T08:48:17.5413823Z [31m│[0m [0m
2023-02-06T08:48:17.5414269Z [31m│[0m [0mThis character is not used within the language.
2023-02-06T08:48:17.5414588Z [31m╵[0m[0m
2023-02-06T08:48:17.5414821Z [31m╷[0m[0m
2023-02-06T08:48:17.5415132Z [31m│[0m [0m[1m[31mError: [0m[0m[1mInvalid expression[0m
2023-02-06T08:48:17.5415438Z [31m│[0m [0m
2023-02-06T08:48:17.5415998Z [31m│[0m [0m[0m on <value for var.allowed_audiences> line 1:
2023-02-06T08:48:17.5416559Z [31m│[0m [0m (source code not available)
2023-02-06T08:48:17.5416989Z [31m│[0m [0m
2023-02-06T08:48:17.5417537Z [31m│[0m [0mExpected the start of an expression, but found an invalid expression token.
2023-02-06T08:48:17.5418082Z [31m╵[0m[0m
My question is, how to pass list of string as variable during Azure Devops release pipeline?
EDIT:
When i try this form:
-var='allowed_audiences=["\"$(allowed_audience)\""]' -var="environment=$(Release.EnvironmentName)"
I get this error:
2023-02-06T09:28:13.7759253Z [31m╷[0m[0m
2023-02-06T09:28:13.7760165Z [31m│[0m [0m[1m[31mError: [0m[0m[1mValue for undeclared variable[0m
2023-02-06T09:28:13.7760795Z [31m│[0m [0m
2023-02-06T09:28:13.7761315Z [31m│[0m [0m[0mA variable named "'allowed_audiences" was assigned on the command line, but
2023-02-06T09:28:13.7761949Z [31m│[0m [0mthe root module does not declare a variable of that name. To use this
2023-02-06T09:28:13.7762528Z [31m│[0m [0mvalue, add a "variable" block to the configuration.
2023-02-06T09:28:13.7762964Z [31m╵[0m[0m

I managed to do that. YOu need to delete quotes from var area and everything should be fine
-var=allowed_audiences=["\"$(allowed_audience)\""] -var="environment=$(Release.EnvironmentName)"

Related

Azure DevOps Pipeline - Create a Synapse managed-private-endpoints to a Azure Storage Account

I am trying to create a 'Synapse Managed private endpoint' to an Azure storage account via a 'Azure cli' task as a step in a pipeline. I want to create the MPE automatically.
The pipeline step calls a power-shell script with parameters. The script is located in source control. Calling the script and passing in parameter values is working fine.
Within the powershell script the following happens...
Get the json template (see below) from source control - this step works.
In the powershell script subsitute the json fields enclosed in <...> with a the parameter values passed in to the power-shell script - this works fine. The converted json is shown in the below screenshot.NB: sensitive values have been readacted here but look correct...
The line in the power-shell that's raising the error is...
az synapse managed-private-endpoints create --workspace-name "$pSynapseWorkspaceName" --pe-name "$pPrivateEndpointName" --file $mpeArmJson --debug --verbose
I think it's to do with the json-string parmater $mpeArmJson and double-quotes - this is what I need help solving ???
The value of $mpeArmJson which the value at this point is (note sensitive values have been readacted here but look correct)...
{
"name": "dds2-datalake-endpoint",
"properties": {
"privateLinkResourceId": "/subscriptions/<redacted subscription id>/resourceGroups/dds2-data-tst-rg/providers/Microsoft.Storage/storageAccounts/dds2datatstdlksa",
"groupId": "dfs",
"fqdns": [
"<redacted-storage-account>.dfs.core.windows.net"
]
}
}
In my Azure devOps pipeline I have created a 'Azure Powershell' task. The task calls a PowerShell script stored in source-control - taking in parameters.
Inside the powershell script I am calling...
New-AzSynapseManagedPrivateEndpoint -WorkspaceName "$pSynapseWorkspaceName" -Name "$pPrivateEndpointName" -DefinitionFile "$tmpDir"
NB: the devOps pipeline runs under a Az 'service principal' which creates the Synapse workspace and in doing so gets the 'owner' and also a 'synapse admin.' permissions automatically set in IAM.
The 'service principal' also needs 'blob storage data contributor' on the main storage account linked to Synapse.

Read DevOps Variable as bool in ARM paramters

I am trying to read in a pipeline variable as a bool. I have the following parameters defined in json:
"parameters": {
"disableFunkyFunction": {
"value": "#{myVariables.disableFunkyFunction}#",
"type": "bool"
}...
}
In my Azure DevOps release pipeline, I have a pipeline variable called myVariables.disableFunkyFunction and the value for it is set to true. However, whenever I try and run the pipeline, it fails on the "Azure resource group deployment" step: Template parameter 'disableFunkyFunction' was provided an invalid value. Expected a value of type 'Boolean', but received a value of type 'String'. I have tried using a value of 1 instead, but to no avail.
The following works, but ideally I want to read the value from the DevOps pipeline variable, not hard code it in the parameters file:
"parameters": {
"disableFunkyFunction": {
"value": true,
"type": "bool"
}...
}
Any suggestions?
From the error message, it seems that the pipeline variable value hasn't been passed to ARM template file.
Since you have set the parameter value as #{myVariables.disableFunkyFunction}#, you can try to use the Replace Token task from Replace Tokens Extension.
Here are the steps:
Step1: Keep the parameter value as #{myVariables.disableFunkyFunction}#.
Step2: Use Replace token task to set the value.
Step3: Deploy the ARM template.
For example:
Note: You need to put the Replace token task before the ARM template deployment step.

NUKE Build in Azure DevOps Build Pipeline Failing

So I have implemented the NUKE build system in my solution, and everything 100% works locally.
Out in Azure DevOps it's a different story, my YAML task looks like this:
- task: CmdLine#2
displayName: 'NUKE Build'
inputs:
script:
.\src\build package --cfg $(buildConfiguration) --pak $(Build.ArtifactStagingDirectory)
And NUKE does run, but it fails with an error stating it couldn't locate my solution file:
Expected file to exist: D:\a\1\s\**\*.sln
Here is the entire command line log output:
2022-04-08T18:39:07.9969860Z ##[section]Starting: NUKE Build
2022-04-08T18:39:08.0228304Z ==============================================================================
2022-04-08T18:39:08.0228652Z Task : Command line
2022-04-08T18:39:08.0228978Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:39:08.0229274Z Version : 2.201.1
2022-04-08T18:39:08.0229490Z Author : Microsoft Corporation
2022-04-08T18:39:08.0230495Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:39:08.0230888Z ==============================================================================
2022-04-08T18:39:09.5867757Z Generating script.
2022-04-08T18:39:09.6086899Z Script contents: shell
2022-04-08T18:39:09.6117246Z .\src\build package --cfg Release --pak D:\a\1\a
2022-04-08T18:39:09.6712303Z ========================== Starting Command Output ===========================
2022-04-08T18:39:09.7222712Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\ec061a9c-d293-42ca-8b24-3d57ab43d6b1.cmd""
2022-04-08T18:39:10.1964079Z PowerShell Desktop version 5.1.20348.558
2022-04-08T18:39:11.9025685Z Microsoft (R) .NET Core SDK version 6.0.201
2022-04-08T18:39:12.1269858Z
2022-04-08T18:39:12.1299946Z Welcome to .NET 6.0!
2022-04-08T18:39:12.1300642Z ---------------------
2022-04-08T18:39:12.1301057Z SDK Version: 6.0.201
2022-04-08T18:39:12.1301258Z
2022-04-08T18:39:12.1301590Z ----------------
2022-04-08T18:39:12.1302080Z Installed an ASP.NET Core HTTPS development certificate.
2022-04-08T18:39:12.1303932Z To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
2022-04-08T18:39:12.1304429Z Learn about HTTPS: https://aka.ms/dotnet-https
2022-04-08T18:39:12.1305954Z ----------------
2022-04-08T18:39:12.1306300Z Write your first app: https://aka.ms/dotnet-hello-world
2022-04-08T18:39:12.1306678Z Find out what's new: https://aka.ms/dotnet-whats-new
2022-04-08T18:39:12.1307948Z Explore documentation: https://aka.ms/dotnet-docs
2022-04-08T18:39:12.1308586Z Report issues and find source on GitHub: https://github.com/dotnet/core
2022-04-08T18:39:12.1309267Z Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
2022-04-08T18:39:12.1311891Z --------------------------------------------------------------------------------------
2022-04-08T18:39:27.0014563Z ##[warning]Exception has been thrown by the target of an invocation.
2022-04-08T18:39:27.1770000Z [90m18:39:26[0m[90m [[0m[33;1mWRN[0m[90m] [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1771426Z System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1773524Z ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.[0m
2022-04-08T18:39:27.1774228Z ---> System.ArgumentException: Expected file to exist: D:\a\1\s\**\*.sln (Parameter 'path')[0m
2022-04-08T18:39:27.1774784Z [90m at Nuke.Common.Assert.FileExists(String path, String message, String argumentExpression)[0m
2022-04-08T18:39:27.1775284Z [90m at Nuke.Common.IO.TextTasks.ReadAllLines(String path, Encoding encoding)[0m
2022-04-08T18:39:27.1775809Z [90m at Nuke.Common.ProjectModel.SolutionSerializer.DeserializeFromFile[T](String solutionFile)[0m
2022-04-08T18:39:27.1776522Z [90m --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1777060Z [90m at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1778369Z [90m at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)[0m
2022-04-08T18:39:27.1779002Z [90m at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)[0m
2022-04-08T18:39:27.1779785Z [90m at Nuke.Common.ProjectModel.SolutionAttribute.GetValue(MemberInfo member, Object instance)[0m
2022-04-08T18:39:27.1782574Z [90m at Nuke.Common.ValueInjection.ValueInjectionAttributeBase.<>c__DisplayClass0_0.<TryGetValue>b__0()[0m
2022-04-08T18:39:27.1783085Z [90m --- End of inner exception stack trace ---[0m
2022-04-08T18:39:27.1783634Z [90m at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)[0m
2022-04-08T18:39:27.1784428Z [90m at System.Delegate.DynamicInvokeImpl(Object[] args)[0m
2022-04-08T18:39:27.1784965Z [90m at System.Delegate.DynamicInvoke(Object[] args)[0m
2022-04-08T18:39:27.1786056Z [90m at Nuke.Common.ControlFlow.SuppressErrorsIf(Boolean condition, Delegate action, Object defaultValue, Boolean includeStackTrace, Boolean logWarning)[0m
2022-04-08T18:39:27.2272867Z ?
2022-04-08T18:39:27.2274719Z [97;1m¦¦¦+ ¦¦+¦¦+ ¦¦+¦¦+ ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2275048Z [97;1m¦¦¦¦+ ¦¦¦¦¦¦ ¦¦¦¦¦¦ ¦¦++¦¦+----+[0m
2022-04-08T18:39:27.2275514Z [97;1m¦¦+¦¦+ ¦¦¦¦¦¦ ¦¦¦¦¦¦¦¦++ ¦¦¦¦¦+ [0m
2022-04-08T18:39:27.2275785Z [97;1m¦¦¦+¦¦+¦¦¦¦¦¦ ¦¦¦¦¦+-¦¦+ ¦¦+--+ [0m
2022-04-08T18:39:27.2276070Z [97;1m¦¦¦ +¦¦¦¦¦+¦¦¦¦¦¦++¦¦¦ ¦¦+¦¦¦¦¦¦¦+[0m
2022-04-08T18:39:27.2276350Z [97;1m+-+ +---+ +-----+ +-+ +-++------+[0m
2022-04-08T18:39:27.2276564Z ?
2022-04-08T18:39:27.2437288Z [36;1mNUKE Execution Engine version 6.0.1 (Windows,.NETCoreApp,Version=v5.0)[0m
2022-04-08T18:39:27.2438057Z ?
2022-04-08T18:39:27.7707082Z ##[warning]Could not complete checking build configurations within 500 milliseconds
2022-04-08T18:39:27.7732088Z [90m18:39:27[0m[90m [[0m[33;1mWRN[0m[90m] [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8279552Z ##[group]Restore
2022-04-08T18:39:31.8446550Z ##[error]Target "Restore" failed
2022-04-08T18:39:31.8794936Z [90m18:39:31[0m[90m [[0m[31;1mERR[0m[90m] [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8796042Z System.NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.8796591Z [90m at Nuke.Common.ProjectModel.Solution.op_Implicit(Solution solution)[0m
2022-04-08T18:39:31.8797101Z [90m at Build.<get_Restore>b__20_2(MSBuildSettings s) in D:\a\1\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8797732Z [90m at Nuke.Common.Tools.MSBuild.MSBuildTasks.MSBuild(Configure`1 configurator)[0m
2022-04-08T18:39:31.8798459Z [90m at Build.<get_Restore>b__20_1() in D:\a\1\s\build\Build.cs:line 77[0m
2022-04-08T18:39:31.8798994Z [90m at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)[0m
2022-04-08T18:39:31.8799610Z [90m at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)[0m
2022-04-08T18:39:31.8800407Z [90m at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)[0m
2022-04-08T18:39:31.8817982Z ##[endgroup]Restore
2022-04-08T18:39:31.8863504Z ##[group]Warnings & Errors
2022-04-08T18:39:31.8882060Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mException has been thrown by the target of an invocation.[0m
2022-04-08T18:39:31.8884458Z [90m[[0m[33;1mWRN[0m[90m] [0m[90m[0m[90m: [0mCould not complete checking build configurations within [0m[36;1m500[0m milliseconds[0m
2022-04-08T18:39:31.8888070Z [90m[[0m[31;1mERR[0m[90m] [0m[90mRestore[0m[90m: [0mTarget [0m[36;1mRestore[0m failed[0m
2022-04-08T18:39:31.8889294Z ##[endgroup]Warnings & Errors
2022-04-08T18:39:31.8932545Z ?
2022-04-08T18:39:31.8933184Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.8933694Z [36;1mTarget Status Duration[0m
2022-04-08T18:39:31.8935167Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9029244Z [31;1mRestore Failed < 1sec // NullReferenceException: Object reference not set to an instance of an object.[0m
2022-04-08T18:39:31.9032700Z [33;1mPreBuild NotRun [0m
2022-04-08T18:39:31.9033326Z [33;1mBuildFrontend NotRun [0m
2022-04-08T18:39:31.9034546Z [33;1mCompile NotRun [0m
2022-04-08T18:39:31.9035764Z [33;1mPublish NotRun [0m
2022-04-08T18:39:31.9036389Z [33;1mPackage NotRun [0m
2022-04-08T18:39:31.9036847Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9037329Z [36;1mTotal < 1sec[0m
2022-04-08T18:39:31.9037792Z [97;1m---------------------------------------[0m
2022-04-08T18:39:31.9038298Z ?
2022-04-08T18:39:31.9054882Z [31;1mBuild failed on 4/8/2022 6:39:31 PM. (?°?°)?? ???[0m
2022-04-08T18:39:32.1509226Z ##[error]Cmd.exe exited with code '-1'.
2022-04-08T18:39:32.2145341Z ##[section]Finishing: NUKE Build
but I definitely have a solution file at:
D:\a\1\s\src\MySolution.sln
I added a YAML task to 100% confirm it is there (and it's there):
- task: CmdLine#2
displayName: 'List Source Folder'
inputs:
script: 'tree $(Build.SourcesDirectory) /f'
Here is the listing:
2022-04-08T18:57:59.6501952Z ##[section]Starting: List Source Folder
2022-04-08T18:57:59.6793825Z ==============================================================================
2022-04-08T18:57:59.6794430Z Task : Command line
2022-04-08T18:57:59.6794753Z Description : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-04-08T18:57:59.6795061Z Version : 2.201.1
2022-04-08T18:57:59.6795267Z Author : Microsoft Corporation
2022-04-08T18:57:59.6795600Z Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-04-08T18:57:59.6795961Z ==============================================================================
2022-04-08T18:58:02.0506033Z Generating script.
2022-04-08T18:58:02.0739760Z Script contents: shell
2022-04-08T18:58:02.0756595Z tree D:\a\1\s /f
2022-04-08T18:58:02.1475179Z ========================== Starting Command Output ===========================
2022-04-08T18:58:02.1898242Z ##[command]"C:\Windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\5da783bd-9a97-4da8-8bef-3d739b2a3128.cmd""
2022-04-08T18:58:02.2402115Z Folder PATH listing for volume Temp
2022-04-08T18:58:02.2403508Z Volume serial number is 00000247 52D3:EF1F
2022-04-08T18:58:02.2404144Z D:\A\1\S
2022-04-08T18:58:02.2405018Z | .gitignore
2022-04-08T18:58:02.2405560Z | azure-pipelines.yml
2022-04-08T18:58:02.2406147Z | clean.bat
2022-04-08T18:58:02.2406717Z | nuget.config
2022-04-08T18:58:02.2407288Z | README.md
2022-04-08T18:58:02.2407842Z |
2022-04-08T18:58:02.2408341Z +---.nuke
2022-04-08T18:58:02.2409000Z | build.schema.json
2022-04-08T18:58:02.2409391Z | parameters.json
2022-04-08T18:58:02.2409867Z |
2022-04-08T18:58:02.2410372Z +---build
2022-04-08T18:58:02.2410926Z | .editorconfig
2022-04-08T18:58:02.2411502Z | Build.cs
2022-04-08T18:58:02.2412097Z | Configuration.cs
2022-04-08T18:58:02.2412876Z | Directory.Build.props
2022-04-08T18:58:02.2413461Z | Directory.Build.targets
2022-04-08T18:58:02.2414211Z | _build.csproj
2022-04-08T18:58:02.2414923Z | _build.csproj.DotSettings
2022-04-08T18:58:02.2415470Z |
2022-04-08T18:58:02.2535989Z +---src
2022-04-08T18:58:02.2536325Z | build.cmd
2022-04-08T18:58:02.2536699Z | build.ps1
2022-04-08T18:58:02.2536957Z | build.sh
2022-04-08T18:58:02.2537193Z | MySolution.sln
2022-04-08T18:58:02.2537398Z |
.
.
.
Lot's of project folders/files here (removed for brevity)
.
.
.
2022-04-08T18:58:02.3340758Z
2022-04-08T18:58:02.3743539Z ##[section]Finishing: List Source Folder
I'm at a loss (why doesn't it find it?), anyone have any insight on why this might be happening?
Turns out... what I thought, was NUKE searching for a solution file, was actually not the case at all.
The error:
Expected file to exist: D:\a\1\s\**\*.sln
was due to the existence of a variable that is normally added to the standard YAML pipeline file (for use with NuGet/MSBuild tasks), i.e.
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
- task: NuGetCommand#2
displayName: 'Restore'
inputs:
command: 'restore'
restoreSolution: '$(solution)'
feedsToUse: 'config'
nugetConfigPath: './nuget.config'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
That solution: '**/*.sln' was somehow overriding the solution value configured in the parameters.json file. Not 100% sure why... but once that environment variable was removed NUKE began to work as expected.
.nuke marks the root directory, so your solution file is located under ./src/MySolution.sln from there and should also be noted like that in the parameters.json

Unexpected error while passing variable group variables (Azure DevOps) to YAML pipeline

I'm a newbie to both Azure DevOps and Terraform but, I'm trying to deploy a pipeline using a YAML file.
I have tried to run a terraform plan using a YAML file and passing variables (from AZ DevOps) but, I got the following error:
2021-11-24T18:39:46.4604561Z Error: "name" may only contain alphanumeric characters, dash, underscores, parentheses and periods
2021-11-24T18:39:46.4604832Z
2021-11-24T18:39:46.4605940Z on modules/aks/main.tf line 2, in resource "azurerm_resource_group" "aks-resource-group":
2021-11-24T18:39:46.4606436Z 2: name = var.resource_group_name
2021-11-24T18:39:46.4606609Z
2021-11-24T18:39:46.4606722Z
2021-11-24T18:39:46.4606818Z
2021-11-24T18:39:46.4607525Z Error: Error: Subnet: (Name "#{vnet_subnet_name}#" / Virtual Network Name "#{vnet_name}#" / Resource Group "RG-XX-XXXX-XXXXX-001") was not found
2021-11-24T18:39:46.4608006Z
2021-11-24T18:39:46.4608580Z on modules/aks/main.tf line 16, in data "azurerm_subnet" "subnet-project":
2021-11-24T18:39:46.4609335Z 16: data "azurerm_subnet" "subnet-project" {
The 'name' has the following format at the Variable group in the Azure DevOps UI:
RG-XX-XXXX-XXXXX-001
This is the snippet of where I included the replace token at the YAML file:
displayName: 'Replace Secrets'
inputs:
targetFiles: |
variables.tfvars
encoding: 'utf-8'
actionOnMissing: fail
tokenPattern: #{MyVar}#
And this is a sample of the variables I have in a variable group:
variable-group-sample
Also, I replace the terraform.tfvars file with something like this:
resource_group_name = "#{resource_group_name}#"
I have checked the name inserted at the UI several times but I feel the error is pointing to something else I cannot see.
Have anyone experienced something related to this error?
Thank you in advance!
tokenPattern: #{MyVar}#
It is looking for the pattern #{MyVar}# to replace. Not "something contained between #{ and }#, but the actual value #{MyVar}#. I'm guessing it's expecting a regular expression, but I'm not familiar with that task.
So the end result is that your #{token values}# aren't getting replaced.
Assuming you're using https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens, you probably want to specify tokenPrefix: #{ and tokenSuffix: }# instead of using tokenPattern.
Now, having said that...
There is no reason for you to be using token replacement on a tfvars file. You should create different tfvars files for each environment, then pass in a tfvars file via the -var-file argument to Terraform. Secrets can be passed in on the command line via -var 'foo=bar'
Storing variables that represent application or deployment configuration in Azure DevOps (or GitHub, or any other CI system) is a big, big anti-pattern, because it's tightly coupling your deployment process to a particular platform. If you're sourcing all of your variables from Azure DevOps, you can't easily test locally or migrate to a different CI/CD provider like GitHub Actions in the future.
For values that shouldn't be in source control, such a secrets, you should use a secret provider like Azure KeyVault and integrate it with your application (or, in this case, use a data resource in Terraform to pull the necessary secrets automatically at deployment time).

Azure Devops - Domain name is invalid

I am trying to create a virtual machine using ARM template.
I have added ARM template in my visual studio and have checked-in into the Azure Repos.
On running release pipeline I am receiving below error:
InvalidDomainNameLabel: The domain name label $(dns) is invalid. It must conform to the following regular expression: ^[a-z][a-z0-9-]{1,61}[a-z0-9]$. []
Below is the parameter.json file:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"value": "Myadmin"
},
"dnsNameForPublicIP": {
"value": "mynewdevvmbox003"
}
}
}
dns name "mynewdevvmbox003" is matching the regular expression requirement but still, I am getting this error.
InvalidDomainNameLabel: The domain name label $(dns) is invalid.
According to this error message, the value of domain name that this task server got is $(dns), not mynewdevvmbox003.
I think you should specified the override parameter value in Override template parameters of Azure resource group deployment task, such as -dnsNameForPublicIP $(dns).
If you indeed specify like this, the value in parameter.json will not be parsed any more. Because the override content has higher priority than parameter.json. Here, dns is a pipeline varibale.
Please ensure select the parameter.json file in Template parameters:
And, do not specify adminUsername and dnsNameForPublicIP again in Override template parameters of the task.