IBM-Cloud / terraform-provider-ibm

https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs
Mozilla Public License 2.0
341 stars 670 forks source link

[Redis]Β Regression > 1.50.0 on maxmemory / maxmerory-redis configuration parameter #4528

Closed ifs-anthonylecarrer closed 1 year ago

ifs-anthonylecarrer commented 1 year ago

Community Note

Terraform CLI and Terraform IBM Provider Version

bash-5.0$ ibmcloud --version
ibmcloud version 2.16.0+492aff3-2023-04-06T16:27:10+00:00
bash-5.0$ terraform -v
Terraform v1.0.7
on darwin_amd64
+ provider registry.terraform.io/ibm-cloud/ibm v1.52.1

Your version of Terraform is out of date! The latest version
is 1.4.5. You can update by downloading from https://www.terraform.io/downloads.html
bash-5.0$ 

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Common vars

variable "region" {
  description = "IBM Region where the infrastructure is hosted in"
  type        = string
  default     = "eu-de"
}

variable "environment_id" {
  type        = string
  description = "Environment id (e.g. `integration`)"
}

variable "resource_group_id" {
  type        = string
  description = "Target resource group ID"
}

variable "tags" {
  description = "A list of tags to assign to the resource."
  type        = list(string)
}

variable "vpc_name" {
  description = "the name of the vpc created by LZ"
  type        = string
}

variable "redis_instance_info" {
  type = object({
    name                         = string
    plan                         = string
    version                      = string
    members_memory_allocation_mb = number
    members_disk_allocation_mb   = number
  })
  default = null
}

variable "redis_config" {
  type = object({
    appendonly                  = optional(string)
    maxmemory-policy            = optional(string)
    stop-writes-on-bgsave-error = optional(string)
    maxmemory-redis             = optional(number)
    maxmemory-samples           = optional(number)
  })
  default = null
}
data "ibm_is_vpc" "vpc" {
  name = var.vpc_name
}

resource "ibm_database" "db_redis" {
  count                        = var.redis_instance_info == null ? 0 : 1
  name                         = join("-", [var.environment_id, var.redis_instance_info.name])
  plan                         = var.redis_instance_info.plan
  location                     = var.region
  service                      = "databases-for-redis"
  version                      = var.redis_instance_info.version == "latest" ? null : var.redis_instance_info.version
  resource_group_id            = var.resource_group_id
  service_endpoints            = "private"
  key_protect_instance         = module.bivwak_kms.kms_instance_id
  key_protect_key              = lookup(module.bivwak_kms.keys, join("-", [var.environment_id, var.redis_instance_info.name, "key"]))
  tags                         = var.tags
  group {
    group_id = "member"

    memory {
      allocation_mb = var.redis_instance_info.members_memory_allocation_mb
    }

    disk {
      allocation_mb = var.redis_instance_info.members_disk_allocation_mb
    }
  }
  configuration                = var.redis_config == null ? null : jsonencode(local.redis_config)
  dynamic "allowlist" {
    for_each = data.ibm_is_vpc.vpc.cse_source_addresses.*.address
    content {
      address     = format("%s/32", allowlist.value)
      description = allowlist.value
    }
  }
}

data "ibm_database_connection" "db_redis_connection" {
    count = var.redis_instance_info == null ? 0 : 1
    endpoint_type = "private"
    deployment_id = ibm_database.db_redis[0].id
    user_id = ibm_database.db_redis[0].adminuser
    user_type = "user"
}

locals {
  kms_info = var.redis_instance_info == null ? null : {
    kms_instance_name   = join("-", [var.environment_id, var.redis_instance_info.name, "keyprotect"])
    source_service_name = "databases-for-redis"
    resource_group_id   = var.resource_group_id
    keys = {
      join("-", [var.environment_id, var.redis_instance_info.name, "key"]) = {
        standard_key = false
      }
    }
  }
  redis_config = var.redis_instance_info == null ? null : defaults(var.redis_config, {
      appendonly                  = "yes"
      maxmemory-policy            = "noeviction"
      stop-writes-on-bgsave-error = "yes"
      maxmemory-redis             = ceil(var.redis_instance_info.members_memory_allocation_mb * 0.8)
      maxmemory-samples           = 5

    })
}

module "bivwak_kms" {
  source   = "./remote_modules/kms"
  region   = var.region
  tags     = var.tags
  kms_info = local.kms_info
}
{
    "region": "eu-de",
    "vpc_name": "vpc2",
    "resource_group_id": "681ed5c0507740ad9226a7d87cabbbfa",
    "environment_id": "test123",
    "tags": [
        "environmentid:test123"
    ],
    "redis_instance_info": {
        "name" : "myredis-db",
        "plan": "standard",
        "version": "latest",
        "members_memory_allocation_mb": 6144,
        "members_disk_allocation_mb": 28672,
        "endpoint" : "private"
    },
    "redis_config": {
        "stop-writes-on-bgsave-error": "yes",
        "maxmemory-samples": 5
    }
}

Debug Output

Panic Output

Expected Behavior

It should work like in 1.50.0 even if i have to change the parameter name .... I can find in 1.51 release notes a change that should have caused this regression

Refactor(Cloud Databases): configuration uses cloud-databases-go-sdk (https://github.com/IBM-Cloud/terraform-provider-ibm/pull/4234)

Actual Behavior

With terraform ibmcloud provider 1.50.0, the configuration parameter name for max memory was maxmerory

Since terraform ibmcloud provider 1.51.0, terraform ask to change this parameter to fix it to maxmemory-redis as described in API documentation

Error using maxmemory with ibmcloud terraform provider => 1.51.0


β”‚ Error: 1 error occurred:
β”‚       * [ERROR] configuration contained invalid field(s): [maxmemory]
β”‚ 
β”‚ 
β”‚ 
β”‚   with ibm_database.db_redis[0],
β”‚   on main.tf line 5, in resource "ibm_database" "db_redis":
β”‚    5: resource "ibm_database" "db_redis" {
β”‚ 

Documentation about redis configuration parameter

Provider documentation : https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs/resources/database#configuration API Documentation : https://cloud.ibm.com/apidocs/cloud-databases-api/cloud-databases-api-v4#setdatabaseconfiguration-request

maxmemory-redis
integer
The maximum memory Redis should use, as bytes.

Possible values: value β‰₯ 0
maxmemory-policy
string
The policy with which Redis evicts keys when maximum memory is reached.

Allowable values: [volatile-lru,allkeys-lru,volatile-random,allkeys-random,volatile-ttl,noeviction]

appendonly
string
If set to yes this will enable AOF persistence.

Allowable values: [yes,no]

maxmemory-samples
integer
The maximum memory Redis should use, as bytes.

Possible values: value β‰₯ 0
stop-writes-on-bgsave-error
string
Whether or not to stop accepting writes when background persistence actions fail.

Allowable values: [yes,no]

Error using maxmemory-redis with ibmcloud terraform provider => 1.51.0

β”‚ Error: [ERROR] Error updating database configuration failed Unprocessable Entity
β”‚ {
β”‚     "StatusCode": 422,
β”‚     "Headers": {
β”‚         "Cache-Control": [
β”‚             "no-cache"
β”‚         ],
β”‚         "Cf-Cache-Status": [
β”‚             "DYNAMIC"
β”‚         ],
β”‚         "Cf-Ray": [
β”‚             "7ba2dcf1da84024b-CDG"
β”‚         ],
β”‚         "Content-Security-Policy": [
β”‚             "frame-ancestors *.bluemix.net *.compose.fastkit *.cloud.ibm.com cloud.ibm.com"
β”‚         ],
β”‚         "Content-Type": [
β”‚             "application/json; charset=utf-8"
β”‚         ],
β”‚         "Date": [
β”‚             "Wed, 19 Apr 2023 05:49:15 GMT"
β”‚         ],
β”‚         "Referrer-Policy": [
β”‚             "strict-origin-when-cross-origin"
β”‚         ],
β”‚         "Server": [
β”‚             "cloudflare"
β”‚         ],
β”‚         "Strict-Transport-Security": [
β”‚             "max-age=0; includeSubDomains"
β”‚         ],
β”‚         "X-Content-Type-Options": [
β”‚             "nosniff"
β”‚         ],
β”‚         "X-Download-Options": [
β”‚             "noopen"
β”‚         ],
β”‚         "X-Envoy-Upstream-Service-Time": [
β”‚             "1242"
β”‚         ],
β”‚         "X-Permitted-Cross-Domain-Policies": [
β”‚             "none"
β”‚         ],
β”‚         "X-Request-Id": [
β”‚             "5441ec02-03c3-4058-bd7d-be1a5cec1dcd"
β”‚         ],
β”‚         "X-Runtime": [
β”‚             "1.240053"
β”‚         ],
β”‚         "X-Xss-Protection": [
β”‚             "1; mode=block"
β”‚         ]
β”‚     },
β”‚     "Result": {
β”‚         "errors": {
β”‚             "configuration.maxmemory-redis": [
β”‚                 "not supported"
β”‚             ]
β”‚         }
β”‚     },
β”‚     "RawResult": null
β”‚ }
β”‚ 
β”‚ 
β”‚   with ibm_database.db_redis[0],
β”‚   on main.tf line 5, in resource "ibm_database" "db_redis":
β”‚    5: resource "ibm_database" "db_redis" {

Steps to Reproduce

  1. terraform init
  2. terraform apply -var-file redis.json -auto-approve

Important Factoids

References

alexhemard commented 1 year ago

@ifs-anthonylecarrer Thanks for reporting this issue. It appears our documentation and client SDK lists this parameter incorrectly as maxmemory-redis instead of maxmemory https://github.com/IBM/cloud-databases-go-sdk/blob/0addb2e7a3617770f607015235d776d62880ba1e/clouddatabasesv5/cloud_databases_v5.go#L2901-L2902

ifs-anthonylecarrer commented 1 year ago

hello @alexhemard

Using `maxmeroy, i have this issue :

β”‚ Error: 1 error occurred:
β”‚       * [ERROR] configuration contained invalid field(s): [maxmemory]
β”‚ 
β”‚ 
β”‚ 
β”‚   with ibm_database.db_redis[0],
β”‚   on main.tf line 5, in resource "ibm_database" "db_redis":
β”‚    5: resource "ibm_database" "db_redis" {

using maxmemory-redis, i have this issue :

β”‚ Error: [ERROR] Error updating database configuration failed Unprocessable Entity
β”‚ {
β”‚     "StatusCode": 422,
β”‚     "Headers": {
β”‚         "Cache-Control": [
β”‚             "no-cache"
β”‚         ],
β”‚         "Cf-Cache-Status": [
β”‚             "DYNAMIC"
β”‚         ],
β”‚         "Cf-Ray": [
β”‚             "7ba2dcf1da84024b-CDG"
β”‚         ],
β”‚         "Content-Security-Policy": [
β”‚             "frame-ancestors *.bluemix.net *.compose.fastkit *.cloud.ibm.com cloud.ibm.com"
β”‚         ],
β”‚         "Content-Type": [
β”‚             "application/json; charset=utf-8"
β”‚         ],
β”‚         "Date": [
β”‚             "Wed, 19 Apr 2023 05:49:15 GMT"
β”‚         ],
β”‚         "Referrer-Policy": [
β”‚             "strict-origin-when-cross-origin"
β”‚         ],
β”‚         "Server": [
β”‚             "cloudflare"
β”‚         ],
β”‚         "Strict-Transport-Security": [
β”‚             "max-age=0; includeSubDomains"
β”‚         ],
β”‚         "X-Content-Type-Options": [
β”‚             "nosniff"
β”‚         ],
β”‚         "X-Download-Options": [
β”‚             "noopen"
β”‚         ],
β”‚         "X-Envoy-Upstream-Service-Time": [
β”‚             "1242"
β”‚         ],
β”‚         "X-Permitted-Cross-Domain-Policies": [
β”‚             "none"
β”‚         ],
β”‚         "X-Request-Id": [
β”‚             "5441ec02-03c3-4058-bd7d-be1a5cec1dcd"
β”‚         ],
β”‚         "X-Runtime": [
β”‚             "1.240053"
β”‚         ],
β”‚         "X-Xss-Protection": [
β”‚             "1; mode=block"
β”‚         ]
β”‚     },
β”‚     "Result": {
β”‚         "errors": {
β”‚             "configuration.maxmemory-redis": [
β”‚                 "not supported"
β”‚             ]
β”‚         }
β”‚     },
β”‚     "RawResult": null
β”‚ }
β”‚ 
β”‚ 
β”‚   with ibm_database.db_redis[0],
β”‚   on main.tf line 5, in resource "ibm_database" "db_redis":
β”‚    5: resource "ibm_database" "db_redis" {

it seems the right parameter is maxmemory-redis but as soon as i try to override this parameter using redis configuration, the result is that the parameter is not supported. If i do not override redis configuration, it works using

 {
    "region": "eu-de",
    "vpc_name": "vpc2",
    "resource_group_id": "681ed5c0507740ad9226a7d87cabbbfa",
    "environment_id": "test123",
    "tags": [
        "environmentid:test123"
    ],
    "redis_instance_info": {
        "name" : "myredis-db",
        "plan": "standard",
        "version": "latest",
        "members_memory_allocation_mb": 6144,
        "members_disk_allocation_mb": 28672,
        "endpoint" : "private"
    }
}

instead of :

 {
    "region": "eu-de",
    "vpc_name": "vpc2",
    "resource_group_id": "681ed5c0507740ad9226a7d87cabbbfa",
    "environment_id": "test123",
    "tags": [
        "environmentid:test123"
    ],
    "redis_instance_info": {
        "name" : "myredis-db",
        "plan": "standard",
        "version": "latest",
        "members_memory_allocation_mb": 6144,
        "members_disk_allocation_mb": 28672,
        "endpoint" : "private"
    },
    "redis_config": {
        "stop-writes-on-bgsave-error": "yes",
        "maxmemory-samples": 5
    }
}
hkantare commented 1 year ago

@obai-1 Can you look into this

pa-jberanek commented 1 year ago

I've just hit this issue and can confirm the behaviour @ifs-anthonylecarrer has shown.