|
1 |
| -# terraform-aws-module-template |
| 1 | +# AWS Redshift Terraform Module |
2 | 2 |
|
3 |
| -## Overview |
| 3 | +This Terraform module creates either an Amazon Redshift cluster or Amazon Redshift Serverless resources based on configuration. |
4 | 4 |
|
5 |
| -SourceFuse AWS Reference Architecture (ARC) Terraform module for managing _________. |
| 5 | +## Features |
6 | 6 |
|
7 |
| -## Usage |
| 7 | +- Create a standard Amazon Redshift cluster with customizable configuration |
| 8 | +- Create Amazon Redshift Serverless namespace and workgroup |
| 9 | +- Toggle between standard cluster and serverless with a single boolean variable |
| 10 | +- **Automatic password generation** - If no password is provided, a secure random password is generated |
| 11 | +- **AWS Secrets Manager integration** - Option to let AWS manage passwords in Secrets Manager |
| 12 | +- Security group management for both deployment options |
| 13 | +- Subnet group creation for standard Redshift clusters |
| 14 | +- Encryption configuration |
| 15 | +- Snapshot management for standard clusters |
| 16 | +- **Standardized tagging** using the sourcefuse/arc-tags/aws module |
| 17 | + |
| 18 | +## Password Management |
| 19 | + |
| 20 | +This module provides three options for managing the master user password: |
8 | 21 |
|
9 |
| -To see a full example, check out the [main.tf](./example/main.tf) file in the example folder. |
| 22 | +1. **Random Password Generation (Recommended)**: Set `master_password = null` to automatically generate a secure random password |
| 23 | +2. **Manual Password**: Provide your own password via the `master_password` variable |
| 24 | +3. **AWS Secrets Manager**: Set `manage_user_password = true` to let AWS manage the password in Secrets Manager |
10 | 25 |
|
11 | 26 | ```hcl
|
12 |
| -module "this" { |
13 |
| - source = "git::https://github.com/sourcefuse/terraform-aws-refarch-<module_name>" |
| 27 | +# Option 1: Random password generation |
| 28 | +module "redshift" { |
| 29 | + source = "path/to/terraform-aws-arc-redshift" |
| 30 | + |
| 31 | + master_password = null # Random password will be generated |
| 32 | + # Access the generated password via: module.redshift.redshift_master_password |
14 | 33 | }
|
15 |
| -``` |
16 |
| - |
17 |
| -<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
18 |
| -## Requirements |
19 | 34 |
|
20 |
| -| Name | Version | |
21 |
| -|------|---------| |
22 |
| -| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.3, < 2.0.0 | |
23 |
| -| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.0 | |
| 35 | +# Option 2: Manual password |
| 36 | +module "redshift" { |
| 37 | + source = "path/to/terraform-aws-arc-redshift" |
| 38 | + |
| 39 | + master_password = "YourStrongPassword123!" |
| 40 | +} |
24 | 41 |
|
25 |
| -## Providers |
| 42 | +# Option 3: AWS Secrets Manager |
| 43 | +module "redshift" { |
| 44 | + source = "path/to/terraform-aws-arc-redshift" |
| 45 | + |
| 46 | + manage_user_password = true |
| 47 | +} |
| 48 | +``` |
26 | 49 |
|
27 |
| -No providers. |
| 50 | +## Usage |
28 | 51 |
|
29 |
| -## Modules |
| 52 | +### Standard Redshift Cluster |
30 | 53 |
|
31 |
| -No modules. |
| 54 | +```hcl |
| 55 | +module "redshift" { |
| 56 | + source = "path/to/terraform-aws-arc-redshift" |
| 57 | +
|
| 58 | + namespace = "arc" |
| 59 | + environment = "dev" |
| 60 | + name = "analytics" |
| 61 | +
|
| 62 | + enable_serverless = false |
| 63 | + |
| 64 | + # Cluster configuration |
| 65 | + database_name = "analytics" |
| 66 | + master_username = "admin" |
| 67 | + master_password = null # Will generate a random password |
| 68 | + # master_password = "YourStrongPassword123!" # Or provide your own |
| 69 | + node_type = "dc2.large" |
| 70 | + cluster_type = "single-node" |
| 71 | + |
| 72 | + # Network configuration |
| 73 | + vpc_id = "vpc-12345678" |
| 74 | + subnet_ids = ["subnet-12345678", "subnet-87654321"] |
| 75 | + publicly_accessible = false |
| 76 | + |
| 77 | + # Security |
| 78 | + encrypted = true |
| 79 | + |
| 80 | + # Security group rules |
| 81 | + ingress_rules = [ |
| 82 | + { |
| 83 | + from_port = 5439 |
| 84 | + to_port = 5439 |
| 85 | + protocol = "tcp" |
| 86 | + cidr_blocks = ["10.0.0.0/16"] |
| 87 | + } |
| 88 | + ] |
| 89 | + |
| 90 | + egress_rules = [ |
| 91 | + { |
| 92 | + from_port = 0 |
| 93 | + to_port = 0 |
| 94 | + protocol = "-1" |
| 95 | + cidr_blocks = ["0.0.0.0/0"] |
| 96 | + } |
| 97 | + ] |
| 98 | + |
| 99 | + tags = { |
| 100 | + Project = "Analytics" |
| 101 | + Department = "Data" |
| 102 | + } |
| 103 | +} |
| 104 | +``` |
32 | 105 |
|
33 |
| -## Resources |
| 106 | +### Redshift Serverless |
34 | 107 |
|
35 |
| -No resources. |
| 108 | +```hcl |
| 109 | +module "redshift_serverless" { |
| 110 | + source = "path/to/terraform-aws-arc-redshift" |
| 111 | +
|
| 112 | + namespace = "arc" |
| 113 | + environment = "dev" |
| 114 | + name = "analytics" |
| 115 | +
|
| 116 | + enable_serverless = true |
| 117 | + |
| 118 | + # Serverless configuration |
| 119 | + database_name = "analytics" |
| 120 | + master_username = "admin" |
| 121 | + master_password = null # Will generate a random password |
| 122 | + # master_password = "YourStrongPassword123!" # Or provide your own |
| 123 | + base_capacity = 32 |
| 124 | + max_capacity = 128 |
| 125 | + |
| 126 | + # Network configuration |
| 127 | + vpc_id = "vpc-12345678" |
| 128 | + subnet_ids = ["subnet-12345678", "subnet-87654321"] |
| 129 | + publicly_accessible = false |
| 130 | + |
| 131 | + # Security group rules |
| 132 | + ingress_rules = [ |
| 133 | + { |
| 134 | + from_port = 5439 |
| 135 | + to_port = 5439 |
| 136 | + protocol = "tcp" |
| 137 | + cidr_blocks = ["10.0.0.0/16"] |
| 138 | + } |
| 139 | + ] |
| 140 | + |
| 141 | + egress_rules = [ |
| 142 | + { |
| 143 | + from_port = 0 |
| 144 | + to_port = 0 |
| 145 | + protocol = "-1" |
| 146 | + cidr_blocks = ["0.0.0.0/0"] |
| 147 | + } |
| 148 | + ] |
| 149 | + |
| 150 | + tags = { |
| 151 | + Project = "Analytics" |
| 152 | + Department = "Data" |
| 153 | + } |
| 154 | +} |
| 155 | +``` |
36 | 156 |
|
37 | 157 | ## Inputs
|
38 | 158 |
|
39 |
| -No inputs. |
| 159 | +| Name | Description | Type | Default | Required | |
| 160 | +|------|-------------|------|---------|----------| |
| 161 | +| namespace | Namespace of the project | `string` | n/a | yes | |
| 162 | +| environment | Name of the environment | `string` | n/a | yes | |
| 163 | +| name | Name for the Redshift resources | `string` | n/a | yes | |
| 164 | +| enable_serverless | Enable Redshift Serverless. If true, creates the serverless module; if false, creates the standard cluster module | `bool` | `false` | no | |
| 165 | +| database_name | The name of the database to create | `string` | n/a | yes | |
| 166 | +| master_username | Username for the master DB user | `string` | n/a | yes | |
| 167 | +| master_password | Password for the master DB user. If null, a random password will be generated | `string` | `null` | no | |
| 168 | +| manage_user_password | Set to true to allow RDS to manage the master user password in Secrets Manager | `bool` | `null` | no | |
| 169 | +| vpc_id | ID of the VPC for Redshift | `string` | `null` | no | |
| 170 | +| subnet_ids | List of subnet IDs for the Redshift subnet group | `list(string)` | `[]` | no | |
| 171 | +| publicly_accessible | If true, the cluster can be accessed from a public network | `bool` | `false` | no | |
| 172 | +| tags | Tags to apply to resources | `map(string)` | `{}` | no | |
| 173 | + |
| 174 | +### Standard Redshift Cluster Specific Inputs |
| 175 | + |
| 176 | +| Name | Description | Type | Default | Required | |
| 177 | +|------|-------------|------|---------|----------| |
| 178 | +| cluster_identifier | The Cluster Identifier | `string` | `null` | no | |
| 179 | +| node_type | The node type to be provisioned for the cluster | `string` | `"dc2.large"` | no | |
| 180 | +| number_of_nodes | Number of nodes in the cluster | `number` | `1` | no | |
| 181 | +| cluster_type | The cluster type to use. Either 'single-node' or 'multi-node' | `string` | `"single-node"` | no | |
| 182 | +| skip_final_snapshot | Determines whether a final snapshot of the cluster is created before Redshift deletes it | `bool` | `false` | no | |
| 183 | +| encrypted | If true, the data in the cluster is encrypted at rest | `bool` | `true` | no | |
| 184 | + |
| 185 | +### Redshift Serverless Specific Inputs |
| 186 | + |
| 187 | +| Name | Description | Type | Default | Required | |
| 188 | +|------|-------------|------|---------|----------| |
| 189 | +| namespace_name | The name of the Redshift Serverless namespace | `string` | `null` | no | |
| 190 | +| workgroup_name | The name of the Redshift Serverless workgroup | `string` | `null` | no | |
| 191 | +| base_capacity | The base data warehouse capacity in Redshift Processing Units (RPUs) | `number` | `32` | no | |
| 192 | +| max_capacity | The maximum data warehouse capacity in Redshift Processing Units (RPUs) | `number` | `512` | no | |
40 | 193 |
|
41 | 194 | ## Outputs
|
42 | 195 |
|
43 |
| -No outputs. |
44 |
| -<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
45 |
| - |
46 |
| -## Versioning |
47 |
| -This project uses a `.version` file at the root of the repo which the pipeline reads from and does a git tag. |
48 |
| - |
49 |
| -When you intend to commit to `main`, you will need to increment this version. Once the project is merged, |
50 |
| -the pipeline will kick off and tag the latest git commit. |
| 196 | +### Standard Redshift Cluster Outputs |
51 | 197 |
|
52 |
| -## Development |
| 198 | +| Name | Description | |
| 199 | +|------|-------------| |
| 200 | +| redshift_cluster_endpoint | The connection endpoint for the Redshift cluster | |
| 201 | +| redshift_cluster_id | The ID of the Redshift cluster | |
| 202 | +| redshift_cluster_arn | The ARN of the Redshift cluster | |
| 203 | +| redshift_cluster_security_group_id | The ID of the security group associated with the Redshift cluster | |
53 | 204 |
|
54 |
| -### Prerequisites |
| 205 | +### Redshift Serverless Outputs |
55 | 206 |
|
56 |
| -- [terraform](https://learn.hashicorp.com/terraform/getting-started/install#installing-terraform) |
57 |
| -- [terraform-docs](https://github.com/segmentio/terraform-docs) |
58 |
| -- [pre-commit](https://pre-commit.com/#install) |
59 |
| -- [golang](https://golang.org/doc/install#install) |
60 |
| -- [golint](https://github.com/golang/lint#installation) |
| 207 | +| Name | Description | |
| 208 | +|------|-------------| |
| 209 | +| redshift_serverless_namespace_id | The ID of the Redshift Serverless namespace | |
| 210 | +| redshift_serverless_namespace_arn | The ARN of the Redshift Serverless namespace | |
| 211 | +| redshift_serverless_workgroup_id | The ID of the Redshift Serverless workgroup | |
| 212 | +| redshift_serverless_workgroup_arn | The ARN of the Redshift Serverless workgroup | |
| 213 | +| redshift_serverless_endpoint | The endpoint URL for the Redshift Serverless workgroup | |
| 214 | +| redshift_serverless_security_group_id | The ID of the security group associated with the Redshift Serverless workgroup | |
61 | 215 |
|
62 |
| -### Configurations |
| 216 | +## License |
63 | 217 |
|
64 |
| -- Configure pre-commit hooks |
65 |
| - ```sh |
66 |
| - pre-commit install |
67 |
| - ``` |
68 |
| - |
69 |
| -### Versioning |
70 |
| - |
71 |
| -while Contributing or doing git commit please specify the breaking change in your commit message whether its major,minor or patch |
72 |
| - |
73 |
| -For Example |
74 |
| - |
75 |
| -```sh |
76 |
| -git commit -m "your commit message #major" |
77 |
| -``` |
78 |
| -By specifying this , it will bump the version and if you don't specify this in your commit message then by default it will consider patch and will bump that accordingly |
79 |
| - |
80 |
| -### Tests |
81 |
| -- Tests are available in `test` directory |
82 |
| -- Configure the dependencies |
83 |
| - ```sh |
84 |
| - cd test/ |
85 |
| - go mod init github.com/sourcefuse/terraform-aws-refarch-<module_name> |
86 |
| - go get github.com/gruntwork-io/terratest/modules/terraform |
87 |
| - ``` |
88 |
| -- Now execute the test |
89 |
| - ```sh |
90 |
| - go test -timeout 30m |
91 |
| - ``` |
92 |
| - |
93 |
| -## Authors |
94 |
| - |
95 |
| -This project is authored by: |
96 |
| -- SourceFuse ARC Team |
| 218 | +This module is licensed under the MIT License. |
0 commit comments