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

Fix casing on app_runner environment variables #782

Merged
merged 2 commits into from
Nov 27, 2023
Merged
Changes from 1 commit
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
29 changes: 16 additions & 13 deletions pkg/infra/iac3/resource.go
Original file line number Diff line number Diff line change
@@ -88,8 +88,7 @@ func (tc *TemplatesCompiler) convertArg(arg any, templateArg *Arg) (any, error)
return arg, nil

case nil:
// don't add to inputs
return nil, nil
return undefined, nil

default:
switch val := reflect.ValueOf(arg); val.Kind() {
@@ -117,13 +116,17 @@ func (tc *TemplatesCompiler) convertArg(arg any, templateArg *Arg) (any, error)
return "", fmt.Errorf("map key is not a string")
}
keyResult := strcase.ToLowerCamel(keyStr)
if templateArg != nil && templateArg.Wrapper == string(CamelCaseWrapper) {
keyResult = strcase.ToCamel(keyStr)
} else if templateArg != nil && templateArg.Wrapper == string(ModelCaseWrapper) {
if validIdentifierPattern.MatchString(keyStr) {
keyResult = keyStr
} else {
keyResult = fmt.Sprintf(`"%s"`, keyStr)
if templateArg != nil {
switch templateArg.Wrapper {
case CamelCaseWrapper:
keyResult = strcase.ToCamel(keyStr)

case ModelCaseWrapper:
if validIdentifierPattern.MatchString(keyStr) {
keyResult = keyStr
} else {
keyResult = fmt.Sprintf(`"%s"`, keyStr)
}
}
}
output, err := tc.convertArg(val.MapIndex(key).Interface(), templateArg)
@@ -153,7 +156,7 @@ func (tc *TemplatesCompiler) getInputArgs(r *construct.Resource, template *Resou
templateArg := template.Args[name]
var argValue any
var err error
if templateArg.Wrapper == string(TemplateWrapper) {
if templateArg.Wrapper == TemplateWrapper {
argValue, err = tc.useNestedTemplate(template, value, templateArg)
if err != nil {
errs = errors.Join(errs, fmt.Errorf("could not use nested template for arg %q: %w", name, err))
@@ -305,13 +308,13 @@ func (tc *TemplatesCompiler) useNestedTemplate(resTmpl *ResourceTemplate, val an
}

func (tc *TemplatesCompiler) modelCase(val any) (any, error) {
return tc.convertArg(val, &Arg{Wrapper: string(ModelCaseWrapper)})
return tc.convertArg(val, &Arg{Wrapper: ModelCaseWrapper})
}

func (tc *TemplatesCompiler) lowerCamelCase(val any) (any, error) {
return tc.convertArg(val, &Arg{Wrapper: string(LowerCamelCaseWrapper)})
return tc.convertArg(val, &Arg{Wrapper: LowerCamelCaseWrapper})
}

func (tc *TemplatesCompiler) camelCase(val any) (any, error) {
return tc.convertArg(val, &Arg{Wrapper: string(CamelCaseWrapper)})
return tc.convertArg(val, &Arg{Wrapper: CamelCaseWrapper})
}
4 changes: 2 additions & 2 deletions pkg/infra/iac3/resource_template.go
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ type (
Arg struct {
Name string
Type string
Wrapper string
Wrapper WrapperType
}

WrapperType string
@@ -129,7 +129,7 @@ func parseArgs(node *sitter.Node, name string) (map[string]Arg, error) {
args[argName] = Arg{Name: argName, Type: argType}
continue
}
args[argName] = Arg{Name: argName, Type: argType, Wrapper: argWrapper.Content()}
args[argName] = Arg{Name: argName, Type: argType, Wrapper: WrapperType(argWrapper.Content())}
}

return args, nil
11 changes: 11 additions & 0 deletions pkg/infra/iac3/template_types.go
Original file line number Diff line number Diff line change
@@ -35,8 +35,19 @@ type (
}

appliedOutputs []appliedOutput

// undefinedT is a helper type to represent the `undefined` value in a template. It is needed over just using
// "undefined" because the string is not false-y.
undefinedT string
)

// undefined is false-y in a template (if used in an `if`), but resolves to `undefined` when rendered.
var undefined = undefinedT("")

func (undefinedT) String() string {
return "undefined"
}

func (tc TemplatesCompiler) NewAppliedOutput(ref construct.PropertyRef, name string) appliedOutput {
ao := appliedOutput{Name: name}
if ao.Name == "" {
11 changes: 10 additions & 1 deletion pkg/infra/iac3/templates/aws/app_runner_service/factory.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import * as aws from '@pulumi/aws'
import * as docker from '@pulumi/docker'
import * as pulumi from '@pulumi/pulumi'
import { ModelCaseWrapper } from '../../wrappers'

interface Args {
Name: string
Image: docker.Image
InstanceRole: aws.iam.Role
EnvironmentVariables: Record<string, pulumi.Output<string>>
EnvironmentVariables: ModelCaseWrapper<Record<string, pulumi.Output<string>>>
Port: number
}

// noinspection JSUnusedLocalSymbols
@@ -20,9 +22,16 @@ function create(args: Args): aws.apprunner.Service {
imageRepository: {
imageIdentifier: args.Image.imageName,
imageRepositoryType: 'ECR',
//TMPL {{- if (or .Port .EnvironmentVariables) }}
imageConfiguration: {
//TMPL {{- if .Port }}
port: 'args.Port',
//TMPL {{- end }}
//TMPL {{- if .EnvironmentVariables }}
runtimeEnvironmentVariables: args.EnvironmentVariables,
//TMPL {{- end }}
},
//TMPL {{- end }}
},
},
instanceConfiguration: {
1 change: 1 addition & 0 deletions pkg/infra/iac3/templates/aws/rds_instance/factory.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as pulumi from '@pulumi/pulumi'
import * as aws from '@pulumi/aws'
import { accountId, region, kloConfig } from '../../globals'

12 changes: 12 additions & 0 deletions pkg/templates/aws/resources/app_runer_service.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
qualified_type_name: aws:app_runner_service
display_name: App Runner
sanitize_name:
# https://docs.aws.amazon.com/apprunner/latest/api/API_Service.html (ServiceName)
# Pattern: [A-Za-z0-9][A-Za-z0-9-_]{3,39}
|
{{ .
| replace `^[^A-Za-z0-9]+` ""
| replace `[^A-Za-z0-9-_]+` ""
| length 4 40
}}

properties:
Image:
@@ -20,6 +29,9 @@ properties:
unique: true
EnvironmentVariables:
type: map(string,string)
Port:
type: number
default_value: 8080

classification:
is: