diff --git a/src/arm/helpers.go b/src/arm/helpers.go index 3041cc6..591aaed 100644 --- a/src/arm/helpers.go +++ b/src/arm/helpers.go @@ -1,6 +1,7 @@ package arm import ( + "strconv" "strings" "github.com/rs/zerolog/log" @@ -50,21 +51,73 @@ func fixType(myItem map[string]interface{}) map[string]interface{} { switch myType { case "object": { - myItem["type"] = "object()" + var types string + var result string + + for name, item := range myItem["defaultValue"].(map[string]interface{}) { + + switch item.(type) { + case []interface{}: + { + var temp string + var temptTypes string + var myType string + for _, y := range item.([]interface{}) { + for name, value := range y.(map[string]interface{}) { + temp = temp + "\t " + name + " = \"" + value.(string) + "\"\n" + myType = myType + "\t " + name + " = string\n" + } + temp = "{\n" + strings.TrimSuffix(temp, "\n") + "}" + temptTypes = "{\n" + strings.TrimSuffix(myType, "\n") + "}" + } + if result != "" { + result = result + "," + name + "= [" + temp + "]" + types = types + "," + name + "= list(object(" + temptTypes + "))" + } else { + result = result + name + "= [" + temp + "]" + types = types + name + "= list(object(" + temptTypes + "))" + } + } + case map[string]interface{}: + { + log.Print(item) + } + case string: + { + log.Print(item) + } + case bool: + { + if result == "" { + result = name + " = " + strconv.FormatBool(item.(bool)) + types = name + " = " + "bool" + } else { + temp := result + result = temp + ",\n\t" + name + " = " + strconv.FormatBool(item.(bool)) + types = types + ",\n\t" + name + " = " + "bool" + } + + } + default: + { + log.Print(item) + } + } + } + myItem["default"] = "{\n\t" + result + "}" + myItem["type"] = "object({\n\t" + types + "})" } case "int", "float": { myItem["type"] = "number" } - case "string", "map[string]interface{}": + case "map[string]interface{}": { myItem["type"] = "string" } - case "securestring": + case "list(string)", "string", "number", "securestring": { - { - myItem["type"] = "securestring" - } + //do nothing- should move this all to preprocess } default: { @@ -73,3 +126,15 @@ func fixType(myItem map[string]interface{}) map[string]interface{} { } return myItem } + +func arrayToString(defaultValue []interface{}) string { + var newValue = "[" + for count, value := range defaultValue { + if count == len(defaultValue)-1 { + newValue = newValue + "\"" + value.(string) + "\"" + } else { + newValue = newValue + "\"" + value.(string) + "\"" + "," + } + } + return newValue + "]" +} diff --git a/src/arm/lookup.go b/src/arm/lookup.go index 8cc4e74..db1fec0 100644 --- a/src/arm/lookup.go +++ b/src/arm/lookup.go @@ -13,6 +13,7 @@ func lookup(myType string) []byte { "Microsoft.Storage/storageAccounts": azurermStorageAccount, "Microsoft.Network/virtualNetworks/subnets": azurermSubnet, "Microsoft.AnalysisServices/servers": azurermAnalysisServicesServer, + "Microsoft.ApiManagement/service": azurermApiManagement, } var myContent []byte diff --git a/src/arm/parse.go b/src/arm/parse.go index e00203e..e6fe351 100644 --- a/src/arm/parse.go +++ b/src/arm/parse.go @@ -140,7 +140,6 @@ func ParseVariables(result map[string]interface{}, funcMap tftemplate.FuncMap, d myItem["name"] = name myItem["type"] = "string" - //myItem["type"] = reflect.TypeOf(value).String() } myItem = fixType(myItem) @@ -655,17 +654,32 @@ func preprocess(results map[string]interface{}) map[string]interface{} { if strings.Contains(defaultValue, "[") { newLocals[item] = defaultValue } + myResult["default"] = myResult["defaultValue"].(string) } - case "int", "object": + case "int": { - + myResult["type"] = "number" + paraParameters[item] = myResult + myResult["default"] = fmt.Sprintf("%v", myResult["defaultValue"].(float64)) + } + case "object", "list(string)": + { + //todo + //myResult["default"] = myResult["defaultValue"] + myResult["default"] = "" + } + case "array": + { + myResult["type"] = "list(string)" + myResult["default"] = arrayToString(myResult["defaultValue"].([]interface{})) + paraParameters[item] = myResult } default: { log.Printf("unhandled %s", myType) } } - + results["parameters"] = paraParameters } else { continue } diff --git a/src/arm/resources.go b/src/arm/resources.go index 5f350f4..6f9769d 100644 --- a/src/arm/resources.go +++ b/src/arm/resources.go @@ -30,3 +30,6 @@ var azurermSubnet []byte //go:embed resources/azurerm_analysis_services_server.template var azurermAnalysisServicesServer []byte + +//go:embed resources/azurerm_api_management.template +var azurermApiManagement []byte diff --git a/src/arm/resources/azurerm_analysis_services_server.template b/src/arm/resources/azurerm_analysis_services_server.template index 9960d6b..8648e58 100644 --- a/src/arm/resources/azurerm_analysis_services_server.template +++ b/src/arm/resources/azurerm_analysis_services_server.template @@ -13,7 +13,7 @@ resource "azurerm_analysis_services_server" "{{.item}}" { sku = {{ .resource.sku.name|Quote }} {{- if .resource.properties.adminUsers}} admin_users = {{Array .resource.properties.adminUsers}} -{{- end}}1 +{{- end}} {{- if .resource.properties.querypoolConnectionMode}} querypool_connection_mode = {{ .resource.properties.querypoolConnectionMode}} {{- end}} diff --git a/src/arm/resources/azurerm_api_management.template b/src/arm/resources/azurerm_api_management.template new file mode 100644 index 0000000..ea8a279 --- /dev/null +++ b/src/arm/resources/azurerm_api_management.template @@ -0,0 +1,79 @@ +resource "azurerm_api_management" "{{.item}}" { +{{- if .resource.location}} + location = {{ .resource.location|Quote }} +{{- else}} + location = data.azurerm_resource_group.sato.location +{{- end }} + name = {{ .resource.name|Quote }} +{{- if .resource.resourceGroupName }} + resource_group_name = {{ .resource.resourceGroupName|Quote }} +{{- else }} + resource_group_name = data.azurerm_resource_group.sato.name +{{- end}} + publisher_name = {{ .resource.properties.publisherName}} + publisher_email = {{ .resource.properties.publisherEmail}} + sku_name = {{ .resource.sku.name}} +{{- if .resource.additionalLocation}} + additional_location={{ .resource.additionalLocation}} +{{- end}} +{{- if .resource.certificate}} + certificate={{ .resource.certificate}} +{{- end}} +{{- if .resource.clientCertificateEnabled }} + client_certificate_enabled={{ .resource.clientCertificateEnabled}} +{{- end}} +{{- if .resource.delegation}} + delegation={{ .resource.delegation}} +{{- end}} +{{- if .resource.delegation}} + gateway_disabled={{ .resource.delegation}} +{{- end}} +{{- if .resource.delegation}} + min_api_version={{ .resource.delegation}} +{{- end}} +{{- if .resource.delegation}} + zones={{ .resource.delegation}} +{{- end}} +{{- if .resource.delegation}} + identity={{ .resource.delegation}} +{{- end}} +{{- if .resource.hostnameConfiguration}} + hostname_configuration={{ .resource.hostnameConfiguration}} +{{- end}} +{{- if .resource.notificationSenderEmails}} + notification_sender_email={{ .resource.notificationSenderEmails}} +{{- end}} +{{- if .resource.policy}} + policy ={{ .resource.policy}} +{{- end}} +{{- if .resource.policy}} + protocols={{ .resource.protocols}} +{{- end}} +{{- if .resource.security}} + security={{ .resource.security}} +{{- end}} +{{- if .resource.signIn}} + sign_in={{ .resource.signIn}} +{{- end}} +{{- if .resource.signUp}} + sign_up={{ .resource.signUp}} +{{- end}} +{{- if .resource.tenantAccess}} + tenant_access={{ .resource.tenantAccess}} +{{- end}} +{{- if .resource.publicIpAddressId}} + public_ip_address_id={{ .resource.publicIpAddressId}} +{{- end}} +{{- if .resource.publicNetworkAccessEnabled}} + public_network_access_enabled={{ .resource.publicNetworkAccessEnabled}} +{{- end}} +{{- if .resource.virtualNetworkType}} + virtual_network_type={{ .resource.virtualNetworkType}} +{{- end}} +{{- if .resource.virtualNetworkConfiguration}} + virtual_network_configuration={{ .resource.virtualNetworkConfiguration}} +{{- end}} +{{- if .resource.tags}} + tags={{ .resource.tags}} +{{- end}} +} \ No newline at end of file diff --git a/src/arm/variable.template b/src/arm/variable.template index 3128ad8..385deb5 100644 --- a/src/arm/variable.template +++ b/src/arm/variable.template @@ -7,7 +7,11 @@ variable "{{.item}}" { type = {{.variable.type}} {{- end }} {{- if .variable.default}} - default = {{ Replace .variable.default "${" "$${"|Quote }} +{{- if or (eq .variable.type "string") (eq .variable.type "securestring")}} + default = {{ Replace .variable.default "${" "$${" | Quote }} +{{- else}} + default = {{ Replace .variable.default "${" "$${"}} +{{- end }} {{- end }} {{- if .variable.metadata.description }} description = "{{ .variable.metadata.description }}" diff --git a/src/helpers.go b/src/helpers.go index 2c4b84d..267c17a 100644 --- a/src/helpers.go +++ b/src/helpers.go @@ -51,7 +51,8 @@ func Dequote(target string) string { // Quote is a template function func Quote(target string) string { //is it a resource or variable - if strings.Contains(target, "var.") || strings.Contains(target, "_") { + if strings.Contains(target, "var.") || + (strings.Contains(target, "_") && strings.Contains(target, ".")) { return target } return "\"" + target + "\"" diff --git a/src/see/lookup.go b/src/see/lookup.go index 19dd305..169fd01 100644 --- a/src/see/lookup.go +++ b/src/see/lookup.go @@ -120,15 +120,22 @@ func Lookup(resource string) (*string, error) { "AWS::ServiceDiscovery::Service": "aws_service_discovery_service", "AWS::StepFunctions::StateMachine": "aws_sfn_state_machine", "AWS::WAFv2::WebACLAssociation": "aws_wafv2_webacl_association", + "Microsoft.AnalysisServices/servers": "azurerm_analysis_services_server", + "Microsoft.ApiManagement/service": "azurerm_api_management", + "Microsoft.App/containerApps": "azurerm_container_app", + "Microsoft.App/managedEnvironments": "azurerm_app_service_environment", + "Microsoft.Authorization/roleAssignments": "azurerm_role_assignment", "Microsoft.Compute/virtualMachines": "azurerm_virtual_machine", "Microsoft.Compute/virtualMachines/extensions": "azurerm_virtual_machine_extension", + "Microsoft.ManagedIdentity/userAssignedIdentities": "azurerm_user_assigned_identity", "Microsoft.Network/networkInterfaces": "azurerm_network_interface", "Microsoft.Network/networkSecurityGroups": "azurerm_network_security_group", "Microsoft.Network/publicIPAddresses": "azurerm_public_ip", "Microsoft.Network/virtualNetworks": "azurerm_virtual_network", - "Microsoft.Storage/storageAccounts": "azurerm_storage_account", "Microsoft.Network/virtualNetworks/subnets": "azurerm_subnet", - "Microsoft.AnalysisServices/servers": "azurerm_analysis_services_server", + "Microsoft.OperationalInsights/workspaces": "azurerm_log_analytics_workspace", + "Microsoft.Resources/deployments": "azurerm_template_deployment", + "Microsoft.Storage/storageAccounts": "azurerm_storage_account", } result := Lookup[resource] var err error