Skip to content

Commit

Permalink
uses actual args for refs instead of dummies
Browse files Browse the repository at this point in the history
  • Loading branch information
loganpowell committed Oct 25, 2023
1 parent e89b727 commit 1c4a7b6
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 44 deletions.
51 changes: 26 additions & 25 deletions examples/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,6 @@ const subdomains = (
invoke_arn: 'lambda_invoke_arn goes here 📌',
},
},
test2: {
'GET /': {
invoke_arn: 'lambda_invoke_arn goes here 📌',
},
},
},
}: {
apex: string
Expand All @@ -659,43 +654,44 @@ const subdomains = (
) => ({
zone: rout53_zone({ apex }),
...Object.entries(subdomainRoutes).reduce(
(a, [subdomain, routes], i) => ({
(a, [subd, routes], i) => ({
...a,
[`cert_${i}`]: acm_cert({ apex, subdomain }),
[`validation_${i}`]: acm_validation({
cert_arn: my?.[`cert_${i}`]?.resource?.acm_certificate?.arn,
[`cert_${subd}`]: acm_cert({ apex, subdomain: subd }),
[`validation_${subd}`]: acm_validation({
cert_arn: my?.[`cert_${subd}`]?.resource?.acm_certificate?.arn,
}), // TODO
[`domain_${i}`]: api_domain({
subdomain,
[`domain_${subd}`]: api_domain({
subdomain: subd,
apex,
cert_arn: my?.[`cert_${i}`]?.resource?.acm_certificate?.arn,
cert_arn: my?.[`cert_${subd}`]?.resource?.acm_certificate?.arn,
}),
[`record_${i}`]: route53_record({
name: subdomain,
[`record_${subd}`]: route53_record({
name: subd,
api_domain_name:
my?.[`domain_${i}`]?.resource?.apigatewayv2_domain_name
my?.[`domain_${subd}`]?.resource?.apigatewayv2_domain_name
?.domain_name_configuration[0]?.target_domain_name,
api_hosted_zone_id:
my?.[`domain_${i}`]?.resource?.apigatewayv2_domain_name
my?.[`domain_${subd}`]?.resource?.apigatewayv2_domain_name
?.domain_name_configuration[0]?.hosted_zone_id,
route53_zone_id: my?.zone?.data?.route53_zone?.zone_id,
}),
[`gateway_${i}`]: api_gateway({ name: subdomain }),
[`stage_${i}`]: api_stage({
api_id: my?.[`gateway_${i}`]?.resource?.apigatewayv2_api?.id,
[`gateway_${subd}`]: api_gateway({ name: subd }),
[`stage_${subd}`]: api_stage({
api_id: my?.[`gateway_${subd}`]?.resource?.apigatewayv2_api?.id,
}),
...Object.entries(routes).reduce(
(acc, [route, { invoke_arn }], idx) => ({
...acc,
[`integration_${i}_${idx}`]: api_lambda_integration({
api_id: my?.[`gateway_${i}`]?.resource?.apigatewayv2_api?.id,
[`integration_${subd}_${route.split(' ')[0]}`]: api_lambda_integration({
api_id: my?.[`gateway_${subd}`]?.resource?.apigatewayv2_api?.id,
lambda_invoke_arn: invoke_arn,
}),
[`route_${i}_${idx}`]: api_route({
api_id: my?.[`gateway_${i}`]?.resource?.apigatewayv2_api?.id,
[`route_${subd}_${route.split(' ')[0]}`]: api_route({
api_id: my?.[`gateway_${subd}`]?.resource?.apigatewayv2_api?.id,
route_key: route,
integration_id:
my?.[`integration_${i}_${idx}`]?.resource?.apigatewayv2_integration?.id,
my?.[`integration_${subd}_${route.split(' ')[0]}`]?.resource
?.apigatewayv2_integration?.id,
}),
}),
{}
Expand All @@ -715,9 +711,14 @@ const [apiOutput, apiRefs] = moduleAPI({
invoke_arn: functionInvokeArn,
},
},
test2: {
'GET /': {
invoke_arn: 'lambda_invoke_arn goes here 📌',
},
},
},
})
JSON.stringify(apiRefs, null, 4) //
JSON.stringify(apiRefs, null, 4) //?
JSON.stringify(apiOutput, null, 4) //

// ,e, 888 888
Expand Down
115 changes: 99 additions & 16 deletions main.tf.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
}
},
"aws_acm_certificate": {
"subdomains_cert_0": {
"subdomains_cert_test1": {
"domain_name": "chopshop-test.net",
"validation_method": "DNS",
"subject_alternative_names": [
Expand All @@ -145,19 +145,35 @@
"lifecycle": {
"create_before_destroy": true
}
},
"subdomains_cert_test2": {
"domain_name": "chopshop-test.net",
"validation_method": "DNS",
"subject_alternative_names": [
"test2.chopshop-test.net"
],
"tags": {
"BroughtToYouBy": "@-0/micro"
},
"lifecycle": {
"create_before_destroy": true
}
}
},
"aws_acm_certificate_validation": {
"subdomains_validation_0": {
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_0.arn}"
"subdomains_validation_test1": {
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_test1.arn}"
},
"subdomains_validation_test2": {
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_test2.arn}"
}
},
"aws_apigatewayv2_domain_name": {
"subdomains_domain_0": {
"subdomains_domain_test1": {
"domain_name": "test1.chopshop-test.net",
"domain_name_configuration": [
{
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_0.arn}",
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_test1.arn}",
"endpoint_type": "REGIONAL",
"security_policy": "TLS_1_2"
}
Expand All @@ -166,22 +182,46 @@
"Name": "test1.chopshop-test.net",
"BroughtToYouBy": "@-0/micro"
}
},
"subdomains_domain_test2": {
"domain_name": "test2.chopshop-test.net",
"domain_name_configuration": [
{
"certificate_arn": "${resource.aws_acm_certificate.subdomains_cert_test2.arn}",
"endpoint_type": "REGIONAL",
"security_policy": "TLS_1_2"
}
],
"tags": {
"Name": "test2.chopshop-test.net",
"BroughtToYouBy": "@-0/micro"
}
}
},
"aws_route53_record": {
"subdomains_record_0": {
"subdomains_record_test1": {
"name": "test1",
"zone_id": "${data.aws_route53_zone.subdomains_zone.zone_id}",
"type": "A",
"alias": {
"name": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_0.domain_name_configuration[0].target_domain_name}",
"zone_id": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_0.domain_name_configuration[0].hosted_zone_id}",
"name": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_test1.domain_name_configuration[0].target_domain_name}",
"zone_id": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_test1.domain_name_configuration[0].hosted_zone_id}",
"evaluate_target_health": false
}
},
"subdomains_record_test2": {
"name": "test2",
"zone_id": "${data.aws_route53_zone.subdomains_zone.zone_id}",
"type": "A",
"alias": {
"name": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_test2.domain_name_configuration[0].target_domain_name}",
"zone_id": "${resource.aws_apigatewayv2_domain_name.subdomains_domain_test2.domain_name_configuration[0].hosted_zone_id}",
"evaluate_target_health": false
}
}
},
"aws_apigatewayv2_api": {
"subdomains_gateway_0": {
"subdomains_gateway_test1": {
"name": "test1",
"description": "api for test1",
"disable_execute_api_endpoint": false,
Expand All @@ -203,32 +243,75 @@
],
"max_age": 300
}
},
"subdomains_gateway_test2": {
"name": "test2",
"description": "api for test2",
"disable_execute_api_endpoint": false,
"protocol_type": "HTTP",
"cors_configuration": {
"allow_headers": [
"content-type",
"x-amz-date",
"authorization",
"x-api-key",
"x-amz-security-token",
"x-amz-user-agent"
],
"allow_methods": [
"*"
],
"allow_origins": [
"*"
],
"max_age": 300
}
}
},
"aws_apigatewayv2_stage": {
"subdomains_stage_0": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_0.id}",
"subdomains_stage_test1": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test1.id}",
"name": "$default",
"auto_deploy": true,
"description": "stage $default API"
},
"subdomains_stage_test2": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test2.id}",
"name": "$default",
"auto_deploy": true,
"description": "stage $default API"
}
},
"aws_apigatewayv2_integration": {
"subdomains_integration_0_0": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_0.id}",
"subdomains_integration_test1_ANY": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test1.id}",
"integration_uri": "${resource.aws_lambda_function.ms1_lambda.invoke_arn}",
"integration_type": "AWS_PROXY",
"integration_method": "POST",
"connection_type": "INTERNET",
"payload_format_version": "2.0",
"timeout_milliseconds": 29000
},
"subdomains_integration_test2_GET": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test2.id}",
"integration_uri": "lambda_invoke_arn goes here 📌",
"integration_type": "AWS_PROXY",
"integration_method": "POST",
"connection_type": "INTERNET",
"payload_format_version": "2.0",
"timeout_milliseconds": 29000
}
},
"aws_apigatewayv2_route": {
"subdomains_route_0_0": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_0.id}",
"subdomains_route_test1_ANY": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test1.id}",
"route_key": "ANY /",
"target": "integrations/${resource.aws_apigatewayv2_integration.subdomains_integration_0_0.id}"
"target": "integrations/${resource.aws_apigatewayv2_integration.subdomains_integration_test1_ANY.id}"
},
"subdomains_route_test2_GET": {
"api_id": "${resource.aws_apigatewayv2_api.subdomains_gateway_test2.id}",
"route_key": "GET /",
"target": "integrations/${resource.aws_apigatewayv2_integration.subdomains_integration_test2_GET.id}"
}
}
},
Expand Down
7 changes: 4 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,12 @@ export const modulate = <T extends { [key: string]: (...args: any[]) => any }>(
provider = 'aws'
) => {
const [key, fn] = Object.entries(obj)[0]
const defaultArg = parseFirstArgObj(fn)
const ref = { [key]: fn(defaultArg) }
const refs = flattenPreservingPaths(ref, provider, [], {}, true)

//const defaultArg = parseFirstArgObj(fn)

return (...args: [FnParams<T[keyof T]>[0], ...Partial<FnParams<T[keyof T]>>[]]) => {
const ref = { [key]: fn(...args) }
const refs = flattenPreservingPaths(ref, provider, [], {}, true)
// TODO: consider just passing the same arguments to the reference function
const obj = { [key]: fn(...args, refs) }
const out = flattenPreservingPaths(obj, provider, [], {}, false)
Expand Down

0 comments on commit 1c4a7b6

Please sign in to comment.