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

Decompile fails to parse apiVersion when type has a trailing / #2162

Closed
stan-sz opened this issue Apr 7, 2021 · 1 comment · Fixed by #5887
Closed

Decompile fails to parse apiVersion when type has a trailing / #2162

stan-sz opened this issue Apr 7, 2021 · 1 comment · Fixed by #5887
Labels
bug Something isn't working story: decompiler
Milestone

Comments

@stan-sz
Copy link
Contributor

stan-sz commented Apr 7, 2021

Bicep version
Bicep CLI version 0.3.126 (a5e4c2e)

Describe the bug
In a valid ARM Json template, the type can have a trailing /. This causes the decompiler to trip over it and fail to parse the apiVersion correctly

To Reproduce

> cat test.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "functions": [],
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts/",
      "apiVersion": "2021-01-01",
      "name": "foo",
      "kind": "StorageV2",
      "location": "",
      "sku": {
        "name": "Standard_RAGRS"
      }
    }
  ]
}
> bicep decompile test.json
test.bicep(1,14) : Error BCP029: The resource type is not valid. Specify a valid resource type of format "<provider>/<types>@<apiVersion>".
> cat test.bicep
resource foo 'Microsoft.Storage/storageAccounts/@2021-01-01' = {
  name: 'foo'
  kind: 'StorageV2'
  location: ''
  sku: {
    name: 'Standard_RAGRS'
  }
}
@ghost ghost added the Needs: Triage 🔍 label Apr 7, 2021
@anthony-c-martin
Copy link
Member

I think the fix should be to add a .Trim('/') after .ToString() on this line:

var type = AssertRequiredProperty(resource, "type", $"Unable to parse \"type\" for resource").ToString();

@alex-frankel alex-frankel added bug Something isn't working and removed Needs: Triage 🔍 labels Apr 8, 2021
@alex-frankel alex-frankel added this to the v0.4 milestone Apr 8, 2021
@alex-frankel alex-frankel modified the milestones: v0.4, v0.5 Jun 3, 2021
@ghost ghost locked as resolved and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working story: decompiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants