Skip to content
Draft
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
4 changes: 4 additions & 0 deletions engines/terraform/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type TerraformDeployment struct {
identityBlueprints map[string]*ResourceBlueprint
terraformVariables map[string]cdktf.TerraformVariable
instancedTerraformVariables map[string]map[string]cdktf.TerraformVariable
sugaProperties map[string]interface{}
}

func NewTerraformDeployment(engine *TerraformEngine, stackName string) *TerraformDeployment {
Expand Down Expand Up @@ -60,6 +61,9 @@ func NewTerraformDeployment(engine *TerraformEngine, stackName string) *Terrafor
terraformVariables: map[string]cdktf.TerraformVariable{},
instancedTerraformVariables: map[string]map[string]cdktf.TerraformVariable{},
serviceIdentities: map[string]map[string]interface{}{},
sugaProperties: map[string]interface{}{
"stack_id": stackId.Result(),
},
}
}

Expand Down
20 changes: 20 additions & 0 deletions engines/terraform/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ func (td *TerraformDeployment) resolveToken(intentName string, specRef *SpecRefe
}
return tfVariable.Value(), nil

case "suga":
if len(specRef.Path) < 1 {
return nil, fmt.Errorf("suga reference requires at least 1 path component (e.g., suga.stack_id)")
}

propertyName := specRef.Path[0]

value, ok := td.sugaProperties[propertyName]
if !ok {
availableProps := slices.Collect(maps.Keys(td.sugaProperties))
return nil, fmt.Errorf("suga property '%s' does not exist. Available properties are: %v", propertyName, availableProps)
}

// If there are nested path components, we don't support that for suga properties currently
if len(specRef.Path) > 1 {
return nil, fmt.Errorf("nested property access is not supported for suga properties (attempted: suga.%s)", strings.Join(specRef.Path, "."))
}

return value, nil

default:
return nil, fmt.Errorf("unknown reference source '%s'", specRef.Source)
}
Expand Down
4 changes: 2 additions & 2 deletions engines/terraform/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ func isOnlyToken(input string) bool {
return strings.TrimSpace(input) == strings.TrimSpace(allTokensPattern.FindString(input))
}

var tokenPattern = regexp.MustCompile(`((?:infra|var|self)\.[a-zA-Z_\-][a-zA-Z0-9_\-\.]*)`)
var allTokensPattern = regexp.MustCompile(`((?:infra|var|self)\.[a-zA-Z_\-][a-zA-Z0-9_\-\.]*)`)
var tokenPattern = regexp.MustCompile(`((?:infra|var|self|suga)\.[a-zA-Z_\-][a-zA-Z0-9_\-\.]*)`)
var allTokensPattern = regexp.MustCompile(`((?:infra|var|self|suga)\.[a-zA-Z_\-][a-zA-Z0-9_\-\.]*)`)
Loading