@@ -92,13 +92,20 @@ func parseModuleSchemaOverrides(packageName string) []*ModuleSchemaOverride {
92
92
return overrides
93
93
}
94
94
95
+ type SchemaFieldMappings struct {
96
+ ProviderFieldMappings map [string ]string
97
+ InputFieldMappings map [resource.PropertyKey ]resource.PropertyKey
98
+ OutputFieldMappings map [resource.PropertyKey ]resource.PropertyKey
99
+ }
100
+
95
101
type InferredModuleSchema struct {
96
- Inputs map [resource.PropertyKey ]* schema.PropertySpec `json:"inputs"`
97
- Outputs map [resource.PropertyKey ]* schema.PropertySpec `json:"outputs"`
98
- SupportingTypes map [string ]* schema.ComplexTypeSpec `json:"supportingTypes"`
99
- RequiredInputs []resource.PropertyKey `json:"requiredInputs"`
100
- NonNilOutputs []resource.PropertyKey `json:"nonNilOutputs"`
101
- ProvidersConfig schema.ConfigSpec `json:"providersConfig"`
102
+ Inputs map [resource.PropertyKey ]* schema.PropertySpec `json:"inputs"`
103
+ Outputs map [resource.PropertyKey ]* schema.PropertySpec `json:"outputs"`
104
+ SupportingTypes map [string ]* schema.ComplexTypeSpec `json:"supportingTypes"`
105
+ RequiredInputs []resource.PropertyKey `json:"requiredInputs"`
106
+ NonNilOutputs []resource.PropertyKey `json:"nonNilOutputs"`
107
+ ProvidersConfig schema.ConfigSpec `json:"providersConfig"`
108
+ SchemaFieldMappings * SchemaFieldMappings `json:"schemaFieldMappings,omitempty"`
102
109
}
103
110
104
111
var stringType = schema.TypeSpec {Type : "string" }
@@ -343,6 +350,10 @@ func InferModuleSchema(
343
350
return inferModuleSchema (ctx , tf , packageName , mod , ver , newComponentLogger (nil , nil ))
344
351
}
345
352
353
+ func containsDash (s string ) bool {
354
+ return strings .Contains (s , "-" )
355
+ }
356
+
346
357
func inferModuleSchema (
347
358
ctx context.Context ,
348
359
tf * tfsandbox.ModuleRuntime ,
@@ -365,10 +376,26 @@ func inferModuleSchema(
365
376
ProvidersConfig : schema.ConfigSpec {
366
377
Variables : map [string ]schema.PropertySpec {},
367
378
},
379
+ SchemaFieldMappings : & SchemaFieldMappings {
380
+ InputFieldMappings : make (map [resource.PropertyKey ]resource.PropertyKey ),
381
+ OutputFieldMappings : make (map [resource.PropertyKey ]resource.PropertyKey ),
382
+ ProviderFieldMappings : make (map [string ]string ),
383
+ },
368
384
}
369
385
386
+ providerFieldMappings := inferredModuleSchema .SchemaFieldMappings .ProviderFieldMappings
387
+ inputFieldMappings := inferredModuleSchema .SchemaFieldMappings .InputFieldMappings
388
+ outputFieldMappings := inferredModuleSchema .SchemaFieldMappings .OutputFieldMappings
389
+
370
390
if module .ProviderRequirements != nil {
371
391
for providerName := range module .ProviderRequirements .RequiredProviders {
392
+ if containsDash (providerName ) {
393
+ // fields with dashes are not valid in Pulumi
394
+ // so we replace dashes with underscores
395
+ pulumiName := strings .ReplaceAll (providerName , "-" , "_" )
396
+ providerFieldMappings [pulumiName ] = providerName
397
+ providerName = pulumiName
398
+ }
372
399
inferredModuleSchema .ProvidersConfig .Variables [providerName ] = schema.PropertySpec {
373
400
Description : "provider configuration for " + providerName ,
374
401
TypeSpec : mapType (anyType ),
@@ -377,6 +404,14 @@ func inferModuleSchema(
377
404
}
378
405
379
406
for variableName , variable := range module .Variables {
407
+ if containsDash (variableName ) {
408
+ // fields with dashes are not valid in Pulumi
409
+ // so we replace dashes with underscores
410
+ pulumiName := strings .ReplaceAll (variableName , "-" , "_" )
411
+ inputFieldMappings [resource .PropertyKey (pulumiName )] = resource .PropertyKey (variableName )
412
+ variableName = pulumiName
413
+ }
414
+
380
415
variableType := convertType (variable .Type , variableName , packageName , inferredModuleSchema .SupportingTypes )
381
416
382
417
key := tfsandbox .PulumiTopLevelKey (variableName )
@@ -395,11 +430,21 @@ func inferModuleSchema(
395
430
}
396
431
397
432
for outputName , output := range module .Outputs {
433
+ if containsDash (outputName ) {
434
+ // fields with dashes are not valid in Pulumi
435
+ // so we replace dashes with underscores
436
+ pulumiName := strings .ReplaceAll (outputName , "-" , "_" )
437
+ outputFieldMappings [resource .PropertyKey (pulumiName )] = resource .PropertyKey (outputName )
438
+ outputName = pulumiName
439
+ }
440
+
398
441
// TODO[pulumi/pulumi-terraform-module#70] reconsider output type inference vs config
399
442
var inferredType schema.TypeSpec
400
443
if referencedVariableName , ok := isVariableReference (output .Expr ); ok {
401
444
k := tfsandbox .PulumiTopLevelKey (referencedVariableName )
402
- inferredType = inferredModuleSchema .Inputs [k ].TypeSpec
445
+ tfName := string (k )
446
+ pulumiInputName := resource .PropertyKey (strings .ReplaceAll (tfName , "-" , "_" ))
447
+ inferredType = inferredModuleSchema .Inputs [pulumiInputName ].TypeSpec
403
448
} else {
404
449
inferredType = inferExpressionType (output .Expr )
405
450
}
0 commit comments