Skip to content

Commit

Permalink
credscan support dynamic schema
Browse files Browse the repository at this point in the history
  • Loading branch information
teowa committed May 8, 2024
1 parent 354a47c commit de056d6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
14 changes: 13 additions & 1 deletion hcl/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,19 @@ func ParseAzapiResource(f hcl.File) (*[]AzapiResource, []error) {
return nil, errs
}

r.Body = body.AsString()
if body.Type() == cty.String {
r.Body = body.AsString()
} else {
logrus.Debugf("jsonencode for azapi_resource %s with dynamic schema body: %+v", r.Name, body)
// azapi dynamic schema is used
v, err := stdlib.JSONEncode(*body)
if err != nil {
errs = append(errs, fmt.Errorf("jsonencode for azapi dynamic schema: %+v", err))
return nil, errs
}

r.Body = v.AsString()
}
}

results = append(results, r)
Expand Down
48 changes: 48 additions & 0 deletions hcl/testdata/test.tf
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,51 @@ resource "azapi_resource" "virtualMachine2" {
schema_validation_enabled = false
response_export_values = ["*"]
}

resource "azapi_resource" "virtualMachine2_dynamic" {
type = "Microsoft.Compute/virtualMachines@2023-03-01"
parent_id = azapi_resource.resourceGroup.id
name = "${var.resource_name}-2-d"
location = var.location
body = {
properties = {
hardwareProfile = {
vmSize = "Standard_F2"
}
networkProfile = {
networkInterfaces = [
{
id = azapi_resource.networkInterface.id
properties = {
primary = false
}
},
]
}
osProfile = {
adminPassword = var.password
adminUsername = "testadmin"
computerName = "hostname230630032848831820"
linuxConfiguration = {
disablePasswordAuthentication = false
}
}
storageProfile = {
imageReference = {
offer = "UbuntuServer"
publisher = "Canonical"
sku = "16.04-LTS"
version = "latest"
}
osDisk = {
caching = "ReadWrite"
createOption = "FromImage"
name = "myosdisk1"
writeAcceleratorEnabled = false
}
}
}
}
schema_validation_enabled = false
response_export_values = ["*"]
}
14 changes: 14 additions & 0 deletions hcl/testdata/test2.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,17 @@ resource "azapi_resource" "test" {
}
})
}

resource "azapi_resource" "test_dynamic" {
type = "Microsoft.AppPlatform/spring/storages@2024-01-01-preview"
name = "acctest-ss-39"
parent_id = azurerm_spring_cloud_service.test.id

body = {
properties = {
accountKey = azurerm_storage_account.test.primary_access_key
accountName = azurerm_storage_account.test.name
storageType = "StorageAccount"
}
}
}

0 comments on commit de056d6

Please sign in to comment.