Skip to content

Commit

Permalink
Groundwork new workflows (#54)
Browse files Browse the repository at this point in the history
* Groundwork new workflows

* Update variables.tf

* Update variables.tf

* fix regex

* bump version

* fix tests

* fix tests

* fix tests

* fix test
  • Loading branch information
max-lobur authored Mar 28, 2023
1 parent 07ed881 commit 6bbfaf9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 103 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.

## Copyright

Copyright © 2017-2022 [Cloud Posse, LLC](https://cpco.io/copyright)
Copyright © 2017-2023 [Cloud Posse, LLC](https://cpco.io/copyright)



Expand Down Expand Up @@ -451,7 +451,7 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply

[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]

<!-- markdownlint-disable -->
[logo]: https://cloudposse.com/logo-300x69.svg
[docs]: https://cpco.io/docs?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-elasticache-memcached&utm_content=docs
[website]: https://cpco.io/homepage?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-elasticache-memcached&utm_content=website
Expand Down Expand Up @@ -482,3 +482,4 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
[share_googleplus]: https://plus.google.com/share?url=https://github.com/cloudposse/terraform-aws-elasticache-memcached
[share_email]: mailto:?subject=terraform-aws-elasticache-memcached&body=https://github.com/cloudposse/terraform-aws-elasticache-memcached
[beacon]: https://ga-beacon.cloudposse.com/UA-76589703-4/cloudposse/terraform-aws-elasticache-memcached?pixel&cs=github&cm=readme&an=terraform-aws-elasticache-memcached
<!-- markdownlint-restore -->
90 changes: 0 additions & 90 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,6 @@ variable "availability_zones" {
description = "List of Availability Zones for the cluster. az_mode must be set to cross-az when used."
}

variable "vpc_id" {
type = string
default = ""
description = "VPC ID"
}

variable "max_item_size" {
type = number
default = 10485760
description = "Max item size"
}

variable "subnets" {
type = list(string)
default = []
description = "AWS subnet ids"
}

variable "maintenance_window" {
type = string
default = "wed:03:00-wed:04:00"
description = "Maintenance window"
}

variable "cluster_size" {
type = number
default = 1
Expand All @@ -63,78 +39,12 @@ variable "engine_version" {
description = "Memcached engine version. For more info, see https://docs.aws.amazon.com/AmazonElastiCache/latest/mem-ug/supported-engine-versions.html"
}

variable "notification_topic_arn" {
type = string
default = ""
description = "Notification topic arn"
}

variable "alarm_cpu_threshold_percent" {
type = number
default = 75
description = "CPU threshold alarm level"
}

variable "alarm_memory_threshold_bytes" {
type = number
default = 10000000 # 10MB
description = "Alarm memory threshold bytes"
}

variable "alarm_actions" {
type = list(string)
default = []
description = "Alarm actions"
}

variable "apply_immediately" {
type = bool
default = true
description = "Specifies whether any database modifications are applied immediately, or during the next maintenance window"
}

variable "zone_id" {
type = string
default = ""
description = "Route53 DNS Zone ID"
}

variable "port" {
type = number
default = 11211
description = "Memcached port"
}

variable "use_existing_security_groups" {
type = bool
description = "Flag to enable/disable creation of Security Group in the module. Set to `true` to disable Security Group creation and provide a list of existing security Group IDs in `existing_security_groups` to place the cluster into"
default = false
}

variable "existing_security_groups" {
type = list(string)
default = []
description = "List of existing Security Group IDs to place the cluster into. Set `use_existing_security_groups` to `true` to enable using `existing_security_groups` as Security Groups for the cluster"
}

variable "allowed_security_groups" {
type = list(string)
default = []
description = "List of Security Group IDs that are allowed ingress to the cluster's Security Group created in the module"
}

variable "allowed_cidr_blocks" {
type = list(string)
default = []
description = "List of CIDR blocks that are allowed ingress to the cluster's Security Group created in the module"
}

variable "elasticache_subnet_group_name" {
type = string
description = "Subnet group name for the ElastiCache instance"
default = ""
}

variable "elasticache_parameter_group_family" {
type = string
description = "ElastiCache parameter group family"
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
terraform {
required_version = ">= 0.13.0"
required_version = ">= 0.14.0"

required_providers {
aws = {
Expand Down
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
elasticache_subnet_group_name = var.elasticache_subnet_group_name != "" ? var.elasticache_subnet_group_name : join("", aws_elasticache_subnet_group.default.*.name)
elasticache_subnet_group_name = var.elasticache_subnet_group_name != "" ? var.elasticache_subnet_group_name : join("", aws_elasticache_subnet_group.default[*].name)
enabled = module.this.enabled
}

Expand All @@ -8,7 +8,7 @@ resource "null_resource" "cluster_urls" {

triggers = {
name = "${replace(
join("", aws_elasticache_cluster.default.*.cluster_address),
join("", aws_elasticache_cluster.default[*].cluster_address),
".cfg.",
format(".%04d.", count.index + 1)
)}:${var.port}"
Expand Down Expand Up @@ -106,7 +106,7 @@ resource "aws_elasticache_cluster" "default" {
engine_version = var.engine_version
node_type = var.instance_type
num_cache_nodes = var.cluster_size
parameter_group_name = join("", aws_elasticache_parameter_group.default.*.name)
parameter_group_name = join("", aws_elasticache_parameter_group.default[*].name)
subnet_group_name = local.elasticache_subnet_group_name
# It would be nice to remove null or duplicate security group IDs, if there are any, using `compact`,
# but that causes problems, and having duplicates does not seem to cause problems.
Expand Down Expand Up @@ -173,7 +173,7 @@ module "dns" {
dns_name = var.dns_subdomain != "" ? var.dns_subdomain : module.this.id
ttl = 60
zone_id = var.zone_id
records = [join("", aws_elasticache_cluster.default.*.cluster_address)]
records = [join("", aws_elasticache_cluster.default[*].cluster_address)]

context = module.this.context
}
10 changes: 5 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
output "cluster_id" {
value = join("", aws_elasticache_cluster.default.*.id)
value = join("", aws_elasticache_cluster.default[*].id)
description = "Cluster ID"
}

Expand All @@ -9,7 +9,7 @@ output "security_group_id" {
}

output "security_group_arn" {
value = join("", module.aws_security_group.*.arn)
value = join("", module.aws_security_group[*].arn)
description = "The ARN of the created security group"
}

Expand All @@ -19,12 +19,12 @@ output "security_group_name" {
}

output "cluster_address" {
value = join("", aws_elasticache_cluster.default.*.cluster_address)
value = join("", aws_elasticache_cluster.default[*].cluster_address)
description = "Cluster address"
}

output "cluster_configuration_endpoint" {
value = join("", aws_elasticache_cluster.default.*.configuration_endpoint)
value = join("", aws_elasticache_cluster.default[*].configuration_endpoint)
description = "Cluster configuration endpoint"
}

Expand All @@ -34,6 +34,6 @@ output "hostname" {
}

output "cluster_urls" {
value = null_resource.cluster_urls.*.triggers.name
value = null_resource.cluster_urls[*].triggers.name
description = "Cluster URLs"
}
10 changes: 9 additions & 1 deletion test/src/examples_complete_test.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
package test

import (
"strings"
"testing"
"fmt"

"github.com/gruntwork-io/terratest/modules/random"
"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()
randID := strings.ToLower(random.UniqueId())
attributes := []string{randID}

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-east-2.tfvars"},
Vars: map[string]interface{}{
"attributes": attributes,
},
}

// At the end of the test, run `terraform destroy` to clean up any resources that were created
Expand All @@ -43,5 +51,5 @@ func TestExamplesComplete(t *testing.T) {
// Run `terraform output` to get the value of an output variable
clusterId := terraform.Output(t, terraformOptions, "cluster_id")
// Verify we're getting back the outputs we expect
assert.Equal(t, "eg-test-memcached-test", clusterId)
assert.Equal(t, fmt.Sprintf("eg-test-memcached-test-%s", randID), clusterId)
}

0 comments on commit 6bbfaf9

Please sign in to comment.