Skip to content

Commit

Permalink
Add version validation (IBM-Cloud#5791)
Browse files Browse the repository at this point in the history
Co-authored-by: Lorna-Kelly <[email protected]>
  • Loading branch information
lornakelly and Lorna-Kelly authored Nov 15, 2024
1 parent 89a24e6 commit f542550
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions ibm/service/database/resource_ibm_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func ResourceIBMDatabaseInstance() *schema.Resource {
resourceIBMDatabaseInstanceDiff,
validateGroupsDiff,
validateUsersDiff,
validateVersionDiff,
validateRemoteLeaderIDDiff),

Importer: &schema.ResourceImporter{},
Expand Down Expand Up @@ -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'.",
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/database.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit f542550

Please sign in to comment.