Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workspace parameter file not working. #5

Open
rubeste opened this issue Jan 5, 2023 · 1 comment
Open

Workspace parameter file not working. #5

rubeste opened this issue Jan 5, 2023 · 1 comment

Comments

@rubeste
Copy link

rubeste commented Jan 5, 2023

Hello,

A few days ago I encountered a problem when I wanted to use a workspace specific Parameter file. What happens is that when I run the workflow it fails the deployment due to missing parameter files. After some Debugging I found the problem.
The problamatic code can be found in the second line of the AttemptDeployment function:

function AttemptDeployment($path, $parameterFile, $deploymentName, $templateObject) {
    Write-Host "[Info] Deploying $path with deployment name $deploymentName"
    $isValid = IsValidTemplate $path $templateObject  <-- this line
    if (-not $isValid) {
        return $false
    }
    ...

Looking at the line or inside the IsValidTemplate function we can see that it doesn't obtain the parameter file that goes with the given template.

To fix this you need to modify the script a bit:
IsValidTemplate

function IsValidTemplate($path, $templateObject, $parameterFile) {
    Try {
        if (DoesContainWorkspaceParam $templateObject) {
            if($parameterFile)
            {
                Test-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $path -TemplateParameterFile $parameterFile -workspace $WorkspaceName
            }
            else{
                Test-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $path -workspace $WorkspaceName
            }
        }
        else {
            if($parameterFile)
            {
                Test-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $path -TemplateParameterFile $parameterFile
            }
            else{
                Test-AzResourceGroupDeployment -ResourceGroupName $ResourceGroupName -TemplateFile $path
            }
        }

        return $true
    }
    Catch {
        Write-Host "[Warning] The file $path is not valid: $_"
        return $false
    }
}

AttemptDeployment

function AttemptDeployment($path, $parameterFile, $deploymentName, $templateObject) {
    Write-Host "[Info] Deploying $path with deployment name $deploymentName"

    $isValid = IsValidTemplate $path $templateObject $parameterFile
    if (-not $isValid) {
        return $false
    }
    ...

I have no clue where I can report this bug so I just post it here.

@JonathanTvanLeeuwen
Copy link

Thanks for the solution. I sat with this problem for hours and couldn't figure out why my deployments failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants