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

JSON array as parameter input #36

Open
dpantaz opened this issue Apr 1, 2021 · 33 comments
Open

JSON array as parameter input #36

dpantaz opened this issue Apr 1, 2021 · 33 comments
Assignees
Labels
backlog Planned for future

Comments

@dpantaz
Copy link

dpantaz commented Apr 1, 2021

Hello.

Is it possible to use a JSON array as a parameter value in the parameters input?
For example
parameters: param1=

Thank you.

@github-actions
Copy link

github-actions bot commented Apr 1, 2021

This issue is marked default for generating issues report.

@github-actions
Copy link

github-actions bot commented Apr 8, 2021

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale 90 days old label Apr 8, 2021
@marvinbuss
Copy link

@bishal-pdMSFT We are running into issues, when trying to do this. Due to the AZURE_CREDENTIALS, it also seems like that any { and } get replaced with *** in the Actions page and passing a JSON array always fails with Failed to parse JSON. Here are more details:
image

@github-actions github-actions bot removed default stale 90 days old labels May 7, 2021
@github-actions
Copy link

github-actions bot commented May 7, 2021

This issue is marked default for generating issues report.

@github-actions
Copy link

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale 90 days old label May 14, 2021
@t-dedah
Copy link
Contributor

t-dedah commented May 15, 2021

Hi @marvinbuss, will it be possible to share the exact parameter input. Are you passing a json or a json string something like this
'{"costCenter":"ABCD", "owner":"XYZ"}'

@marvinbuss
Copy link

marvinbuss commented May 17, 2021

Hi @t-dedah, I am passing a JSON string as input (e.g. '{"costCenter":"ABCD", "owner":"XYZ"}'). It seems like { and } get replaced with ***. Using a JSON as secret is also not recommended by the Actions team. We should consider moving to a different authentication method for Azure/login with individual secrets for clientId and clientSecret. See here: https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-secrets

@github-actions github-actions bot removed default stale 90 days old labels May 17, 2021
@github-actions
Copy link

This issue is marked default for generating issues report.

@t-dedah
Copy link
Contributor

t-dedah commented May 19, 2021

@marvinbuss I am little confused. What secrets are you trying to pass as parameters? shouldn't we use azure login task for that? Also I consoled out '{"costCenter":"ABCD", "owner":"XYZ"}' and everything looks okay to me.

Will it be possible to share repro steps for the issue?

Screenshot 2021-05-19 at 3 43 55 PM

@marvinbuss
Copy link

marvinbuss commented May 19, 2021

Please try this workflow, then you will see the issue:

name: Deployment

on:
  push:
    branches: [ main ]
    paths:
      - 'infra/**'
  pull_request:
    branches: [ main ]
    paths:
      - 'infra/**'

env:
  AZURE_SUBSCRIPTION_ID: 'your-sub-id'
  AZURE_LOCATION: 'northeurope'
  AZURE_TAGS: '{"costCenter":"ABCD", "owner":"XYZ"}'

jobs:
  create-resource-groups:
    runs-on: ubuntu-latest

    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - name: Check Out Repository
      id: checkout_repository
      uses: actions/checkout@v2
    
    # Login to Azure
    - name: Azure Login
      id: azure_login
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    # Deploy Resource Groups
    - name: Deploy Resource Groups
      id: resource_groups_deployment
      uses: azure/arm-deploy@v1
      with:
        scope: subscription
        subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
        region: ${{ env.AZURE_LOCATION }}
        template: ${{ github.workspace }}/infra/ResourceGroups/deploy.resourceGroups.json
        parameters: ${{ github.workspace }}/infra/ResourceGroups/params.resourceGroups.json tags='${{ env.AZURE_TAGS }}'
    
    # Log out from Azure
    - name: Log out from Azure
      id: azure_logout
      uses: azure/cli@v1
      with:
        azcliversion: latest
        inlineScript: |
          az logout

@github-actions github-actions bot removed the default label May 19, 2021
@github-actions
Copy link

This issue is marked default for generating issues report.

@github-actions github-actions bot added default and removed default labels May 19, 2021
@github-actions
Copy link

This issue is marked default for generating issues report.

@github-actions github-actions bot added default and removed default labels May 19, 2021
@marvinbuss
Copy link

I get same error even without storing any AZURE CREDENTIAL. Just running this command without login gives a 'json parse failed' error. I might be wrong but isnt it the behaviour of az comand?

az deployment group validate --resource-group E2eTestResourceGroupForArmAction --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/emptyRG.json --parameters tags='${{ env.AZURE_TAGS }}'

@t-dedah No this is not the behavior of az cli. The issue is, that we are storing a JSON as secret (AZURE_CREDENTIALS). If you remove the reference to it, everything will run just fine. The issue is Azure/login. The Action needs to accept individual secrets rather than a json. This requires an improvment.

@github-actions github-actions bot removed the default label May 28, 2021
@github-actions
Copy link

This issue is marked default for generating issues report.

@github-actions
Copy link

github-actions bot commented Jun 4, 2021

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale 90 days old label Jun 4, 2021
@github-actions
Copy link

This issue is idle because it has been open for 14 days with no activity.

@github-actions github-actions bot added the idle Inactive for 14 days label Jun 29, 2021
simkin2004 added a commit to mytrout/Pipelines that referenced this issue Jul 8, 2021
Attempt to single quote database server name from example in Azure/arm-deploy#36.
Confirmed that parameter spelling is correct.
Confirmed that only valid characters for a SQL Server Server Name are lowercase letters, numbers, and dashes.
@t-dedah t-dedah closed this as completed Sep 6, 2021
@t-dedah t-dedah reopened this Sep 6, 2021
@gummigroda
Copy link

Hi,

Are there any updates regarding how to add for example tags as parameters?
Or even more complex structures as objects in an array?

Tried as sugested:
image

and get the error:
image

Or is it better to skip this action and run a regular shell with AZ CLI ?

@github-actions github-actions bot removed idle Inactive for 14 days stale 90 days old labels Nov 16, 2021
@t-dedah
Copy link
Contributor

t-dedah commented Nov 22, 2021

Hi @gummigroda Can you please try this?

tags="{\"costCenter\":\"12345\", \"owner\":\"IT\", \"Service\": \"Identity\"}"

@marvinbuss
Copy link

I get same error even without storing any AZURE CREDENTIAL. Just running this command without login gives a 'json parse failed' error. I might be wrong but isnt it the behaviour of az comand?

az deployment group validate --resource-group E2eTestResourceGroupForArmAction --template-uri https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/emptyRG.json --parameters tags='${{ env.AZURE_TAGS }}'

@t-dedah No this is not the behavior of az cli. The issue is, that we are storing a JSON as secret (AZURE_CREDENTIALS). If you remove the reference to it, everything will run just fine. The issue is Azure/login. The Action needs to accept individual secrets rather than a json. This requires an improvment.

This is the reason why it will not work. If you use the new Workload Identity Federation, this issue will most likely be solved, as you are not storing a JSON as secret then.

@github-actions
Copy link

github-actions bot commented Dec 3, 2021

This issue is idle because it has been open for 14 days with no activity.

@github-actions github-actions bot added the idle Inactive for 14 days label Dec 3, 2021
@github-actions
Copy link

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale 90 days old label Dec 10, 2021
@t-dedah t-dedah added backlog Planned for future and removed stale 90 days old idle Inactive for 14 days labels Aug 31, 2022
@aavdberg
Copy link

Please try this workflow, then you will see the issue:

name: Deployment

on:
  push:
    branches: [ main ]
    paths:
      - 'infra/**'
  pull_request:
    branches: [ main ]
    paths:
      - 'infra/**'

env:
  AZURE_SUBSCRIPTION_ID: 'your-sub-id'
  AZURE_LOCATION: 'northeurope'
  AZURE_TAGS: '{"costCenter":"ABCD", "owner":"XYZ"}'

jobs:
  create-resource-groups:
    runs-on: ubuntu-latest

    steps:
    # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
    - name: Check Out Repository
      id: checkout_repository
      uses: actions/checkout@v2
    
    # Login to Azure
    - name: Azure Login
      id: azure_login
      uses: azure/login@v1
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    
    # Deploy Resource Groups
    - name: Deploy Resource Groups
      id: resource_groups_deployment
      uses: azure/arm-deploy@v1
      with:
        scope: subscription
        subscriptionId: ${{ env.AZURE_SUBSCRIPTION_ID }}
        region: ${{ env.AZURE_LOCATION }}
        template: ${{ github.workspace }}/infra/ResourceGroups/deploy.resourceGroups.json
        parameters: ${{ github.workspace }}/infra/ResourceGroups/params.resourceGroups.json tags='${{ env.AZURE_TAGS }}'
    
    # Log out from Azure
    - name: Log out from Azure
      id: azure_logout
      uses: azure/cli@v1
      with:
        azcliversion: latest
        inlineScript: |
          az logout

I think you have to put the line between quotes, did you try understanding?

         parameters: "${{ github.workspace }}/infra/ResourceGroups/params.resourceGroups.json tags='${{ env.AZURE_TAGS }}'"

And better to use https://docs.microsoft.com/en-us/azure/active-directory/develop/workload-identity-federation

@t-dedah t-dedah removed the default label Jan 5, 2023
@vRune4
Copy link

vRune4 commented Apr 12, 2024

When googling "azure/arm-deploy json array parameter" this issue is the first hit.

After reading the comments above, I'm none the wiser.

I've tried escaping quotes, encapsulating the whole thing with a single quote and without escapes, and... No go. & gh variable set ELASTIC_POOL_SKU --env dev --body '''{\"name\": \"BasicPool\", \"tier\": \"Basic\", \"capacity\": 50}''' is my last attempt at setting a variable.

 parameters: >
            el_sku=${{vars.ELASTIC_POOL_SKU}}

Result:
Error: ERROR: Failed to parse string as JSON:
'{\maxSizeBytes":5242880000, "perDatabaseSettings":{"maxCapacity": 5, "minCapacity": 0}}' el_sku='{"name": "BasicPool", "tier": "Basic", "capacity": 50}'

Which leads me to believe I should not have escaped the double quotes.

So... Change that so that gh variable list shows:
ELASTIC_POOL_PROPERTIES {"maxSizeBytes":5242880000, "perDatabaseSettings":{"maxCapacity": 5, "minCapacity": 0}}

Error: ERROR: Failed to parse string as JSON:
{maxSizeBytes:5242880000,
Error detail: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

Wait... What?!? gh variable list clearly disagrees. "maxSizeBytes" is definitively quoted.

@anthony-c-martin
Copy link
Member

anthony-c-martin commented Apr 12, 2024

@vRune4 A shot in the dark, but here's what I would try:

Setting the variable:

& gh variable set ELASTIC_POOL_SKU --env dev --body '{"name": "BasicPool", "tier": "Basic", "capacity": 50}'

Using the variable:

 parameters: >
            el_sku='${{vars.ELASTIC_POOL_SKU}}'

@vRune4
Copy link

vRune4 commented Apr 12, 2024

parameters: >
el_sku='${{vars.ELASTIC_POOL_SKU}}'

Quoting the value is one of the things I tried.

It expands into:

parameters: services.json location=norwayeast environment=dev retention=7 project_name=smartskill ip_list=[] elastic_pool_properties='{"maxSizeBytes":5242880000, "perDatabaseSettings":{"maxCapacity": 5, "minCapacity": 0}}' el_sku='{"name": "BasicPool", "tier": "Basic", "capacity": 50}' adAdminUser='***'

(the last parameter is a secret)

Error: ERROR: Failed to parse string as JSON:
'{maxSizeBytes:5242880000,
Error detail: Expecting value: line 1 column 1 (char 0)

If the error message is to be believed, the double quote goes AWOL somewhere along the way. (I am reworking this to single parameters now)

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

No branches or pull requests

8 participants