From 946a7a2e6555af61cff018405798adbf9a8ba158 Mon Sep 17 00:00:00 2001 From: Andriy Knysh Date: Fri, 5 Jul 2019 11:34:14 -0400 Subject: [PATCH] Convert to TF 0.12. Add tests. Add Codefresh test pipeline (#53) * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline * Convert to TF 0.12. Add tests. Add Codefresh test pipeline --- .travis.yml | 16 -- README.md | 89 ++++---- README.yaml | 22 +- codefresh/test.yml | 74 +++++++ docs/terraform.md | 71 +++--- examples/basic/main.tf | 2 +- examples/basic/outputs.tf | 16 +- examples/complete/fixtures.us-west-1.tfvars | 29 +++ examples/complete/main.tf | 92 ++++++++ examples/complete/outputs.tf | 61 +++++ examples/complete/variables.tf | 73 ++++++ examples/enhanced_monitoring/main.tf | 10 +- examples/enhanced_monitoring/outputs.tf | 16 +- examples/serverless_mysql/main.tf | 4 +- examples/serverless_mysql/outputs.tf | 16 +- examples/with_cluster_parameters/main.tf | 39 ++-- examples/with_cluster_parameters/outputs.tf | 16 +- main.tf | 234 +++++++++++--------- outputs.tf | 35 +-- test/.gitignore | 1 + test/Makefile | 43 ++++ test/Makefile.alpine | 5 + test/src/.gitignore | 2 + test/src/Gopkg.lock | 92 ++++++++ test/src/Gopkg.toml | 7 + test/src/Makefile | 50 +++++ test/src/examples_complete_test.go | 52 +++++ variables.tf | 147 +++++++----- versions.tf | 8 + 29 files changed, 981 insertions(+), 341 deletions(-) delete mode 100644 .travis.yml create mode 100644 codefresh/test.yml create mode 100644 examples/complete/fixtures.us-west-1.tfvars create mode 100644 examples/complete/main.tf create mode 100644 examples/complete/outputs.tf create mode 100644 examples/complete/variables.tf create mode 100644 test/.gitignore create mode 100644 test/Makefile create mode 100644 test/Makefile.alpine create mode 100644 test/src/.gitignore create mode 100644 test/src/Gopkg.lock create mode 100644 test/src/Gopkg.toml create mode 100644 test/src/Makefile create mode 100644 test/src/examples_complete_test.go create mode 100644 versions.tf diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 241026ee..00000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -addons: - apt: - packages: - - git - - make - - curl - -install: - - make init - -script: - - make terraform/install - - make terraform/get-plugins - - make terraform/get-modules - - make terraform/lint - - make terraform/validate diff --git a/README.md b/README.md index 79b363f9..832ac94b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Cloud Posse][logo]](https://cpco.io/homepage) -# terraform-aws-rds-cluster [![Build Status](https://travis-ci.org/cloudposse/terraform-aws-rds-cluster.svg?branch=master)](https://travis-ci.org/cloudposse/terraform-aws-rds-cluster) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-rds-cluster.svg)](https://github.com/cloudposse/terraform-aws-rds-cluster/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) +# terraform-aws-rds-cluster [![Codefresh Build Status](https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-rds-cluster?type=cf-1)](https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1eb949a7e22e49dc7ea7c9) [![Latest Release](https://img.shields.io/github/release/cloudposse/terraform-aws-rds-cluster.svg)](https://github.com/cloudposse/terraform-aws-rds-cluster/releases/latest) [![Slack Community](https://slack.cloudposse.com/badge.svg)](https://slack.cloudposse.com) Terraform module to provision an [`RDS Aurora`](https://aws.amazon.com/rds/aurora) cluster for MySQL or Postgres. @@ -102,7 +102,7 @@ module "rds_cluster_aurora_mysql_serverless" { max_capacity = 256 min_capacity = 2 seconds_until_auto_pause = 300 - }, + } ] } ``` @@ -150,11 +150,11 @@ module "rds_cluster_aurora_mysql" { }, { name = "collation_connection" - value = "uft8_bin" + value = "utf8_bin" }, { name = "collation_server" - value = "uft8_bin" + value = "utf8_bin" }, { name = "lower_case_table_names" @@ -165,7 +165,7 @@ module "rds_cluster_aurora_mysql" { name = "skip-character-set-client-handshake" value = "1" apply_method = "pending-reboot" - }, + } ] } ``` @@ -176,12 +176,12 @@ module "rds_cluster_aurora_mysql" { # create IAM role for monitoring resource "aws_iam_role" "enhanced_monitoring" { name = "rds-cluster-example-1" - assume_role_policy = "${data.aws_iam_policy_document.enhanced_monitoring.json}" + assume_role_policy = data.aws_iam_policy_document.enhanced_monitoring.json } # Attach Amazon's managed policy for RDS enhanced monitoring resource "aws_iam_role_policy_attachment" "enhanced_monitoring" { - role = "${aws_iam_role.enhanced_monitoring.name}" + role = aws_iam_role.enhanced_monitoring.name policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole" } @@ -220,10 +220,10 @@ module "rds_cluster_aurora_postgres" { zone_id = "Zxxxxxxxx" # enable monitoring every 30 seconds - rds_monitoring_interval = "30" + rds_monitoring_interval = 30 # reference iam role created above - rds_monitoring_role_arn = "${aws_iam_role.enhanced_monitoring.arn}" + rds_monitoring_role_arn = aws_iam_role.enhanced_monitoring.arn } ``` @@ -248,55 +248,55 @@ Available targets: |------|-------------|:----:|:-----:|:-----:| | admin_password | (Required unless a snapshot_identifier is provided) Password for the master DB user | string | `` | no | | admin_user | (Required unless a snapshot_identifier is provided) Username for the master DB user | string | `admin` | no | -| allowed_cidr_blocks | List of CIDR blocks allowed to access | list | `` | no | -| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no | -| attributes | Additional attributes (e.g. `1`) | list | `` | no | -| autoscaling_enabled | Whether to enable cluster autoscaling | string | `false` | no | -| autoscaling_max_capacity | Maximum number of instances to be maintained by the autoscaler | string | `5` | no | -| autoscaling_min_capacity | Minimum number of instances to be maintained by the autoscaler | string | `1` | no | +| allowed_cidr_blocks | List of CIDR blocks allowed to access the cluster | list(string) | `` | no | +| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | bool | `true` | no | +| attributes | Additional attributes (e.g. `1`) | list(string) | `` | no | +| autoscaling_enabled | Whether to enable cluster autoscaling | bool | `false` | no | +| autoscaling_max_capacity | Maximum number of instances to be maintained by the autoscaler | number | `5` | no | +| autoscaling_min_capacity | Minimum number of instances to be maintained by the autoscaler | number | `1` | no | | autoscaling_policy_type | Autoscaling policy type. `TargetTrackingScaling` and `StepScaling` are supported | string | `TargetTrackingScaling` | no | -| autoscaling_scale_in_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling down activity can start. Default is 300s | string | `300` | no | -| autoscaling_scale_out_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling up activity can start. Default is 300s | string | `300` | no | +| autoscaling_scale_in_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling down activity can start. Default is 300s | number | `300` | no | +| autoscaling_scale_out_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling up activity can start. Default is 300s | number | `300` | no | | autoscaling_target_metrics | The metrics type to use. If this value isn't provided the default is CPU utilization | string | `RDSReaderAverageCPUUtilization` | no | -| autoscaling_target_value | The target value to scale with respect to target metrics | string | `75` | no | +| autoscaling_target_value | The target value to scale with respect to target metrics | number | `75` | no | | backup_window | Daily time range during which the backups happen | string | `07:00-09:00` | no | | cluster_dns_name | Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name` | string | `` | no | | cluster_family | The family of the DB cluster parameter group | string | `aurora5.6` | no | -| cluster_parameters | List of DB parameters to apply | list | `` | no | -| cluster_size | Number of DB instances to create in the cluster | string | `2` | no | +| cluster_parameters | List of DB cluster parameters to apply | object | `` | no | +| cluster_size | Number of DB instances to create in the cluster | number | `2` | no | | db_name | Database name | string | - | yes | -| db_port | Database port | string | `3306` | no | -| deletion_protection | If the DB instance should have deletion protection enabled. | string | `false` | no | +| db_port | Database port | number | `3306` | no | +| deletion_protection | If the DB instance should have deletion protection enabled | bool | `false` | no | | delimiter | Delimiter to be used between `name`, `namespace`, `stage` and `attributes` | string | `-` | no | -| enabled | Set to false to prevent the module from creating any resources | string | `true` | no | -| enabled_cloudwatch_logs_exports | List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery. | list | `` | no | +| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| enabled_cloudwatch_logs_exports | List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery | list(string) | `` | no | | engine | The name of the database engine to be used for this DB cluster. Valid values: `aurora`, `aurora-mysql`, `aurora-postgresql` | string | `aurora` | no | | engine_mode | The database engine mode. Valid values: `parallelquery`, `provisioned`, `serverless` | string | `provisioned` | no | | engine_version | The version number of the database engine to use | string | `` | no | -| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled. | string | `false` | no | +| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no | | instance_availability_zone | Optional parameter to place cluster instances in a specific availability zone. If left empty, will place randomly | string | `` | no | -| instance_parameters | List of DB instance parameters to apply | list | `` | no | +| instance_parameters | List of DB instance parameters to apply | object | `` | no | | instance_type | Instance type to use | string | `db.t2.small` | no | -| kms_key_arn | The ARN for the KMS encryption key. When specifying kms_key_arn, storage_encrypted needs to be set to true. | string | `` | no | +| kms_key_arn | The ARN for the KMS encryption key. When specifying `kms_key_arn`, `storage_encrypted` needs to be set to `true` | string | `` | no | | maintenance_window | Weekly time range during which system maintenance can occur, in UTC | string | `wed:03:00-wed:04:00` | no | | name | Name of the application | string | - | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes | -| performance_insights_enabled | Whether to enable Performance Insights | string | `false` | no | +| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | +| performance_insights_enabled | Whether to enable Performance Insights | bool | `false` | no | | performance_insights_kms_key_id | The ARN for the KMS key to encrypt Performance Insights data. When specifying `performance_insights_kms_key_id`, `performance_insights_enabled` needs to be set to true | string | `` | no | -| publicly_accessible | Set to true if you want your cluster to be publicly accessible (such as via QuickSight) | string | `false` | no | -| rds_monitoring_interval | Interval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60) | string | `0` | no | +| publicly_accessible | Set to true if you want your cluster to be publicly accessible (such as via QuickSight) | bool | `false` | no | +| rds_monitoring_interval | Interval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60) | number | `0` | no | | rds_monitoring_role_arn | The ARN for the IAM role that can send monitoring metrics to CloudWatch Logs | string | `` | no | | reader_dns_name | Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name` | string | `` | no | | replication_source_identifier | ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica | string | `` | no | -| retention_period | Number of days to retain backups for | string | `5` | no | -| scaling_configuration | List of nested attributes with scaling properties. Only valid when engine_mode is set to `serverless` | list | `` | no | -| security_groups | List of security groups to be allowed to connect to the DB instance | list | `` | no | -| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | string | `true` | no | +| retention_period | Number of days to retain backups for | number | `5` | no | +| scaling_configuration | List of nested attributes with scaling properties. Only valid when `engine_mode` is set to `serverless` | object | `` | no | +| security_groups | List of security groups to be allowed to connect to the DB instance | list(string) | `` | no | +| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | bool | `true` | no | | snapshot_identifier | Specifies whether or not to create this cluster from a snapshot | string | `` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | -| storage_encrypted | Specifies whether the DB cluster is encrypted. The default is `false` for `provisioned` `engine_mode` and `true` for `serverless` `engine_mode` | string | `false` | no | -| subnets | List of VPC subnet IDs | list | - | yes | -| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no | +| storage_encrypted | Specifies whether the DB cluster is encrypted. The default is `false` for `provisioned` `engine_mode` and `true` for `serverless` `engine_mode` | bool | `false` | no | +| subnets | List of VPC subnet IDs | list(string) | - | yes | +| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `` | no | | vpc_id | VPC ID to create the cluster in (e.g. `vpc-a22222ee`) | string | - | yes | | zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas | string | `` | no | @@ -305,15 +305,16 @@ Available targets: | Name | Description | |------|-------------| | arn | Amazon Resource Name (ARN) of cluster | -| cluster_name | Cluster Identifier | -| cluster_resource_id | The region-unique, immutable identifie of the cluster. | -| dbi_resource_ids | List of the region-unique, immutable identifiers for the DB instances in the cluster. | +| cluster_identifier | Cluster Identifier | +| cluster_resource_id | The region-unique, immutable identifie of the cluster | +| cluster_security_groups | Default RDS cluster security groups | +| database_name | Database name | +| dbi_resource_ids | List of the region-unique, immutable identifiers for the DB instances in the cluster | | endpoint | The DNS address of the RDS instance | | master_host | DB Master hostname | -| name | Database name | +| master_username | Username for the master DB user | | reader_endpoint | A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas | | replicas_host | Replicas hostname | -| user | Username for the master DB user | diff --git a/README.yaml b/README.yaml index 18fa6c2c..c0d46794 100644 --- a/README.yaml +++ b/README.yaml @@ -34,9 +34,9 @@ github_repo: cloudposse/terraform-aws-rds-cluster # Badges to display badges: - - name: "Build Status" - image: "https://travis-ci.org/cloudposse/terraform-aws-rds-cluster.svg?branch=master" - url: "https://travis-ci.org/cloudposse/terraform-aws-rds-cluster" + - name: "Codefresh Build Status" + image: "https://g.codefresh.io/api/badges/pipeline/cloudposse/terraform-modules%2Fterraform-aws-rds-cluster?type=cf-1" + url: "https://g.codefresh.io/public/accounts/cloudposse/pipelines/5d1eb949a7e22e49dc7ea7c9" - name: "Latest Release" image: "https://img.shields.io/github/release/cloudposse/terraform-aws-rds-cluster.svg" url: "https://github.com/cloudposse/terraform-aws-rds-cluster/releases/latest" @@ -113,7 +113,7 @@ usage: |- max_capacity = 256 min_capacity = 2 seconds_until_auto_pause = 300 - }, + } ] } ``` @@ -161,11 +161,11 @@ usage: |- }, { name = "collation_connection" - value = "uft8_bin" + value = "utf8_bin" }, { name = "collation_server" - value = "uft8_bin" + value = "utf8_bin" }, { name = "lower_case_table_names" @@ -176,7 +176,7 @@ usage: |- name = "skip-character-set-client-handshake" value = "1" apply_method = "pending-reboot" - }, + } ] } ``` @@ -187,12 +187,12 @@ usage: |- # create IAM role for monitoring resource "aws_iam_role" "enhanced_monitoring" { name = "rds-cluster-example-1" - assume_role_policy = "${data.aws_iam_policy_document.enhanced_monitoring.json}" + assume_role_policy = data.aws_iam_policy_document.enhanced_monitoring.json } # Attach Amazon's managed policy for RDS enhanced monitoring resource "aws_iam_role_policy_attachment" "enhanced_monitoring" { - role = "${aws_iam_role.enhanced_monitoring.name}" + role = aws_iam_role.enhanced_monitoring.name policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole" } @@ -231,10 +231,10 @@ usage: |- zone_id = "Zxxxxxxxx" # enable monitoring every 30 seconds - rds_monitoring_interval = "30" + rds_monitoring_interval = 30 # reference iam role created above - rds_monitoring_role_arn = "${aws_iam_role.enhanced_monitoring.arn}" + rds_monitoring_role_arn = aws_iam_role.enhanced_monitoring.arn } ``` diff --git a/codefresh/test.yml b/codefresh/test.yml new file mode 100644 index 00000000..ddd07f97 --- /dev/null +++ b/codefresh/test.yml @@ -0,0 +1,74 @@ +version: '1.0' + +stages: + - Prepare + - Test + +steps: + wait: + title: Wait + stage: Prepare + image: codefresh/cli:latest + commands: + - codefresh get builds --pipeline=${{CF_REPO_NAME}} --status running --limit 1000 -o json | jq --arg id ${{CF_BUILD_ID}} -ser 'flatten|.[-1].id==$id' + retry: + maxAttempts: 10 + delay: 20 + exponentialFactor: 1.1 + + main_clone: + title: "Clone repository" + type: git-clone + stage: Prepare + description: "Initialize" + repo: ${{CF_REPO_OWNER}}/${{CF_REPO_NAME}} + git: CF-default + revision: ${{CF_REVISION}} + + clean_init: + title: Prepare build-harness and test-harness + image: ${{TEST_IMAGE}} + stage: Prepare + commands: + - cf_export PATH="/usr/local/terraform/0.12/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" + - make init + - git -C build-harness checkout master + - make -C test/ clean init TEST_HARNESS_BRANCH=master + - make -C test/src clean init + - find . -type d -name '.terraform' | xargs rm -rf + - find . -type f -name 'terraform.tfstate*' -exec rm -f {} \; + + test: + type: "parallel" + title: "Run tests" + description: "Run all tests in parallel" + stage: Test + steps: + test_readme_lint: + title: "Test README.md updated" + stage: "Test" + image: ${{TEST_IMAGE}} + description: Test "readme/lint" + commands: + - make readme/lint + + test_module: + title: Test module with bats + image: ${{TEST_IMAGE}} + stage: Test + commands: + - make -C test/ module + + test_examples_complete: + title: Test "examples/complete" with bats + image: ${{TEST_IMAGE}} + stage: Test + commands: + - make -C test/ examples/complete + + test_examples_complete_terratest: + title: Test "examples/complete" with terratest + image: ${{TEST_IMAGE}} + stage: Test + commands: + - make -C test/src diff --git a/docs/terraform.md b/docs/terraform.md index e4f37bdf..d3be81c5 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -4,55 +4,55 @@ |------|-------------|:----:|:-----:|:-----:| | admin_password | (Required unless a snapshot_identifier is provided) Password for the master DB user | string | `` | no | | admin_user | (Required unless a snapshot_identifier is provided) Username for the master DB user | string | `admin` | no | -| allowed_cidr_blocks | List of CIDR blocks allowed to access | list | `` | no | -| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | string | `true` | no | -| attributes | Additional attributes (e.g. `1`) | list | `` | no | -| autoscaling_enabled | Whether to enable cluster autoscaling | string | `false` | no | -| autoscaling_max_capacity | Maximum number of instances to be maintained by the autoscaler | string | `5` | no | -| autoscaling_min_capacity | Minimum number of instances to be maintained by the autoscaler | string | `1` | no | +| allowed_cidr_blocks | List of CIDR blocks allowed to access the cluster | list(string) | `` | no | +| apply_immediately | Specifies whether any cluster modifications are applied immediately, or during the next maintenance window | bool | `true` | no | +| attributes | Additional attributes (e.g. `1`) | list(string) | `` | no | +| autoscaling_enabled | Whether to enable cluster autoscaling | bool | `false` | no | +| autoscaling_max_capacity | Maximum number of instances to be maintained by the autoscaler | number | `5` | no | +| autoscaling_min_capacity | Minimum number of instances to be maintained by the autoscaler | number | `1` | no | | autoscaling_policy_type | Autoscaling policy type. `TargetTrackingScaling` and `StepScaling` are supported | string | `TargetTrackingScaling` | no | -| autoscaling_scale_in_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling down activity can start. Default is 300s | string | `300` | no | -| autoscaling_scale_out_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling up activity can start. Default is 300s | string | `300` | no | +| autoscaling_scale_in_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling down activity can start. Default is 300s | number | `300` | no | +| autoscaling_scale_out_cooldown | The amount of time, in seconds, after a scaling activity completes and before the next scaling up activity can start. Default is 300s | number | `300` | no | | autoscaling_target_metrics | The metrics type to use. If this value isn't provided the default is CPU utilization | string | `RDSReaderAverageCPUUtilization` | no | -| autoscaling_target_value | The target value to scale with respect to target metrics | string | `75` | no | +| autoscaling_target_value | The target value to scale with respect to target metrics | number | `75` | no | | backup_window | Daily time range during which the backups happen | string | `07:00-09:00` | no | | cluster_dns_name | Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name` | string | `` | no | | cluster_family | The family of the DB cluster parameter group | string | `aurora5.6` | no | -| cluster_parameters | List of DB parameters to apply | list | `` | no | -| cluster_size | Number of DB instances to create in the cluster | string | `2` | no | +| cluster_parameters | List of DB cluster parameters to apply | object | `` | no | +| cluster_size | Number of DB instances to create in the cluster | number | `2` | no | | db_name | Database name | string | - | yes | -| db_port | Database port | string | `3306` | no | -| deletion_protection | If the DB instance should have deletion protection enabled. | string | `false` | no | +| db_port | Database port | number | `3306` | no | +| deletion_protection | If the DB instance should have deletion protection enabled | bool | `false` | no | | delimiter | Delimiter to be used between `name`, `namespace`, `stage` and `attributes` | string | `-` | no | -| enabled | Set to false to prevent the module from creating any resources | string | `true` | no | -| enabled_cloudwatch_logs_exports | List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery. | list | `` | no | +| enabled | Set to false to prevent the module from creating any resources | bool | `true` | no | +| enabled_cloudwatch_logs_exports | List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery | list(string) | `` | no | | engine | The name of the database engine to be used for this DB cluster. Valid values: `aurora`, `aurora-mysql`, `aurora-postgresql` | string | `aurora` | no | | engine_mode | The database engine mode. Valid values: `parallelquery`, `provisioned`, `serverless` | string | `provisioned` | no | | engine_version | The version number of the database engine to use | string | `` | no | -| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled. | string | `false` | no | +| iam_database_authentication_enabled | Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool | `false` | no | | instance_availability_zone | Optional parameter to place cluster instances in a specific availability zone. If left empty, will place randomly | string | `` | no | -| instance_parameters | List of DB instance parameters to apply | list | `` | no | +| instance_parameters | List of DB instance parameters to apply | object | `` | no | | instance_type | Instance type to use | string | `db.t2.small` | no | -| kms_key_arn | The ARN for the KMS encryption key. When specifying kms_key_arn, storage_encrypted needs to be set to true. | string | `` | no | +| kms_key_arn | The ARN for the KMS encryption key. When specifying `kms_key_arn`, `storage_encrypted` needs to be set to `true` | string | `` | no | | maintenance_window | Weekly time range during which system maintenance can occur, in UTC | string | `wed:03:00-wed:04:00` | no | | name | Name of the application | string | - | yes | -| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes | -| performance_insights_enabled | Whether to enable Performance Insights | string | `false` | no | +| namespace | Namespace (e.g. `eg` or `cp`) | string | `` | no | +| performance_insights_enabled | Whether to enable Performance Insights | bool | `false` | no | | performance_insights_kms_key_id | The ARN for the KMS key to encrypt Performance Insights data. When specifying `performance_insights_kms_key_id`, `performance_insights_enabled` needs to be set to true | string | `` | no | -| publicly_accessible | Set to true if you want your cluster to be publicly accessible (such as via QuickSight) | string | `false` | no | -| rds_monitoring_interval | Interval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60) | string | `0` | no | +| publicly_accessible | Set to true if you want your cluster to be publicly accessible (such as via QuickSight) | bool | `false` | no | +| rds_monitoring_interval | Interval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60) | number | `0` | no | | rds_monitoring_role_arn | The ARN for the IAM role that can send monitoring metrics to CloudWatch Logs | string | `` | no | | reader_dns_name | Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name` | string | `` | no | | replication_source_identifier | ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica | string | `` | no | -| retention_period | Number of days to retain backups for | string | `5` | no | -| scaling_configuration | List of nested attributes with scaling properties. Only valid when engine_mode is set to `serverless` | list | `` | no | -| security_groups | List of security groups to be allowed to connect to the DB instance | list | `` | no | -| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | string | `true` | no | +| retention_period | Number of days to retain backups for | number | `5` | no | +| scaling_configuration | List of nested attributes with scaling properties. Only valid when `engine_mode` is set to `serverless` | object | `` | no | +| security_groups | List of security groups to be allowed to connect to the DB instance | list(string) | `` | no | +| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB cluster is deleted | bool | `true` | no | | snapshot_identifier | Specifies whether or not to create this cluster from a snapshot | string | `` | no | -| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | - | yes | -| storage_encrypted | Specifies whether the DB cluster is encrypted. The default is `false` for `provisioned` `engine_mode` and `true` for `serverless` `engine_mode` | string | `false` | no | -| subnets | List of VPC subnet IDs | list | - | yes | -| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map | `` | no | +| stage | Stage (e.g. `prod`, `dev`, `staging`) | string | `` | no | +| storage_encrypted | Specifies whether the DB cluster is encrypted. The default is `false` for `provisioned` `engine_mode` and `true` for `serverless` `engine_mode` | bool | `false` | no | +| subnets | List of VPC subnet IDs | list(string) | - | yes | +| tags | Additional tags (e.g. map(`BusinessUnit`,`XYZ`) | map(string) | `` | no | | vpc_id | VPC ID to create the cluster in (e.g. `vpc-a22222ee`) | string | - | yes | | zone_id | Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas | string | `` | no | @@ -61,13 +61,14 @@ | Name | Description | |------|-------------| | arn | Amazon Resource Name (ARN) of cluster | -| cluster_name | Cluster Identifier | -| cluster_resource_id | The region-unique, immutable identifie of the cluster. | -| dbi_resource_ids | List of the region-unique, immutable identifiers for the DB instances in the cluster. | +| cluster_identifier | Cluster Identifier | +| cluster_resource_id | The region-unique, immutable identifie of the cluster | +| cluster_security_groups | Default RDS cluster security groups | +| database_name | Database name | +| dbi_resource_ids | List of the region-unique, immutable identifiers for the DB instances in the cluster | | endpoint | The DNS address of the RDS instance | | master_host | DB Master hostname | -| name | Database name | +| master_username | Username for the master DB user | | reader_endpoint | A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas | | replicas_host | Replicas hostname | -| user | Username for the master DB user | diff --git a/examples/basic/main.tf b/examples/basic/main.tf index 6ac4f006..960f752f 100644 --- a/examples/basic/main.tf +++ b/examples/basic/main.tf @@ -1,7 +1,7 @@ # https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBClusterParameterGroup.html provider "aws" { - region = "us-west-2" + region = "us-west-1" # Make it faster by skipping some checks skip_get_ec2_platforms = true diff --git a/examples/basic/outputs.tf b/examples/basic/outputs.tf index 24770820..4a33afc3 100644 --- a/examples/basic/outputs.tf +++ b/examples/basic/outputs.tf @@ -1,39 +1,39 @@ output "name" { - value = "${module.rds_cluster_aurora_postgres.name}" + value = module.rds_cluster_aurora_postgres.database_name description = "Database name" } output "user" { - value = "${module.rds_cluster_aurora_postgres.user}" + value = module.rds_cluster_aurora_postgres.user description = "Username for the master DB user" } output "cluster_name" { - value = "${module.rds_cluster_aurora_postgres.cluster_name}" + value = module.rds_cluster_aurora_postgres.cluster_name description = "Cluster Identifier" } output "arn" { - value = "${module.rds_cluster_aurora_postgres.arn}" + value = module.rds_cluster_aurora_postgres.arn description = "Amazon Resource Name (ARN) of cluster" } output "endpoint" { - value = "${module.rds_cluster_aurora_postgres.endpoint}" + value = module.rds_cluster_aurora_postgres.endpoint description = "The DNS address of the RDS instance" } output "reader_endpoint" { - value = "${module.rds_cluster_aurora_postgres.reader_endpoint}" + value = module.rds_cluster_aurora_postgres.reader_endpoint description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" } output "master_host" { - value = "${module.rds_cluster_aurora_postgres.master_host}" + value = module.rds_cluster_aurora_postgres.master_host description = "DB Master hostname" } output "replicas_host" { - value = "${module.rds_cluster_aurora_postgres.replicas_host}" + value = module.rds_cluster_aurora_postgres.replicas_host description = "Replicas hostname" } diff --git a/examples/complete/fixtures.us-west-1.tfvars b/examples/complete/fixtures.us-west-1.tfvars new file mode 100644 index 00000000..641eb0f2 --- /dev/null +++ b/examples/complete/fixtures.us-west-1.tfvars @@ -0,0 +1,29 @@ +region = "us-west-1" + +availability_zones = ["us-west-1b", "us-west-1c"] + +namespace = "eg" + +stage = "test" + +name = "rds-cluster" + +instance_type = "db.t2.small" + +cluster_family = "aurora5.6" + +cluster_size = 1 + +deletion_protection = false + +autoscaling_enabled = false + +engine = "aurora" + +engine_mode = "provisioned" + +db_name = "test_db" + +admin_user = "admin" + +admin_password = "admin_password" diff --git a/examples/complete/main.tf b/examples/complete/main.tf new file mode 100644 index 00000000..92939d17 --- /dev/null +++ b/examples/complete/main.tf @@ -0,0 +1,92 @@ +provider "aws" { + region = var.region +} + +module "vpc" { + source = "git::https://github.com/cloudposse/terraform-aws-vpc.git?ref=tags/0.7.0" + namespace = var.namespace + stage = var.stage + name = var.name + cidr_block = "172.16.0.0/16" +} + +module "subnets" { + source = "git::https://github.com/cloudposse/terraform-aws-dynamic-subnets.git?ref=tags/0.16.0" + availability_zones = var.availability_zones + namespace = var.namespace + stage = var.stage + name = var.name + vpc_id = module.vpc.vpc_id + igw_id = module.vpc.igw_id + cidr_block = module.vpc.vpc_cidr_block + nat_gateway_enabled = false + nat_instance_enabled = false +} + +module "rds_cluster" { + source = "../../" + namespace = var.namespace + stage = var.stage + name = var.name + engine = var.engine + engine_mode = var.engine_mode + cluster_family = var.cluster_family + cluster_size = var.cluster_size + admin_user = var.admin_user + admin_password = var.admin_password + db_name = var.db_name + instance_type = var.instance_type + vpc_id = module.vpc.vpc_id + subnets = module.subnets.private_subnet_ids + security_groups = [module.vpc.vpc_default_security_group_id] + deletion_protection = var.deletion_protection + autoscaling_enabled = var.autoscaling_enabled + + cluster_parameters = [ + { + name = "character_set_client" + value = "utf8" + apply_method = "pending-reboot" + }, + { + name = "character_set_connection" + value = "utf8" + apply_method = "pending-reboot" + }, + { + name = "character_set_database" + value = "utf8" + apply_method = "pending-reboot" + }, + { + name = "character_set_results" + value = "utf8" + apply_method = "pending-reboot" + }, + { + name = "character_set_server" + value = "utf8" + apply_method = "pending-reboot" + }, + { + name = "collation_connection" + value = "utf8_bin" + apply_method = "pending-reboot" + }, + { + name = "collation_server" + value = "utf8_bin" + apply_method = "pending-reboot" + }, + { + name = "lower_case_table_names" + value = "1" + apply_method = "pending-reboot" + }, + { + name = "skip-character-set-client-handshake" + value = "1" + apply_method = "pending-reboot" + } + ] +} diff --git a/examples/complete/outputs.tf b/examples/complete/outputs.tf new file mode 100644 index 00000000..7b25ca91 --- /dev/null +++ b/examples/complete/outputs.tf @@ -0,0 +1,61 @@ +output "database_name" { + value = module.rds_cluster.database_name + description = "Database name" +} + +output "master_username" { + value = module.rds_cluster.master_username + description = "Username for the master DB user" +} + +output "cluster_identifier" { + value = module.rds_cluster.cluster_identifier + description = "Cluster Identifier" +} + +output "arn" { + value = module.rds_cluster.arn + description = "Amazon Resource Name (ARN) of cluster" +} + +output "endpoint" { + value = module.rds_cluster.endpoint + description = "The DNS address of the RDS instance" +} + +output "reader_endpoint" { + value = module.rds_cluster.reader_endpoint + description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" +} + +output "master_host" { + value = module.rds_cluster.master_host + description = "DB Master hostname" +} + +output "replicas_host" { + value = module.rds_cluster.replicas_host + description = "Replicas hostname" +} + +output "dbi_resource_ids" { + value = module.rds_cluster.dbi_resource_ids + description = "List of the region-unique, immutable identifiers for the DB instances in the cluster" +} + +output "cluster_resource_id" { + value = module.rds_cluster.cluster_resource_id + description = "The region-unique, immutable identifie of the cluster" +} + +output "public_subnet_cidrs" { + value = module.subnets.public_subnet_cidrs +} + +output "private_subnet_cidrs" { + value = module.subnets.private_subnet_cidrs +} + +output "vpc_cidr" { + value = module.vpc.vpc_cidr_block +} diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf new file mode 100644 index 00000000..bb4349d6 --- /dev/null +++ b/examples/complete/variables.tf @@ -0,0 +1,73 @@ +variable "region" { + type = string + description = "AWS region" +} + +variable "availability_zones" { + type = list(string) +} + +variable "namespace" { + type = string + description = "Namespace (e.g. `eg` or `cp`)" +} + +variable "stage" { + type = string + description = "Stage (e.g. `prod`, `dev`, `staging`, `infra`)" +} + +variable "name" { + type = string + description = "Name (e.g. `app` or `cluster`)" +} + +variable "instance_type" { + type = string + description = "Instance type to use" +} + +variable "cluster_size" { + type = number + description = "Number of DB instances to create in the cluster" +} + +variable "db_name" { + type = string + description = "Database name" +} + +variable "admin_user" { + type = string + description = "(Required unless a snapshot_identifier is provided) Username for the master DB user" +} + +variable "admin_password" { + type = string + description = "(Required unless a snapshot_identifier is provided) Password for the master DB user" +} + +variable "cluster_family" { + type = string + description = "The family of the DB cluster parameter group" +} + +variable "engine" { + type = string + description = "The name of the database engine to be used for this DB cluster. Valid values: `aurora`, `aurora-mysql`, `aurora-postgresql`" +} + +variable "engine_mode" { + type = string + description = "The database engine mode. Valid values: `parallelquery`, `provisioned`, `serverless`" +} + +variable "deletion_protection" { + type = bool + description = "If the DB instance should have deletion protection enabled" +} + +variable "autoscaling_enabled" { + type = bool + description = "Whether to enable cluster autoscaling" +} diff --git a/examples/enhanced_monitoring/main.tf b/examples/enhanced_monitoring/main.tf index 3231ce1f..a288313b 100644 --- a/examples/enhanced_monitoring/main.tf +++ b/examples/enhanced_monitoring/main.tf @@ -1,7 +1,7 @@ # https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBClusterParameterGroup.html provider "aws" { - region = "us-west-2" + region = "us-west-1" # Make it faster by skipping some checks skip_get_ec2_platforms = true @@ -14,12 +14,12 @@ provider "aws" { # create IAM role for monitoring resource "aws_iam_role" "enhanced_monitoring" { name = "rds-cluster-example-1" - assume_role_policy = "${data.aws_iam_policy_document.enhanced_monitoring.json}" + assume_role_policy = data.aws_iam_policy_document.enhanced_monitoring.json } # Attach Amazon's managed policy for RDS enhanced monitoring resource "aws_iam_role_policy_attachment" "enhanced_monitoring" { - role = "${aws_iam_role.enhanced_monitoring.name}" + role = aws_iam_role.enhanced_monitoring.name policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonRDSEnhancedMonitoringRole" } @@ -58,8 +58,8 @@ module "rds_cluster_aurora_postgres" { zone_id = "Zxxxxxxxx" # enable monitoring every 30 seconds - rds_monitoring_interval = "30" + rds_monitoring_interval = 30 # reference iam role created above - rds_monitoring_role_arn = "${aws_iam_role.enhanced_monitoring.arn}" + rds_monitoring_role_arn = aws_iam_role.enhanced_monitoring.arn } diff --git a/examples/enhanced_monitoring/outputs.tf b/examples/enhanced_monitoring/outputs.tf index 24770820..4a33afc3 100644 --- a/examples/enhanced_monitoring/outputs.tf +++ b/examples/enhanced_monitoring/outputs.tf @@ -1,39 +1,39 @@ output "name" { - value = "${module.rds_cluster_aurora_postgres.name}" + value = module.rds_cluster_aurora_postgres.database_name description = "Database name" } output "user" { - value = "${module.rds_cluster_aurora_postgres.user}" + value = module.rds_cluster_aurora_postgres.user description = "Username for the master DB user" } output "cluster_name" { - value = "${module.rds_cluster_aurora_postgres.cluster_name}" + value = module.rds_cluster_aurora_postgres.cluster_name description = "Cluster Identifier" } output "arn" { - value = "${module.rds_cluster_aurora_postgres.arn}" + value = module.rds_cluster_aurora_postgres.arn description = "Amazon Resource Name (ARN) of cluster" } output "endpoint" { - value = "${module.rds_cluster_aurora_postgres.endpoint}" + value = module.rds_cluster_aurora_postgres.endpoint description = "The DNS address of the RDS instance" } output "reader_endpoint" { - value = "${module.rds_cluster_aurora_postgres.reader_endpoint}" + value = module.rds_cluster_aurora_postgres.reader_endpoint description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" } output "master_host" { - value = "${module.rds_cluster_aurora_postgres.master_host}" + value = module.rds_cluster_aurora_postgres.master_host description = "DB Master hostname" } output "replicas_host" { - value = "${module.rds_cluster_aurora_postgres.replicas_host}" + value = module.rds_cluster_aurora_postgres.replicas_host description = "Replicas hostname" } diff --git a/examples/serverless_mysql/main.tf b/examples/serverless_mysql/main.tf index e1f5f379..6570aac2 100644 --- a/examples/serverless_mysql/main.tf +++ b/examples/serverless_mysql/main.tf @@ -3,7 +3,7 @@ # https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/aurora-serverless.html provider "aws" { - region = "us-west-2" + region = "us-west-1" # Make it faster by skipping some checks skip_get_ec2_platforms = true @@ -38,6 +38,6 @@ module "rds_cluster_aurora_mysql_serverless" { max_capacity = 256 min_capacity = 2 seconds_until_auto_pause = 300 - }, + } ] } diff --git a/examples/serverless_mysql/outputs.tf b/examples/serverless_mysql/outputs.tf index 47d6a324..92a86914 100644 --- a/examples/serverless_mysql/outputs.tf +++ b/examples/serverless_mysql/outputs.tf @@ -1,39 +1,39 @@ output "name" { - value = "${module.rds_cluster_aurora_mysql_serverless.name}" + value = module.rds_cluster_aurora_mysql_serverless.database_name description = "Database name" } output "user" { - value = "${module.rds_cluster_aurora_mysql_serverless.user}" + value = module.rds_cluster_aurora_mysql_serverless.user description = "Username for the master DB user" } output "cluster_name" { - value = "${module.rds_cluster_aurora_mysql_serverless.cluster_name}" + value = module.rds_cluster_aurora_mysql_serverless.cluster_name description = "Cluster Identifier" } output "arn" { - value = "${module.rds_cluster_aurora_mysql_serverless.arn}" + value = module.rds_cluster_aurora_mysql_serverless.arn description = "Amazon Resource Name (ARN) of cluster" } output "endpoint" { - value = "${module.rds_cluster_aurora_mysql_serverless.endpoint}" + value = module.rds_cluster_aurora_mysql_serverless.endpoint description = "The DNS address of the RDS instance" } output "reader_endpoint" { - value = "${module.rds_cluster_aurora_mysql_serverless.reader_endpoint}" + value = module.rds_cluster_aurora_mysql_serverless.reader_endpoint description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" } output "master_host" { - value = "${module.rds_cluster_aurora_mysql_serverless.master_host}" + value = module.rds_cluster_aurora_mysql_serverless.master_host description = "DB Master hostname" } output "replicas_host" { - value = "${module.rds_cluster_aurora_mysql_serverless.replicas_host}" + value = module.rds_cluster_aurora_mysql_serverless.replicas_host description = "Replicas hostname" } diff --git a/examples/with_cluster_parameters/main.tf b/examples/with_cluster_parameters/main.tf index fea29d00..55e2dec8 100644 --- a/examples/with_cluster_parameters/main.tf +++ b/examples/with_cluster_parameters/main.tf @@ -1,7 +1,7 @@ # https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBClusterParameterGroup.html provider "aws" { - region = "us-west-2" + region = "us-west-1" # Make it faster by skipping some checks skip_get_ec2_platforms = true @@ -30,32 +30,39 @@ module "rds_cluster_aurora_mysql" { cluster_parameters = [ { - name = "character_set_client" - value = "utf8" + name = "character_set_client" + value = "utf8" + apply_method = "pending-reboot" }, { - name = "character_set_connection" - value = "utf8" + name = "character_set_connection" + value = "utf8" + apply_method = "pending-reboot" }, { - name = "character_set_database" - value = "utf8" + name = "character_set_database" + value = "utf8" + apply_method = "pending-reboot" }, { - name = "character_set_results" - value = "utf8" + name = "character_set_results" + value = "utf8" + apply_method = "pending-reboot" }, { - name = "character_set_server" - value = "utf8" + name = "character_set_server" + value = "utf8" + apply_method = "pending-reboot" }, { - name = "collation_connection" - value = "uft8_bin" + name = "collation_connection" + value = "utf8_bin" + apply_method = "pending-reboot" }, { - name = "collation_server" - value = "uft8_bin" + name = "collation_server" + value = "utf8_bin" + apply_method = "pending-reboot" }, { name = "lower_case_table_names" @@ -66,6 +73,6 @@ module "rds_cluster_aurora_mysql" { name = "skip-character-set-client-handshake" value = "1" apply_method = "pending-reboot" - }, + } ] } diff --git a/examples/with_cluster_parameters/outputs.tf b/examples/with_cluster_parameters/outputs.tf index 56ba843d..2c1afd74 100644 --- a/examples/with_cluster_parameters/outputs.tf +++ b/examples/with_cluster_parameters/outputs.tf @@ -1,39 +1,39 @@ output "name" { - value = "${module.rds_cluster_aurora_mysql.name}" + value = module.rds_cluster_aurora_mysql.database_name description = "Database name" } output "user" { - value = "${module.rds_cluster_aurora_mysql.user}" + value = module.rds_cluster_aurora_mysql.user description = "Username for the master DB user" } output "cluster_name" { - value = "${module.rds_cluster_aurora_mysql.cluster_name}" + value = module.rds_cluster_aurora_mysql.cluster_name description = "Cluster Identifier" } output "arn" { - value = "${module.rds_cluster_aurora_mysql.arn}" + value = module.rds_cluster_aurora_mysql.arn description = "Amazon Resource Name (ARN) of cluster" } output "endpoint" { - value = "${module.rds_cluster_aurora_mysql.endpoint}" + value = module.rds_cluster_aurora_mysql.endpoint description = "The DNS address of the RDS instance" } output "reader_endpoint" { - value = "${module.rds_cluster_aurora_mysql.reader_endpoint}" + value = module.rds_cluster_aurora_mysql.reader_endpoint description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" } output "master_host" { - value = "${module.rds_cluster_aurora_mysql.master_host}" + value = module.rds_cluster_aurora_mysql.master_host description = "DB Master hostname" } output "replicas_host" { - value = "${module.rds_cluster_aurora_mysql.replicas_host}" + value = module.rds_cluster_aurora_mysql.replicas_host description = "Replicas hostname" } diff --git a/main.tf b/main.tf index d4599b47..696ea5b1 100644 --- a/main.tf +++ b/main.tf @@ -1,32 +1,32 @@ module "label" { - source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.3.5" - namespace = "${var.namespace}" - name = "${var.name}" - stage = "${var.stage}" - delimiter = "${var.delimiter}" - attributes = "${var.attributes}" - tags = "${var.tags}" - enabled = "${var.enabled}" + source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1" + namespace = var.namespace + name = var.name + stage = var.stage + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags + enabled = var.enabled } resource "aws_security_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - name = "${module.label.id}" + count = var.enabled ? 1 : 0 + name = module.label.id description = "Allow inbound traffic from Security Groups and CIDRs" - vpc_id = "${var.vpc_id}" + vpc_id = var.vpc_id ingress { - from_port = "${var.db_port}" - to_port = "${var.db_port}" + from_port = var.db_port + to_port = var.db_port protocol = "tcp" - security_groups = ["${var.security_groups}"] + security_groups = var.security_groups } ingress { - from_port = "${var.db_port}" - to_port = "${var.db_port}" + from_port = var.db_port + to_port = var.db_port protocol = "tcp" - cidr_blocks = ["${var.allowed_cidr_blocks}"] + cidr_blocks = var.allowed_cidr_blocks } egress { @@ -36,139 +36,163 @@ resource "aws_security_group" "default" { cidr_blocks = ["0.0.0.0/0"] } - tags = "${module.label.tags}" + tags = module.label.tags } resource "aws_rds_cluster" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - cluster_identifier = "${module.label.id}" - database_name = "${var.db_name}" - master_username = "${var.admin_user}" - master_password = "${var.admin_password}" - backup_retention_period = "${var.retention_period}" - preferred_backup_window = "${var.backup_window}" - final_snapshot_identifier = "${lower(module.label.id)}" - skip_final_snapshot = "${var.skip_final_snapshot}" - apply_immediately = "${var.apply_immediately}" - storage_encrypted = "${var.storage_encrypted}" - kms_key_id = "${var.kms_key_arn}" - snapshot_identifier = "${var.snapshot_identifier}" - vpc_security_group_ids = ["${aws_security_group.default.id}"] - preferred_maintenance_window = "${var.maintenance_window}" - db_subnet_group_name = "${aws_db_subnet_group.default.name}" - db_cluster_parameter_group_name = "${aws_rds_cluster_parameter_group.default.name}" - iam_database_authentication_enabled = "${var.iam_database_authentication_enabled}" - tags = "${module.label.tags}" - engine = "${var.engine}" - engine_version = "${var.engine_version}" - engine_mode = "${var.engine_mode}" - scaling_configuration = "${var.scaling_configuration}" - replication_source_identifier = "${var.replication_source_identifier}" - enabled_cloudwatch_logs_exports = "${var.enabled_cloudwatch_logs_exports}" - deletion_protection = "${var.deletion_protection}" + count = var.enabled ? 1 : 0 + cluster_identifier = module.label.id + database_name = var.db_name + master_username = var.admin_user + master_password = var.admin_password + backup_retention_period = var.retention_period + preferred_backup_window = var.backup_window + final_snapshot_identifier = lower(module.label.id) + skip_final_snapshot = var.skip_final_snapshot + apply_immediately = var.apply_immediately + storage_encrypted = var.storage_encrypted + kms_key_id = var.kms_key_arn + snapshot_identifier = var.snapshot_identifier + vpc_security_group_ids = [join("", aws_security_group.default.*.id)] + preferred_maintenance_window = var.maintenance_window + db_subnet_group_name = join("", aws_db_subnet_group.default.*.name) + db_cluster_parameter_group_name = join("", aws_rds_cluster_parameter_group.default.*.name) + iam_database_authentication_enabled = var.iam_database_authentication_enabled + tags = module.label.tags + engine = var.engine + engine_version = var.engine_version + engine_mode = var.engine_mode + + dynamic "scaling_configuration" { + for_each = var.scaling_configuration + content { + auto_pause = lookup(scaling_configuration.value, "auto_pause", null) + max_capacity = lookup(scaling_configuration.value, "max_capacity", null) + min_capacity = lookup(scaling_configuration.value, "min_capacity", null) + seconds_until_auto_pause = lookup(scaling_configuration.value, "seconds_until_auto_pause", null) + } + } + + replication_source_identifier = var.replication_source_identifier + enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports + deletion_protection = var.deletion_protection } locals { - min_instance_count = "${var.autoscaling_enabled == "true" ? var.autoscaling_min_capacity : var.cluster_size}" - cluster_instance_count = "${var.enabled == "true" ? local.min_instance_count : 0}" + min_instance_count = var.autoscaling_enabled ? var.autoscaling_min_capacity : var.cluster_size + cluster_instance_count = var.enabled ? local.min_instance_count : 0 } resource "aws_rds_cluster_instance" "default" { - count = "${local.cluster_instance_count}" - identifier = "${module.label.id}-${count.index+1}" - cluster_identifier = "${join("", aws_rds_cluster.default.*.id)}" - instance_class = "${var.instance_type}" - db_subnet_group_name = "${aws_db_subnet_group.default.name}" - db_parameter_group_name = "${aws_db_parameter_group.default.name}" - publicly_accessible = "${var.publicly_accessible}" - tags = "${module.label.tags}" - engine = "${var.engine}" - engine_version = "${var.engine_version}" - monitoring_interval = "${var.rds_monitoring_interval}" - monitoring_role_arn = "${var.rds_monitoring_role_arn}" - performance_insights_enabled = "${var.performance_insights_enabled}" - performance_insights_kms_key_id = "${var.performance_insights_kms_key_id}" - availability_zone = "${var.instance_availability_zone}" + count = local.cluster_instance_count + identifier = "${module.label.id}-${count.index + 1}" + cluster_identifier = join("", aws_rds_cluster.default.*.id) + instance_class = var.instance_type + db_subnet_group_name = join("", aws_db_subnet_group.default.*.name) + db_parameter_group_name = join("", aws_db_parameter_group.default.*.name) + publicly_accessible = var.publicly_accessible + tags = module.label.tags + engine = var.engine + engine_version = var.engine_version + monitoring_interval = var.rds_monitoring_interval + monitoring_role_arn = var.rds_monitoring_role_arn + performance_insights_enabled = var.performance_insights_enabled + performance_insights_kms_key_id = var.performance_insights_kms_key_id + availability_zone = var.instance_availability_zone } resource "aws_db_subnet_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - name = "${module.label.id}" + count = var.enabled ? 1 : 0 + name = module.label.id description = "Allowed subnets for DB cluster instances" - subnet_ids = ["${var.subnets}"] - tags = "${module.label.tags}" + subnet_ids = var.subnets + tags = module.label.tags } resource "aws_rds_cluster_parameter_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - name = "${module.label.id}" + count = var.enabled ? 1 : 0 + name = module.label.id description = "DB cluster parameter group" - family = "${var.cluster_family}" - parameter = ["${var.cluster_parameters}"] - tags = "${module.label.tags}" + family = var.cluster_family + + dynamic "parameter" { + for_each = var.cluster_parameters + content { + apply_method = lookup(parameter.value, "apply_method", null) + name = parameter.value.name + value = parameter.value.value + } + } + + tags = module.label.tags } resource "aws_db_parameter_group" "default" { - count = "${var.enabled == "true" ? 1 : 0}" - name = "${module.label.id}" + count = var.enabled ? 1 : 0 + name = module.label.id description = "DB instance parameter group" - family = "${var.cluster_family}" - parameter = ["${var.instance_parameters}"] - tags = "${module.label.tags}" + family = var.cluster_family + + dynamic "parameter" { + for_each = var.instance_parameters + content { + apply_method = lookup(parameter.value, "apply_method", null) + name = parameter.value.name + value = parameter.value.value + } + } + + tags = module.label.tags } locals { cluster_dns_name_default = "master.${var.name}" - cluster_dns_name = "${var.cluster_dns_name != "" ? var.cluster_dns_name : local.cluster_dns_name_default}" + cluster_dns_name = var.cluster_dns_name != "" ? var.cluster_dns_name : local.cluster_dns_name_default reader_dns_name_default = "replicas.${var.name}" - reader_dns_name = "${var.reader_dns_name != "" ? var.reader_dns_name : local.reader_dns_name_default}" + reader_dns_name = var.reader_dns_name != "" ? var.reader_dns_name : local.reader_dns_name_default } module "dns_master" { - source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.6" - enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}" - namespace = "${var.namespace}" - name = "${local.cluster_dns_name}" - stage = "${var.stage}" - zone_id = "${var.zone_id}" - records = ["${coalescelist(aws_rds_cluster.default.*.endpoint, list(""))}"] + source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.3.0" + enabled = var.enabled && length(var.zone_id) > 0 ? true : false + name = local.cluster_dns_name + zone_id = var.zone_id + records = coalescelist(aws_rds_cluster.default.*.endpoint, [""]) } module "dns_replicas" { - source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.2.6" - enabled = "${var.enabled == "true" && length(var.zone_id) > 0 ? "true" : "false"}" - namespace = "${var.namespace}" - name = "${local.reader_dns_name}" - stage = "${var.stage}" - zone_id = "${var.zone_id}" - records = ["${coalescelist(aws_rds_cluster.default.*.reader_endpoint, list(""))}"] + source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.3.0" + enabled = var.enabled && length(var.zone_id) > 0 && var.engine_mode != "serverless" ? true : false + name = local.reader_dns_name + zone_id = var.zone_id + records = coalescelist(aws_rds_cluster.default.*.reader_endpoint, [""]) } resource "aws_appautoscaling_target" "replicas" { - count = "${var.enabled == "true" && var.autoscaling_enabled == "true" ? 1 : 0}" + count = var.enabled && var.autoscaling_enabled ? 1 : 0 service_namespace = "rds" scalable_dimension = "rds:cluster:ReadReplicaCount" - resource_id = "cluster:${aws_rds_cluster.default.id}" - min_capacity = "${var.autoscaling_min_capacity}" - max_capacity = "${var.autoscaling_max_capacity}" + resource_id = "cluster:${join("", aws_rds_cluster.default.*.id)}" + min_capacity = var.autoscaling_min_capacity + max_capacity = var.autoscaling_max_capacity } resource "aws_appautoscaling_policy" "replicas" { - count = "${var.enabled == "true" && var.autoscaling_enabled == "true" ? 1 : 0}" - name = "${module.label.id}" - service_namespace = "${join("", aws_appautoscaling_target.replicas.*.service_namespace)}" - scalable_dimension = "${join("", aws_appautoscaling_target.replicas.*.scalable_dimension)}" - resource_id = "${join("", aws_appautoscaling_target.replicas.*.resource_id)}" - policy_type = "${var.autoscaling_policy_type}" + count = var.enabled && var.autoscaling_enabled ? 1 : 0 + name = module.label.id + service_namespace = join("", aws_appautoscaling_target.replicas.*.service_namespace) + scalable_dimension = join("", aws_appautoscaling_target.replicas.*.scalable_dimension) + resource_id = join("", aws_appautoscaling_target.replicas.*.resource_id) + policy_type = var.autoscaling_policy_type target_tracking_scaling_policy_configuration { predefined_metric_specification { - predefined_metric_type = "${var.autoscaling_target_metrics}" + predefined_metric_type = var.autoscaling_target_metrics } disable_scale_in = false - target_value = "${var.autoscaling_target_value}" - scale_in_cooldown = "${var.autoscaling_scale_in_cooldown}" - scale_out_cooldown = "${var.autoscaling_scale_out_cooldown}" + target_value = var.autoscaling_target_value + scale_in_cooldown = var.autoscaling_scale_in_cooldown + scale_out_cooldown = var.autoscaling_scale_out_cooldown } } diff --git a/outputs.tf b/outputs.tf index df074c1a..1777f728 100644 --- a/outputs.tf +++ b/outputs.tf @@ -1,49 +1,54 @@ -output "name" { - value = "${join("", aws_rds_cluster.default.*.database_name)}" +output "database_name" { + value = join("", aws_rds_cluster.default.*.database_name) description = "Database name" } -output "user" { - value = "${join("", aws_rds_cluster.default.*.master_username)}" +output "master_username" { + value = join("", aws_rds_cluster.default.*.master_username) description = "Username for the master DB user" } -output "cluster_name" { - value = "${join("", aws_rds_cluster.default.*.cluster_identifier)}" +output "cluster_identifier" { + value = join("", aws_rds_cluster.default.*.cluster_identifier) description = "Cluster Identifier" } output "arn" { - value = "${join("", aws_rds_cluster.default.*.arn)}" + value = join("", aws_rds_cluster.default.*.arn) description = "Amazon Resource Name (ARN) of cluster" } output "endpoint" { - value = "${join("", aws_rds_cluster.default.*.endpoint)}" + value = join("", aws_rds_cluster.default.*.endpoint) description = "The DNS address of the RDS instance" } output "reader_endpoint" { - value = "${join("", aws_rds_cluster.default.*.reader_endpoint)}" + value = join("", aws_rds_cluster.default.*.reader_endpoint) description = "A read-only endpoint for the Aurora cluster, automatically load-balanced across replicas" } output "master_host" { - value = "${module.dns_master.hostname}" + value = module.dns_master.hostname description = "DB Master hostname" } output "replicas_host" { - value = "${module.dns_replicas.hostname}" + value = module.dns_replicas.hostname description = "Replicas hostname" } output "dbi_resource_ids" { - value = ["${aws_rds_cluster_instance.default.*.dbi_resource_id}"] - description = "List of the region-unique, immutable identifiers for the DB instances in the cluster." + value = aws_rds_cluster_instance.default.*.dbi_resource_id + description = "List of the region-unique, immutable identifiers for the DB instances in the cluster" } output "cluster_resource_id" { - value = "${join("", aws_rds_cluster.default.*.cluster_resource_id )}" - description = "The region-unique, immutable identifie of the cluster." + value = join("", aws_rds_cluster.default.*.cluster_resource_id) + description = "The region-unique, immutable identifie of the cluster" +} + +output "cluster_security_groups" { + value = coalescelist(aws_rds_cluster.default.*.vpc_security_group_ids, [""]) + description = "Default RDS cluster security groups" } diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 00000000..442804a2 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +.test-harness diff --git a/test/Makefile b/test/Makefile new file mode 100644 index 00000000..17b2fe74 --- /dev/null +++ b/test/Makefile @@ -0,0 +1,43 @@ +TEST_HARNESS ?= https://github.com/cloudposse/test-harness.git +TEST_HARNESS_BRANCH ?= master +TEST_HARNESS_PATH = $(realpath .test-harness) +BATS_ARGS ?= --tap +BATS_LOG ?= test.log + +# Define a macro to run the tests +define RUN_TESTS +@echo "Running tests in $(1)" +@cd $(1) && bats $(BATS_ARGS) $(addsuffix .bats,$(addprefix $(TEST_HARNESS_PATH)/test/terraform/,$(TESTS))) +endef + +default: all + +-include Makefile.* + +## Provision the test-harnesss +.test-harness: + [ -d $@ ] || git clone --depth=1 -b $(TEST_HARNESS_BRANCH) $(TEST_HARNESS) $@ + +## Initialize the tests +init: .test-harness + +## Install all dependencies (OS specific) +deps:: + @exit 0 + +## Clean up the test harness +clean: + [ "$(TEST_HARNESS_PATH)" == "/" ] || rm -rf $(TEST_HARNESS_PATH) + +## Run all tests +all: module examples/complete + +## Run basic sanity checks against the module itself +module: export TESTS ?= installed lint get-modules module-pinning get-plugins provider-pinning validate terraform-docs input-descriptions output-descriptions +module: deps + $(call RUN_TESTS, ../) + +## Run tests against example +examples/complete: export TESTS ?= installed lint get-modules get-plugins validate +examples/complete: deps + $(call RUN_TESTS, ../$@) diff --git a/test/Makefile.alpine b/test/Makefile.alpine new file mode 100644 index 00000000..7925b186 --- /dev/null +++ b/test/Makefile.alpine @@ -0,0 +1,5 @@ +ifneq (,$(wildcard /sbin/apk)) +## Install all dependencies for alpine +deps:: init + @apk add --update terraform-docs@cloudposse json2hcl@cloudposse +endif diff --git a/test/src/.gitignore b/test/src/.gitignore new file mode 100644 index 00000000..31b0219e --- /dev/null +++ b/test/src/.gitignore @@ -0,0 +1,2 @@ +.gopath +vendor/ diff --git a/test/src/Gopkg.lock b/test/src/Gopkg.lock new file mode 100644 index 00000000..87bb6bd6 --- /dev/null +++ b/test/src/Gopkg.lock @@ -0,0 +1,92 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "UT" + revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73" + version = "v1.1.1" + +[[projects]] + digest = "1:75d6042fc66aebc974cc49b0c6c7cc3b9adb5f8130fbfa0dbec0820d990afa25" + name = "github.com/gruntwork-io/terratest" + packages = [ + "modules/collections", + "modules/customerrors", + "modules/files", + "modules/logger", + "modules/retry", + "modules/shell", + "modules/ssh", + "modules/terraform", + ] + pruneopts = "UT" + revision = "892abb2c35878d0808101bbfe6559e931dc2d354" + version = "v0.16.0" + +[[projects]] + digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe" + name = "github.com/pmezard/go-difflib" + packages = ["difflib"] + pruneopts = "UT" + revision = "792786c7400a136282c1664665ae0a8db921c6c2" + version = "v1.0.0" + +[[projects]] + digest = "1:5da8ce674952566deae4dbc23d07c85caafc6cfa815b0b3e03e41979cedb8750" + name = "github.com/stretchr/testify" + packages = [ + "assert", + "require", + ] + pruneopts = "UT" + revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053" + version = "v1.3.0" + +[[projects]] + branch = "master" + digest = "1:831470c2758c8b733941144f2803a0ccad0632c5a767415b777ebd296b5f463e" + name = "golang.org/x/crypto" + packages = [ + "curve25519", + "ed25519", + "ed25519/internal/edwards25519", + "internal/chacha20", + "internal/subtle", + "poly1305", + "ssh", + "ssh/agent", + ] + pruneopts = "UT" + revision = "22d7a77e9e5f409e934ed268692e56707cd169e5" + +[[projects]] + branch = "master" + digest = "1:76ee51c3f468493aff39dbacc401e8831fbb765104cbf613b89bef01cf4bad70" + name = "golang.org/x/net" + packages = ["context"] + pruneopts = "UT" + revision = "f3200d17e092c607f615320ecaad13d87ad9a2b3" + +[[projects]] + branch = "master" + digest = "1:181f3fd33e620b958b5ab77da177cf775cdcccd7db82963607875fbd09ae995e" + name = "golang.org/x/sys" + packages = [ + "cpu", + "unix", + ] + pruneopts = "UT" + revision = "9cd6430ef91e39e1a0ec0470cf1321a33ef1b887" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/gruntwork-io/terratest/modules/terraform", + "github.com/stretchr/testify/assert", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/test/src/Gopkg.toml b/test/src/Gopkg.toml new file mode 100644 index 00000000..995bac57 --- /dev/null +++ b/test/src/Gopkg.toml @@ -0,0 +1,7 @@ +[[constraint]] + name = "github.com/stretchr/testify" + version = "1.2.2" + +[prune] + go-tests = true + unused-packages = true diff --git a/test/src/Makefile b/test/src/Makefile new file mode 100644 index 00000000..8138a780 --- /dev/null +++ b/test/src/Makefile @@ -0,0 +1,50 @@ +PACKAGE = terraform-aws-rds-cluster +GOEXE ?= /usr/bin/go +GOPATH = $(CURDIR)/.gopath +GOBIN = $(GOPATH)/bin +BASE = $(GOPATH)/src/$(PACKAGE) +PATH := $(PATH):$(GOBIN) + +export TF_DATA_DIR ?= $(CURDIR)/.terraform +export TF_CLI_ARGS_init ?= -get-plugins=true +export GOPATH + +.PHONY: all +## Default target +all: test + +ifneq (,$(wildcard /sbin/apk)) +## Install go, if not installed +$(GOEXE): + apk add --update go +endif + +ifeq ($(shell uname -s),Linux) +## Install all `dep`, if not installed +$(GOBIN)/dep: + @mkdir -p $(GOBIN) + @curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh +endif + +## Prepare the GOPATH +$(BASE): $(GOEXE) + @mkdir -p $(dir $@) + @ln -sf $(CURDIR) $@ + +## Download vendor dependencies to vendor/ +$(BASE)/vendor: $(BASE) $(GOBIN)/dep + cd $(BASE) && dep ensure + +.PHONY : init +## Initialize tests +init: $(BASE)/vendor + +.PHONY : test +## Run tests +test: init + cd $(BASE) && go test -v -timeout 30m -run TestExamplesComplete + +.PHONY : clean +## Clean up files +clean: + rm -rf .gopath/ vendor/ $(TF_DATA_DIR) diff --git a/test/src/examples_complete_test.go b/test/src/examples_complete_test.go new file mode 100644 index 00000000..f1b57f2a --- /dev/null +++ b/test/src/examples_complete_test.go @@ -0,0 +1,52 @@ +package test + +import ( + "testing" + + "github.com/gruntwork-io/terratest/modules/terraform" + "github.com/stretchr/testify/assert" +) + +// Test the Terraform module in examples/complete using Terratest. +func TestExamplesComplete(t *testing.T) { + t.Parallel() + + terraformOptions := &terraform.Options{ + // The path to where our Terraform code is located + TerraformDir: "../../examples/complete", + Upgrade: true, + // Variables to pass to our Terraform code using -var-file options + VarFiles: []string{"fixtures.us-west-1.tfvars"}, + } + + // At the end of the test, run `terraform destroy` to clean up any resources that were created + defer terraform.Destroy(t, terraformOptions) + + // This will run `terraform init` and `terraform apply` and fail the test if there are any errors + terraform.InitAndApply(t, terraformOptions) + + // Run `terraform output` to get the value of an output variable + vpcCidr := terraform.Output(t, terraformOptions, "vpc_cidr") + // Verify we're getting back the outputs we expect + assert.Equal(t, "172.16.0.0/16", vpcCidr) + + // Run `terraform output` to get the value of an output variable + privateSubnetCidrs := terraform.OutputList(t, terraformOptions, "private_subnet_cidrs") + // Verify we're getting back the outputs we expect + assert.Equal(t, []string{"172.16.0.0/18", "172.16.64.0/18"}, privateSubnetCidrs) + + // Run `terraform output` to get the value of an output variable + publicSubnetCidrs := terraform.OutputList(t, terraformOptions, "public_subnet_cidrs") + // Verify we're getting back the outputs we expect + assert.Equal(t, []string{"172.16.128.0/18", "172.16.192.0/18"}, publicSubnetCidrs) + + // Run `terraform output` to get the value of an output variable + clusterIdentifier := terraform.Output(t, terraformOptions, "cluster_identifier") + // Verify we're getting back the outputs we expect + assert.Equal(t, "eg-test-rds-cluster", clusterIdentifier) + + // Run `terraform output` to get the value of an output variable + arn := terraform.Output(t, terraformOptions, "arn") + // Verify we're getting back the outputs we expect + assert.Equal(t, "arn:aws:rds:us-west-1:126450723953:cluster:eg-test-rds-cluster", arn) +} diff --git a/variables.tf b/variables.tf index f4ef82dd..daebcb05 100644 --- a/variables.tf +++ b/variables.tf @@ -1,297 +1,326 @@ variable "namespace" { - type = "string" + type = string description = "Namespace (e.g. `eg` or `cp`)" + default = "" } variable "stage" { - type = "string" + type = string description = "Stage (e.g. `prod`, `dev`, `staging`)" + default = "" } variable "name" { - type = "string" + type = string description = "Name of the application" } variable "zone_id" { - type = "string" + type = string default = "" description = "Route53 parent zone ID. If provided (not empty), the module will create sub-domain DNS records for the DB master and replicas" } variable "security_groups" { - type = "list" + type = list(string) default = [] description = "List of security groups to be allowed to connect to the DB instance" } variable "vpc_id" { - type = "string" + type = string description = "VPC ID to create the cluster in (e.g. `vpc-a22222ee`)" } variable "subnets" { - type = "list" + type = list(string) description = "List of VPC subnet IDs" } variable "instance_type" { - type = "string" + type = string default = "db.t2.small" description = "Instance type to use" } variable "cluster_size" { - type = "string" - default = "2" + type = number + default = 2 description = "Number of DB instances to create in the cluster" } variable "snapshot_identifier" { - type = "string" + type = string default = "" description = "Specifies whether or not to create this cluster from a snapshot" } variable "db_name" { - type = "string" + type = string description = "Database name" } variable "db_port" { - type = "string" - default = "3306" + type = number + default = 3306 description = "Database port" } variable "admin_user" { - type = "string" + type = string default = "admin" description = "(Required unless a snapshot_identifier is provided) Username for the master DB user" } variable "admin_password" { - type = "string" + type = string default = "" description = "(Required unless a snapshot_identifier is provided) Password for the master DB user" } variable "retention_period" { - type = "string" - default = "5" + type = number + default = 5 description = "Number of days to retain backups for" } variable "backup_window" { - type = "string" + type = string default = "07:00-09:00" description = "Daily time range during which the backups happen" } variable "maintenance_window" { - type = "string" + type = string default = "wed:03:00-wed:04:00" description = "Weekly time range during which system maintenance can occur, in UTC" } variable "delimiter" { - type = "string" + type = string default = "-" description = "Delimiter to be used between `name`, `namespace`, `stage` and `attributes`" } variable "attributes" { - type = "list" + type = list(string) default = [] description = "Additional attributes (e.g. `1`)" } variable "tags" { - type = "map" + type = map(string) default = {} description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)" } variable "cluster_parameters" { - type = "list" + type = list(object({ + apply_method = string + name = string + value = string + })) default = [] - description = "List of DB parameters to apply" + description = "List of DB cluster parameters to apply" } variable "instance_parameters" { - type = "list" + type = list(object({ + apply_method = string + name = string + value = string + })) default = [] description = "List of DB instance parameters to apply" } variable "cluster_family" { - type = "string" + type = string default = "aurora5.6" description = "The family of the DB cluster parameter group" } variable "engine" { - type = "string" + type = string default = "aurora" description = "The name of the database engine to be used for this DB cluster. Valid values: `aurora`, `aurora-mysql`, `aurora-postgresql`" } variable "engine_mode" { - type = "string" + type = string default = "provisioned" description = "The database engine mode. Valid values: `parallelquery`, `provisioned`, `serverless`" } variable "engine_version" { - type = "string" + type = string default = "" description = "The version number of the database engine to use" } variable "scaling_configuration" { - type = "list" + type = list(object({ + auto_pause = bool + max_capacity = number + min_capacity = number + seconds_until_auto_pause = number + })) default = [] - description = "List of nested attributes with scaling properties. Only valid when engine_mode is set to `serverless`" + description = "List of nested attributes with scaling properties. Only valid when `engine_mode` is set to `serverless`" } variable "allowed_cidr_blocks" { - type = "list" + type = list(string) default = [] - description = "List of CIDR blocks allowed to access" + description = "List of CIDR blocks allowed to access the cluster" } variable "enabled" { + type = bool description = "Set to false to prevent the module from creating any resources" - default = "true" + default = true } variable "publicly_accessible" { + type = bool description = "Set to true if you want your cluster to be publicly accessible (such as via QuickSight)" - default = "false" + default = false } variable "storage_encrypted" { + type = bool description = "Specifies whether the DB cluster is encrypted. The default is `false` for `provisioned` `engine_mode` and `true` for `serverless` `engine_mode`" - default = "false" + default = false } variable "kms_key_arn" { - description = "The ARN for the KMS encryption key. When specifying kms_key_arn, storage_encrypted needs to be set to true." + type = string + description = "The ARN for the KMS encryption key. When specifying `kms_key_arn`, `storage_encrypted` needs to be set to `true`" default = "" } variable "skip_final_snapshot" { + type = bool description = "Determines whether a final DB snapshot is created before the DB cluster is deleted" - default = "true" + default = true } variable "deletion_protection" { - type = "string" - description = "If the DB instance should have deletion protection enabled." - default = "false" + type = bool + description = "If the DB instance should have deletion protection enabled" + default = false } variable "apply_immediately" { + type = bool description = "Specifies whether any cluster modifications are applied immediately, or during the next maintenance window" - default = "true" + default = true } variable "iam_database_authentication_enabled" { - description = "Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled." - default = "false" + type = bool + description = "Specifies whether or mappings of AWS Identity and Access Management (IAM) accounts to database accounts is enabled" + default = false } variable "rds_monitoring_interval" { + type = number description = "Interval in seconds that metrics are collected, 0 to disable (values can only be 0, 1, 5, 10, 15, 30, 60)" - default = "0" + default = 0 } variable "rds_monitoring_role_arn" { - type = "string" + type = string default = "" description = "The ARN for the IAM role that can send monitoring metrics to CloudWatch Logs" } variable "replication_source_identifier" { - type = "string" + type = string description = "ARN of a source DB cluster or DB instance if this DB cluster is to be created as a Read Replica" default = "" } variable "enabled_cloudwatch_logs_exports" { - type = "list" - description = "List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery." + type = list(string) + description = "List of log types to export to cloudwatch. The following log types are supported: audit, error, general, slowquery" default = [] } variable "performance_insights_enabled" { - type = "string" - default = "false" + type = bool + default = false description = "Whether to enable Performance Insights" } variable "performance_insights_kms_key_id" { - type = "string" + type = string default = "" description = "The ARN for the KMS key to encrypt Performance Insights data. When specifying `performance_insights_kms_key_id`, `performance_insights_enabled` needs to be set to true" } variable "autoscaling_enabled" { - type = "string" - default = "false" + type = bool + default = false description = "Whether to enable cluster autoscaling" } variable "autoscaling_policy_type" { - type = "string" + type = string default = "TargetTrackingScaling" description = "Autoscaling policy type. `TargetTrackingScaling` and `StepScaling` are supported" } variable "autoscaling_target_metrics" { - type = "string" + type = string default = "RDSReaderAverageCPUUtilization" description = "The metrics type to use. If this value isn't provided the default is CPU utilization" } variable "autoscaling_target_value" { + type = number default = 75 description = "The target value to scale with respect to target metrics" } variable "autoscaling_scale_in_cooldown" { + type = number default = 300 description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling down activity can start. Default is 300s" } variable "autoscaling_scale_out_cooldown" { + type = number default = 300 description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling up activity can start. Default is 300s" } variable "autoscaling_min_capacity" { + type = number default = 1 description = "Minimum number of instances to be maintained by the autoscaler" } variable "autoscaling_max_capacity" { + type = number default = 5 description = "Maximum number of instances to be maintained by the autoscaler" } variable "instance_availability_zone" { + type = string default = "" description = "Optional parameter to place cluster instances in a specific availability zone. If left empty, will place randomly" } variable "cluster_dns_name" { - type = "string" + type = string description = "Name of the cluster CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `master.var.name`" default = "" } variable "reader_dns_name" { - type = "string" + type = string description = "Name of the reader endpoint CNAME record to create in the parent DNS zone specified by `zone_id`. If left empty, the name will be auto-asigned using the format `replicas.var.name`" default = "" } diff --git a/versions.tf b/versions.tf new file mode 100644 index 00000000..4c7776f9 --- /dev/null +++ b/versions.tf @@ -0,0 +1,8 @@ +terraform { + required_version = "~> 0.12.0" + + required_providers { + aws = "~> 2.0" + null = "~> 2.0" + } +}