Skip to content

Commit

Permalink
feat:! Adds Maintenance Policy (#95)
Browse files Browse the repository at this point in the history
* add maintenance window

* readme update

* remove trailing whitespace

* update default var

* update default var

* update var default

* default to 12:30 EST Friday

* support backwards compatability

* update docs

* format

* whitespace

* memcached + version bumps

* duration param

* format :)

* documentation

* Update versions.tf

Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>

Co-authored-by: Andrew Peabody <apeabody@gmail.com>
Co-authored-by: Bharath KKB <bharathkrishnakb@gmail.com>
  • Loading branch information
3 people committed Aug 5, 2022
1 parent 0c0dd29 commit 561af25
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module "memorystore" {
| enable\_apis | Flag for enabling redis.googleapis.com in your project | `bool` | `true` | no |
| labels | The resource labels to represent user provided metadata. | `map(string)` | `null` | no |
| location\_id | The zone where the instance will be provisioned. If not provided, the service will choose a zone for the instance. For STANDARD\_HA tier, instances will be created across two zones for protection against zonal failures. If [alternativeLocationId] is also provided, it must be different from [locationId]. | `string` | `null` | no |
| maintenance\_policy | The maintenance policy for an instance. | <pre>object({<br> day = string<br> start_time = object({<br> hours = number<br> minutes = number<br> seconds = number<br> nanos = number<br> })<br> })</pre> | `null` | no |
| memory\_size\_gb | Redis memory size in GiB. Defaulted to 1 GiB | `number` | `1` | no |
| name | The ID of the instance or a fully qualified identifier for the instance. | `string` | n/a | yes |
| project | The ID of the project in which the resource belongs to. | `string` | n/a | yes |
Expand Down
4 changes: 2 additions & 2 deletions examples/memcache/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "~> 3.52"
version = "~> 4.23.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = "~> 3.52"
version = "~> 4.23.0"
}
}
}
15 changes: 15 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ resource "google_redis_instance" "default" {
auth_enabled = var.auth_enabled

transit_encryption_mode = var.transit_encryption_mode

dynamic "maintenance_policy" {
for_each = var.maintenance_policy != null ? [var.maintenance_policy] : []
content {
weekly_maintenance_window {
day = maintenance_policy.value["day"]
start_time {
hours = maintenance_policy.value["start_time"]["hours"]
minutes = maintenance_policy.value["start_time"]["minutes"]
seconds = maintenance_policy.value["start_time"]["seconds"]
nanos = maintenance_policy.value["start_time"]["nanos"]
}
}
}
}
}

module "enable_apis" {
Expand Down
1 change: 1 addition & 0 deletions modules/memcache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A Terraform module for creating a fully functional Google Memorystore (memcache)
| display\_name | An arbitrary and optional user-provided name for the instance. | `string` | `null` | no |
| enable\_apis | Flag for enabling memcache.googleapis.com in your project | `bool` | `true` | no |
| labels | The resource labels to represent user provided metadata. | `map(string)` | `{}` | no |
| maintenance\_policy | The maintenance policy for an instance. | <pre>object({<br> day = string<br> duration = number<br> start_time = object({<br> hours = number<br> minutes = number<br> seconds = number<br> nanos = number<br> })<br> })</pre> | `null` | no |
| memory\_size\_mb | Memcache memory size in MiB. Defaulted to 1024 | `number` | `1024` | no |
| name | The ID of the instance or a fully qualified identifier for the instance. | `string` | n/a | yes |
| node\_count | Number of nodes in the memcache instance. | `number` | `1` | no |
Expand Down
16 changes: 16 additions & 0 deletions modules/memcache/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ resource "google_memcache_instance" "self" {
}
}

dynamic "maintenance_policy" {
for_each = var.maintenance_policy != null ? [var.maintenance_policy] : []
content {
weekly_maintenance_window {
day = maintenance_policy.value["day"]
duration = maintenance_policy.value["duration"]
start_time {
hours = maintenance_policy.value["start_time"]["hours"]
minutes = maintenance_policy.value["start_time"]["minutes"]
seconds = maintenance_policy.value["start_time"]["seconds"]
nanos = maintenance_policy.value["start_time"]["nanos"]
}
}
}
}

}


Expand Down
16 changes: 16 additions & 0 deletions modules/memcache/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@ variable "params" {
type = map(string)
default = null
}

variable "maintenance_policy" {
description = "The maintenance policy for an instance."
# type = object(any)
type = object({
day = string
duration = number
start_time = object({
hours = number
minutes = number
seconds = number
nanos = number
})
})
default = null
}
4 changes: 2 additions & 2 deletions modules/memcache/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 3.53, < 5.0"
version = ">= 4.23.0, < 5.0"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 3.53, < 5.0"
version = ">= 4.23.0, < 5.0"
}
}

Expand Down
15 changes: 15 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,18 @@ variable "transit_encryption_mode" {
type = string
default = "SERVER_AUTHENTICATION"
}

variable "maintenance_policy" {
description = "The maintenance policy for an instance."
# type = object(any)
type = object({
day = string
start_time = object({
hours = number
minutes = number
seconds = number
nanos = number
})
})
default = null
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ terraform {

google = {
source = "hashicorp/google"
version = ">= 3.53, < 5.0"
version = ">= 4.10.0, < 5.0"
}
}

Expand Down

0 comments on commit 561af25

Please sign in to comment.