-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
415 additions
and
30 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
67 changes: 67 additions & 0 deletions
67
examples/redshift/direct-put-to-redshift-with-secrets-manager/README.md
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,67 @@ | ||
# Kinesis Firehose: Direct Put To Redshift | ||
|
||
Configuration in this directory creates kinesis firehose stream with Direct Put as source and Redshift as destination using secrets manager. | ||
|
||
This example is ready to be tested with Demo Data in Kinesis Firehose Console. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute: | ||
|
||
```bash | ||
$ terraform init | ||
$ terraform plan | ||
$ terraform apply | ||
``` | ||
|
||
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources. | ||
|
||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.4 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.4 | | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_firehose"></a> [firehose](#module\_firehose) | ../../../ | n/a | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | | ||
| [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | | ||
| [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | | ||
| [aws_kms_key.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/kms_key) | resource | | ||
| [aws_s3_bucket.s3](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource | | ||
| [random_pet.this](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | resource | | ||
| [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | ||
| [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_name_prefix"></a> [name\_prefix](#input\_name\_prefix) | Name prefix to use in resources | `string` | `"direct-put-to-s3"` | no | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_kinesis_firehose_arn"></a> [kinesis\_firehose\_arn](#output\_kinesis\_firehose\_arn) | The ARN of the Kinesis Firehose Stream | | ||
| <a name="output_kinesis_firehose_destination_id"></a> [kinesis\_firehose\_destination\_id](#output\_kinesis\_firehose\_destination\_id) | The Destination id of the Kinesis Firehose Stream | | ||
| <a name="output_kinesis_firehose_role_arn"></a> [kinesis\_firehose\_role\_arn](#output\_kinesis\_firehose\_role\_arn) | The ARN of the IAM role created for Kinesis Firehose Stream | | ||
| <a name="output_kinesis_firehose_version_id"></a> [kinesis\_firehose\_version\_id](#output\_kinesis\_firehose\_version\_id) | The Version id of the Kinesis Firehose Stream | | ||
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> |
83 changes: 83 additions & 0 deletions
83
examples/redshift/direct-put-to-redshift-with-secrets-manager/main.tf
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,83 @@ | ||
data "aws_caller_identity" "current" {} | ||
|
||
resource "random_pet" "this" { | ||
length = 2 | ||
} | ||
|
||
resource "aws_s3_bucket" "s3" { | ||
bucket = "${var.name_prefix}-destination-bucket-${random_pet.this.id}" | ||
force_destroy = true | ||
} | ||
|
||
resource "aws_redshift_cluster" "this" { | ||
cluster_identifier = "${var.name_prefix}-redshift-cluster" | ||
database_name = "test" | ||
master_username = var.redshift_username | ||
master_password = var.redshift_password | ||
node_type = "dc2.large" | ||
cluster_type = "single-node" | ||
skip_final_snapshot = true | ||
# provisioner "local-exec" { | ||
# command = "psql \"postgresql://${self.master_username}:${self.master_password}@${self.endpoint}/${self.database_name}\" -f ./redshift_table.sql" | ||
# } | ||
} | ||
|
||
resource "aws_kms_key" "this" { | ||
description = "${var.name_prefix}-kms-key" | ||
deletion_window_in_days = 7 | ||
} | ||
|
||
module "firehose" { | ||
source = "../../../" | ||
name = "${var.name_prefix}-delivery-stream" | ||
destination = "redshift" | ||
s3_bucket_arn = aws_s3_bucket.s3.arn | ||
buffering_interval = 60 | ||
redshift_cluster_identifier = aws_redshift_cluster.this.cluster_identifier | ||
redshift_cluster_endpoint = aws_redshift_cluster.this.endpoint | ||
redshift_database_name = aws_redshift_cluster.this.database_name | ||
enable_secrets_manager = true | ||
secret_arn = module.secrets_manager.secret_arn | ||
secret_kms_key_arn = module.secrets_manager.secret_arn | ||
redshift_table_name = "firehose_test_table" | ||
redshift_copy_options = "json 'auto ignorecase'" | ||
enable_s3_backup = true | ||
s3_backup_prefix = "backup/" | ||
s3_backup_bucket_arn = aws_s3_bucket.s3.arn | ||
s3_backup_buffering_interval = 100 | ||
s3_backup_buffering_size = 100 | ||
s3_backup_compression = "GZIP" | ||
s3_backup_enable_encryption = true | ||
s3_backup_kms_key_arn = aws_kms_key.this.arn | ||
} | ||
|
||
|
||
module "secrets_manager" { | ||
source = "terraform-aws-modules/secrets-manager/aws" | ||
version = "1.1.2" | ||
kms_key_id = aws_kms_key.this.id | ||
|
||
# Secret | ||
name_prefix = "${var.name_prefix}-redshift-secret" | ||
description = "Example Secrets Manager secret" | ||
recovery_window_in_days = 0 | ||
# Policy | ||
create_policy = true | ||
block_public_policy = true | ||
policy_statements = { | ||
read = { | ||
sid = "AllowAccountRead" | ||
principals = [{ | ||
type = "AWS" | ||
identifiers = ["arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"] | ||
}] | ||
actions = ["secretsmanager:GetSecretValue"] | ||
resources = ["*"] | ||
} | ||
} | ||
|
||
secret_string = jsonencode({ | ||
username = var.redshift_username, | ||
password = var.redshift_password | ||
}) | ||
} |
19 changes: 19 additions & 0 deletions
19
examples/redshift/direct-put-to-redshift-with-secrets-manager/outputs.tf
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,19 @@ | ||
output "kinesis_firehose_arn" { | ||
description = "The ARN of the Kinesis Firehose Stream" | ||
value = module.firehose.kinesis_firehose_arn | ||
} | ||
|
||
output "kinesis_firehose_destination_id" { | ||
description = "The Destination id of the Kinesis Firehose Stream" | ||
value = module.firehose.kinesis_firehose_destination_id | ||
} | ||
|
||
output "kinesis_firehose_version_id" { | ||
description = "The Version id of the Kinesis Firehose Stream" | ||
value = module.firehose.kinesis_firehose_version_id | ||
} | ||
|
||
output "kinesis_firehose_role_arn" { | ||
description = "The ARN of the IAM role created for Kinesis Firehose Stream" | ||
value = module.firehose.kinesis_firehose_role_arn | ||
} |
7 changes: 7 additions & 0 deletions
7
examples/redshift/direct-put-to-redshift-with-secrets-manager/redshift_table.sql
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,7 @@ | ||
Create table firehose_test_table | ||
( | ||
ticker_symbol varchar(4), | ||
sector varchar(16), | ||
change float, | ||
price float | ||
); |
17 changes: 17 additions & 0 deletions
17
examples/redshift/direct-put-to-redshift-with-secrets-manager/variables.tf
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,17 @@ | ||
variable "name_prefix" { | ||
description = "Name prefix to use in resources" | ||
type = string | ||
default = "direct-put-to-redshift" | ||
} | ||
|
||
variable "redshift_username" { | ||
description = "The username that the firehose delivery stream will assume. It is strongly recommended that the username and password provided is used exclusively for Amazon Kinesis Firehose purposes, and that the permissions for the account are restricted for Amazon Redshift INSERT permissions" | ||
type = string | ||
sensitive = true | ||
} | ||
|
||
variable "redshift_password" { | ||
description = "The password for the redshift username above" | ||
type = string | ||
sensitive = true | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/redshift/direct-put-to-redshift-with-secrets-manager/versions.tf
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,14 @@ | ||
terraform { | ||
required_version = ">= 0.13.1" | ||
|
||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.0" | ||
} | ||
random = { | ||
source = "hashicorp/random" | ||
version = ">= 2.0" | ||
} | ||
} | ||
} |
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
Oops, something went wrong.