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

armstrong credscan - support dynamic schema #101

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}
}
Loading