|
| 1 | +<img src="https://user-images.githubusercontent.com/44297242/188002580-ba0a6d59-8b1c-475e-bd61-192dd952194f.png" alt="drawing" style="width:400px;"/> |
| 2 | + |
| 3 | +# spectral-lambda-integration |
| 4 | + |
| 5 | +Terraform configuration used to create the required AWS resources for integrating between Spectral and external service providers. |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +| Name | Version | |
| 10 | +| ----------- | ----------- | |
| 11 | +| [terraform](https://www.terraform.io/downloads) | ~> 1.2.0 | |
| 12 | + |
| 13 | +## Providers |
| 14 | + |
| 15 | +| Name | Version | |
| 16 | +| ----------- | ----------- | |
| 17 | +| [aws](https://registry.terraform.io/providers/hashicorp/aws/latest/docs) | ~> 4.9 | |
| 18 | + |
| 19 | +## Inputs |
| 20 | + |
| 21 | +| Name | Description | Type | Default | Required | |
| 22 | +| ----------- | ----------- | ----------- | ----------- | ----------- | |
| 23 | +| `account_id` | AWS Account ID number of the account in which to manage resources. | `number` | N/A | Yes | |
| 24 | +| `aws_region` | The region in which to manage resources.| `string` | N/A | Yes | |
| 25 | +| `environment` | The target environment name for deployment | `string` | `prod` | No | |
| 26 | +| `integration_type` | Spectral integration type (A unique phrase describing the integration) - Available values: `terraform` | `string` | N/A | Yes | |
| 27 | +| [`env_vars`](#env_vars) | Extendable object contains all required environment variables required for the integration. | `map(string)` | N/A | No | |
| 28 | +| [`global_tags`](#global_tags) | Tags to be applied on every newly created resource. | `map(string)` | ```{ BusinessUnit = "Spectral" }``` | No | |
| 29 | +| [`tags`](#tags) | Tags to be applied on concrete resources | `map(map(string))` | ```{ iam = { } lambda = { } api_gateway = { } }``` | No | |
| 30 | +| `lambda_enable_logs` | Specifies if Lambda should have CloudWatch a dedicated logs group. | `bool` | `false` | No | |
| 31 | +| `lambda_logs_retention_in_days` | Specifies the number of days you want to retain log events in the specified log group. | `number` | `30` | No | |
| 32 | +| `lambda_function_timeout` | Amount of time your Lambda Function has to run in seconds. | `number` | 300 | No | |
| 33 | +| `lambda_function_memory_size` | Amount of memory in MB your Lambda Function can use at runtime. | `number` | 1024 | No | |
| 34 | +| `lambda_publish` | Whether to publish creation/change as new Lambda Function Version. | `bool` | `false` | No | |
| 35 | + |
| 36 | +### env_vars |
| 37 | + |
| 38 | +In some integrations, Spectral requires some extra environment variables besides the default ones. |
| 39 | +Those extra variables should be added to the `env_vars` map in addition to `CHECK_POLICY` and `SPECTRAL_DSN` which are mandatory. |
| 40 | + |
| 41 | +Please refer to our docs to view the extra environment variables needed for the integration. |
| 42 | + |
| 43 | +##### SPECTRAL_DSN (mandatory) |
| 44 | + |
| 45 | +Your SpectralOps identifier, retrieved from your SpectralOps account. |
| 46 | + |
| 47 | +##### CHECK_POLICY (mandatory) |
| 48 | + |
| 49 | +`CHECK_POLICY` responsible for setting the minimum issue severity that should fail the check. |
| 50 | +The valid values for this field are: |
| 51 | + |
| 52 | +1. Fail on any issue |
| 53 | +2. Fail on warnings and above |
| 54 | +3. Fail on errors only |
| 55 | +4. Always pass |
| 56 | + |
| 57 | +### global_tags |
| 58 | + |
| 59 | +This variable holds a list of tags be applied on all newly created resources: |
| 60 | + |
| 61 | +```tcl |
| 62 | +{ |
| 63 | + BusinessUnit = "Spectral" |
| 64 | + ... |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +### tags |
| 69 | + |
| 70 | +This variable holds a collection of tags grouped by key representing its target resource: |
| 71 | + |
| 72 | +1. IAM role resource - using the `iam` key |
| 73 | +2. Lambda resource - using the `lambda` key |
| 74 | +3. ApiGateway resource - using the `api_gateway` key |
| 75 | + |
| 76 | +```tcl |
| 77 | +{ |
| 78 | + iam = { |
| 79 | + ... |
| 80 | + } |
| 81 | + lambda = { |
| 82 | + ... |
| 83 | + } |
| 84 | + api_gateway = { |
| 85 | + ... |
| 86 | + } |
| 87 | +} |
| 88 | +``` |
| 89 | + |
| 90 | +## Usage |
| 91 | + |
| 92 | +```tcl |
| 93 | +module "spectral_lambda_integration" { |
| 94 | + source = "github.com/SpectralOps/spectral-terraform-lambda-integration?ref=v1.0.0" |
| 95 | +
|
| 96 | + account_id = 111111111111 |
| 97 | + aws_region = "us-east-1" |
| 98 | + environment = "prod" |
| 99 | + integration_type = "terraform" |
| 100 | + lambda_enable_logs = true |
| 101 | + lambda_logs_retention_in_days = 30 |
| 102 | + lambda_publish = false |
| 103 | + lambda_function_timeout = 300 |
| 104 | + lambda_function_memory_size = 1024 |
| 105 | +
|
| 106 | + # Environment variables used by the integration |
| 107 | + env_vars = { |
| 108 | + # Mandatory - Your spectral DSN retreived from SpectralOps |
| 109 | + SPECTRAL_DSN = "" |
| 110 | + # Mandatory - Set which severity should fail the check |
| 111 | + CHECK_POLICY = "" |
| 112 | + # Additional env-vars should go here |
| 113 | + } |
| 114 | +
|
| 115 | + # Global tags - Tags to be applied on every newly created resource |
| 116 | + global_tags = { |
| 117 | + # Tags to apply to all newly created resources |
| 118 | + BusinessUnit = "Spectral" |
| 119 | + } |
| 120 | +
|
| 121 | + # Tags to be applied on concrete resources |
| 122 | + tags = { |
| 123 | + # Tags to apply on iam related resources |
| 124 | + iam = { |
| 125 | + Resource = "role" |
| 126 | + } |
| 127 | + # Tags to apply on lambda related resources |
| 128 | + lambda = { |
| 129 | + Resource = "lambda" |
| 130 | + } |
| 131 | + # Tags to apply on api_gateway related resources |
| 132 | + api_gateway = { |
| 133 | + Resource = "api_gateway" |
| 134 | + } |
| 135 | + } |
| 136 | +} |
| 137 | +``` |
| 138 | + |
| 139 | +## Resources |
| 140 | + |
| 141 | +| Name | Type | |
| 142 | +| ----------- | ----------- | |
| 143 | +| [aws_api_gateway_rest_api](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_rest_api) | resource | |
| 144 | +| [aws_api_gateway_method](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method) | resource | |
| 145 | +| [aws_api_gateway_method_response](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_method_response) | resource | |
| 146 | +| [aws_api_gateway_integration](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_integration) | resource | |
| 147 | +| [aws_api_gateway_deployment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_deployment) | resource | |
| 148 | +| [aws_api_gateway_stage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/api_gateway_stage) | resource | |
| 149 | +| [aws_lambda_permission](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_permission) | resource | |
| 150 | +| [aws_lambda_function](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_function) | resource | |
| 151 | +| [aws_cloudwatch_log_group](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_log_group) | resource | |
| 152 | +| [aws_iam_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | |
| 153 | +| [aws_iam_role_policy_attachment](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | |
| 154 | +| [aws_iam_policy_document](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data | |
| 155 | + |
| 156 | +## Outputs |
| 157 | + |
| 158 | +### This module has the following outputs |
| 159 | + |
| 160 | +1. `rest_api_id` - The ID of the REST API. |
| 161 | +2. `rest_api_url` - The URL for accessing the lambda through the ApiGateway. |
| 162 | +3. `rest_api_arn` - Amazon Resource Name (ARN) identifying your Rest API. |
| 163 | +4. `rest_api_execution_arn` - The execution ARN part to be used in lambda_permission's source_arn, not concatenated to other allowed API resources. |
| 164 | +5. `rest_api_lambda_execution_arn` - The execution ARN part to be used in lambda_permission's source_arn, concatenated with allowed API resources (method & path). |
| 165 | +6. `lambda_function_arn` - Amazon Resource Name (ARN) identifying your Lambda Function. |
| 166 | +7. `lambda_function_name` - The name of the lambda function. |
| 167 | +8. `lambda_iam_role_arn` - Amazon Resource Name (ARN) specifying the role. |
| 168 | +9. `lambda_iam_role_name` - Name of the role. |
0 commit comments