diff --git a/ibm/service/database/resource_ibm_database.go b/ibm/service/database/resource_ibm_database.go index a0d2ab72a0..175899fecb 100644 --- a/ibm/service/database/resource_ibm_database.go +++ b/ibm/service/database/resource_ibm_database.go @@ -141,6 +141,7 @@ func ResourceIBMDatabaseInstance() *schema.Resource { resourceIBMDatabaseInstanceDiff, validateGroupsDiff, validateUsersDiff, + validateVersionDiff, validateRemoteLeaderIDDiff), Importer: &schema.ResourceImporter{}, @@ -241,11 +242,11 @@ func ResourceIBMDatabaseInstance() *schema.Resource { Description: "The configuration schema in JSON format", }, "version": { - Description: "The database version to provision if specified", - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Description: "The database version to provision if specified", + Type: schema.TypeString, + Optional: true, + Computed: true, + DiffSuppressFunc: flex.ApplyOnce, }, "service_endpoints": { Description: "Types of the service endpoints. Possible values are 'public', 'private', 'public-and-private'.", @@ -2956,6 +2957,16 @@ func getCpuEnforcementRatios(service string, plan string, hostFlavor string, met return nil, 0, 0 } +func validateVersionDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) (err error) { + version, configVersion := diff.GetChange("version") + + if version != configVersion { + return fmt.Errorf("[ERROR] The version in your configuration file (%s) does not match the version of your remote instance (%s). Make sure that you have the same version in your configuration as the version on the remote instance. Learn more about the versioning policy here: https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-versioning-policy ", configVersion, version) + } + + return nil +} + func validateUsersDiff(_ context.Context, diff *schema.ResourceDiff, meta interface{}) (err error) { service := diff.Get("service").(string) diff --git a/website/docs/r/database.html.markdown b/website/docs/r/database.html.markdown index f72636b3f1..ae9bd98c39 100644 --- a/website/docs/r/database.html.markdown +++ b/website/docs/r/database.html.markdown @@ -686,7 +686,7 @@ Review the argument reference that you can specify for your resource. - `service` - (Required, Forces new resource, String) The type of Cloud Databases that you want to create. Only the following services are currently accepted: `databases-for-etcd`, `databases-for-postgresql`, `databases-for-redis`, `databases-for-elasticsearch`, `messages-for-rabbitmq`,`databases-for-mongodb`,`databases-for-mysql`, and `databases-for-enterprisedb`. - `service_endpoints` - (Required, String) Specify whether you want to enable the public, private, or both service endpoints. Supported values are `public`, `private`, or `public-and-private`. - `tags` (Optional, Array of Strings) A list of tags that you want to add to your instance. -- `version` - (Optional, Forces new resource, String) The version of the database to be provisioned. If omitted, the database is created with the most recent major and minor version. +- `version` - (Optional, String) The version of the database to be provisioned. If omitted, the database is created with the most recent major and minor version. For more information, see our [versioning policy](https://cloud.ibm.com/docs/cloud-databases?topic=cloud-databases-versioning-policy). - `deletion_protection` - (Optional, Boolean) If the DB instance should have deletion protection within terraform enabled. This is not a property of the resource and does not prevent deletion outside of terraform. The database can't be deleted by terraform when this value is set to `true`. The default is `false`. - `users` - (Optional, List of Objects) A list of users that you want to create on the database. Multiple blocks are allowed.