protected static ProgressEvent validateResourceModel()

in key/src/main/java/software/amazon/kms/key/BaseHandlerStd.java [118:151]


    protected static ProgressEvent<ResourceModel, CallbackContext> validateResourceModel(
        final ProgressEvent<ResourceModel, CallbackContext> progress,
        final ResourceModel previousModel,
        final ResourceModel model) {
        // If the key is asymmetric, we cannot enable key rotation
        if (!Objects
            .equals(model.getKeySpec(), KeySpec.SYMMETRIC_DEFAULT.toString())
            && model.getEnableKeyRotation()) {
            throw new CfnInvalidRequestException(
                "You cannot set the EnableKeyRotation property to true on asymmetric keys.");
        }

        // Update specific validation
        if (previousModel != null) {
            // If the key is disabled, and will continue to be, we cannot modify the
            // EnableKeyRotation property
            if (!previousModel.getEnabled() && !model.getEnabled()
                && previousModel.getEnableKeyRotation() != model.getEnableKeyRotation()) {
                throw new CfnInvalidRequestException("You cannot change the EnableKeyRotation "
                    + "property while the Enabled property is false.");
            }

            // If the key usage or spec or multi-region value changes,
            // we need to trigger re-creation
            if (!Objects.equals(previousModel.getKeyUsage(), model.getKeyUsage())
                || !Objects.equals(previousModel.getKeySpec(), model.getKeySpec())
                || !Objects.equals(previousModel.getMultiRegion(), model.getMultiRegion())) {
                throw new CfnNotUpdatableException(ResourceModel.TYPE_NAME,
                    Objects.toString(model.getKeyId()));
            }
        }

        return progress;
    }