def generate_secret_file(file_path, pattern, service, environment, clients):
  """
  Generate a parameter files with it's secrets encrypted in KMS
  Args:
      file_path (string): Path to the parameter file to be encrypted
      pattern (string): Pattern to do fuzzy string matching
      service (string): Service to use KMS key to encrypt file
      environment (string): Environment to encrypt values
      clients (dict): KMS AWS client that has been instantiated
  Returns:
      None
  Raises:
    IOError: If the file does not exist
  """
  changed = False
  with open(file_path) as json_file:
    data = json.load(json_file, object_pairs_hook=OrderedDict)
    try:
      for key, value in data["params"][environment].items():
        if pattern in key:
          if "aws:kms:decrypt" in value:
            print("Found match, key {} but value is encrypted already; skipping...".format(key))
          else:
            print("Found match, encrypting key {}".format(key))
            encrypted_password = ef_utils.kms_encrypt(clients['kms'], service, environment, value)
            data["params"][environment][key] = format_secret(encrypted_password)
            changed = True
    except KeyError:
      ef_utils.fail("Error env: {} does not exist in parameters file".format(environment))

  if changed:
    with open(file_path, "w") as encrypted_file:
      json.dump(data, encrypted_file, indent=2, separators=(',', ': '))
      # Writing new line here so it conforms to WG14 N1256 5.1.1.1 (so github doesn't complain)
      encrypted_file.write("\n")