// Module included in the following assemblies:
//
// configuring/assembly-external-config.adoc

[id='proc-loading-config-from-file-{context}']
= Loading configuration values from a file within a directory

[role="_abstract"]
Use the `FileConfigProvider` to provide configuration properties from a file within a directory.
Files can be config maps or secrets.

In this procedure, a file provides configuration properties for a connector.
A database name and password are specified as properties of a secret.
The secret is mounted to the Kafka Connect pod as a volume. 
Volumes are mounted on the path `/opt/kafka/external-configuration/<volume-name>`.

.Prerequisites

* A Kafka cluster is running.
* The Cluster Operator is running.
* You have a secret containing the connector configuration.

.Example secret with database properties
[source,yaml,subs=attributes+]
----
apiVersion: v1
kind: Secret
metadata:
  name: mysecret
type: Opaque
stringData:
  connector.properties: |- # <1>
    dbUsername: my-username # <2>
    dbPassword: my-password
----
<1> The connector configuration in properties file format.
<2> Database username and password properties used in the configuration.

.Procedure

. Configure the `KafkaConnect` resource.
+
--
* Enable the `FileConfigProvider`
* Specify the file using the `externalConfiguration` property.
--
+
.Example Kafka Connect configuration to use an external property file
[source,yaml,subs="attributes+"]
----
apiVersion: {KafkaConnectApiVersion}
kind: KafkaConnect
metadata:
  name: my-connect
spec:
  # ...
  config:
    config.providers: file # <1>
    config.providers.file.class: org.apache.kafka.common.config.provider.FileConfigProvider # <2>
  #...
  externalConfiguration:
    volumes:
      - name: connector-config # <3>
        secret:
          secretName: mysecret # <4>
----
<1> The alias for the configuration provider is used to define other configuration parameters.
<2> `FileConfigProvider` provides values from properties files.
The parameter uses the alias from `config.providers`, taking the form `config.providers.${alias}.class`.
<3> The name of the volume containing the secret.
<4> The name of the secret.

. Create or update the resource to enable the provider.
+
[source,shell,subs=+quotes]
----
kubectl apply -f <kafka_connect_configuration_file>
----

. Reference the file properties in the connector configuration as placeholders.
+
.Example connector configuration referencing the file
[source,yaml,subs="attributes+"]
----
apiVersion: {KafkaConnectorApiVersion}
kind: KafkaConnector
metadata:
  name: my-source-connector
  labels:
    strimzi.io/cluster: my-connect-cluster
spec:
  class: io.debezium.connector.mysql.MySqlConnector
  tasksMax: 2
  config:
    database.hostname: 192.168.99.1
    database.port: "3306"
    database.user: "${file:/opt/kafka/external-configuration/connector-config/mysecret:dbUsername}"
    database.password: "${file:/opt/kafka/external-configuration/connector-config/mysecret:dbPassword}"
    database.server.id: "184054"
    #...
----
+
The placeholder structure is `file:<path_and_file_name>:<property>`.
`FileConfigProvider` reads and extracts the database username and password property values from the mounted secret.