-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Ryan Cartwright <[email protected]> Co-authored-by: Jye Cusch <[email protected]>
- Loading branch information
1 parent
f74db93
commit 39315ef
Showing
177 changed files
with
12,695 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
dist/ | ||
deploy/runtime-aws | ||
deploytf/runtime/runtime-aws | ||
common/runtime/runtime-aws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright Nitric Pty Ltd. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/nitrictech/nitric/cloud/aws/common/runtime" | ||
"github.com/nitrictech/nitric/cloud/aws/deploytf" | ||
"github.com/nitrictech/nitric/cloud/common/deploy/provider" | ||
) | ||
|
||
// Start the deployment server | ||
func main() { | ||
// os.Setenv("JSII_SILENCE_WARNING_UNTESTED_NODE_VERSION", "true") | ||
// os.Setenv("SYNTH_HCL_OUTPUT", "true") | ||
awsStack := deploytf.NewNitricAwsProvider() | ||
|
||
providerServer := provider.NewTerraformProviderServer(awsStack, runtime.NitricAwsRuntime) | ||
|
||
// Start the terraform provider server | ||
providerServer.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
// Copyright Nitric Pty Ltd. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package common | ||
|
||
import ( | ||
"github.com/imdario/mergo" | ||
"github.com/mitchellh/mapstructure" | ||
"github.com/nitrictech/nitric/cloud/common/deploy/config" | ||
) | ||
|
||
type ApiConfig struct { | ||
Domains []string | ||
} | ||
|
||
type AwsImports struct { | ||
// A map of nitric names to ARNs | ||
Secrets map[string]string | ||
} | ||
|
||
type AwsConfig struct { | ||
ScheduleTimezone string `mapstructure:"schedule-timezone,omitempty"` | ||
Import AwsImports | ||
Refresh bool | ||
Apis map[string]*ApiConfig | ||
config.AbstractConfig[*AwsConfigItem] `mapstructure:"config,squash"` | ||
} | ||
|
||
type AwsConfigItem struct { | ||
Lambda *AwsLambdaConfig `mapstructure:",omitempty"` | ||
Telemetry int | ||
} | ||
|
||
type AwsLambdaVpcConfig struct { | ||
SubnetIds []string `mapstructure:"subnet-ids"` | ||
SecurityGroupIds []string `mapstructure:"security-group-ids"` | ||
} | ||
|
||
type AwsLambdaConfig struct { | ||
Memory int | ||
Timeout int | ||
ProvisionedConcurreny int `mapstructure:"provisioned-concurrency"` | ||
Vpc *AwsLambdaVpcConfig `mapstructure:"vpc,omitempty"` | ||
} | ||
|
||
var defaultLambdaConfig = &AwsLambdaConfig{ | ||
Memory: 128, | ||
Timeout: 15, | ||
ProvisionedConcurreny: 0, | ||
} | ||
|
||
var defaultAwsConfigItem = AwsConfigItem{ | ||
Telemetry: 0, | ||
} | ||
|
||
// Return AwsConfig from stack attributes | ||
func ConfigFromAttributes(attributes map[string]interface{}) (*AwsConfig, error) { | ||
// get config attributes | ||
err := config.ValidateRawConfigKeys(attributes, []string{"lambda"}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
awsConfig := &AwsConfig{} | ||
err = mapstructure.Decode(attributes, awsConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// Default timezone if not specified | ||
if awsConfig.ScheduleTimezone == "" { | ||
// default to UTC | ||
awsConfig.ScheduleTimezone = "UTC" | ||
} | ||
|
||
if awsConfig.Apis == nil { | ||
awsConfig.Apis = map[string]*ApiConfig{} | ||
} | ||
|
||
if awsConfig.Config == nil { | ||
awsConfig.Config = map[string]*AwsConfigItem{} | ||
} | ||
|
||
// if no default then set provider level defaults | ||
if _, hasDefault := awsConfig.Config["default"]; !hasDefault { | ||
awsConfig.Config["default"] = &defaultAwsConfigItem | ||
awsConfig.Config["default"].Lambda = defaultLambdaConfig | ||
} | ||
|
||
for configName, configVal := range awsConfig.Config { | ||
// Add omitted values from default configs where needed. | ||
err := mergo.Merge(configVal, defaultAwsConfigItem) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if configVal.Lambda == nil { // check if no runtime config provided, default to Lambda. | ||
configVal.Lambda = defaultLambdaConfig | ||
} else { | ||
err := mergo.Merge(configVal.Lambda, defaultLambdaConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
awsConfig.Config[configName] = configVal | ||
} | ||
|
||
return awsConfig, nil | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
resource "aws_apigatewayv2_api" "api_gateway" { | ||
name = var.name | ||
protocol_type = "HTTP" | ||
body = var.spec | ||
tags = { | ||
"x-nitric-${var.stack_id}-name" = var.name, | ||
"x-nitric-${var.stack_id}-type" = "api", | ||
} | ||
} | ||
|
||
resource "aws_apigatewayv2_stage" "stage" { | ||
api_id = aws_apigatewayv2_api.api_gateway.id | ||
name = "$default" | ||
auto_deploy = true | ||
} | ||
|
||
# deploy lambda permissions for execution | ||
resource "aws_lambda_permission" "apigw_lambda" { | ||
for_each = var.target_lambda_functions | ||
action = "lambda:InvokeFunction" | ||
function_name = each.value | ||
principal = "apigateway.amazonaws.com" | ||
source_arn = "${aws_apigatewayv2_api.api_gateway.execution_arn}/*/*/*" | ||
} | ||
|
||
# look up existing certificate for domains | ||
data "aws_acm_certificate" "cert" { | ||
for_each = var.domains | ||
domain = each.value | ||
} | ||
|
||
# deploy custom domain names | ||
resource "aws_apigatewayv2_domain_name" "domain" { | ||
for_each = var.domains | ||
domain_name = each.value | ||
domain_name_configuration { | ||
certificate_arn = data.aws_acm_certificate.cert[each.key].arn | ||
endpoint_type = "REGIONAL" | ||
security_policy = "TLS_1_2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "endpoint" { | ||
value = aws_apigatewayv2_api.api_gateway.api_endpoint | ||
} |
Oops, something went wrong.