> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-solutions-factory/use-hsf/template-library/setup-custom-htl.md).

# Using Your Own SCM for Custom Harness Template Library

Custom Harness Template Library is a point-in-time mirror of HTL that your organization controls. You can copy templates from HTL into Custom HTL and modify them there. If Harness releases an update to a template in HTL, it will not overwrite your customizations in Custom HTL: you choose when to adopt Harness updates. The Custom Harness Template Library is included with the deployment of your Harness Solutions Factory.

{% hint style="info" %}
**CUSTOM TEMPLATE LIBRARY**

If you do not have a Custom Harness Template Library repo in the root of your Harness Platform Management organization, then proceed to the documentation on [How to upgrade your Solutions Factory implementation](/harness-solutions-factory/new-to-hsf/hsf-upgrade.md)

When configuring the Solutions Factory implementation for the first time, the custom-harness-template-library will import the original source repository directly into the repo. The source for this repo can be found in [Github here](https://github.com/harness-solutions-factory/custom-harness-template-library). Subsequent updates to the Solutions Factory installation will not synchronize any changes in this repository.
{% endhint %}

### Leverage your own Source Code Manager <a href="#leverage-your-own-source-code-manager" id="leverage-your-own-source-code-manager"></a>

In order to leverage your own Source Code Manager, you will be required to configure several pre-requisites prior to utilizing any templates stored in that repository.

***Note**: The steps detailed here will assume that you have permissions to create and manage repositories within your Source Code Manager and are able to create and configure the necessary connectors*

#### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* A new or existing Source Code Manager (SCM) connector with appropriate permissions

  ***Note**: The reuse of an existing connector or the Central Build Farm connector is possible as this does not require a dedicated connector. The Connector must live within the scope of either the Account or the Organization. While possible to support a connector at the project level, we advise against it in the event that the connections are required across any of the projects within the Harness Platform Management organization*
* The contents of the Custom Harness Template Library repository pushed into the new repository within your SCM

  ***Note**: While not required, we highly advise setting the initial baseline for your custom repository based on the version provided within the Harness Platform Management repository.*
* A delegate with access to your SCM

  ***Note**: This is only required for customers hosting their SCM internal to their networks*

#### Modify standard variables <a href="#modify-standard-variables" id="modify-standard-variables"></a>

* Update the Account-level variable `Custom Template Library Connector` to point to the Connector from which your custom repository will come. The connector should be prefixed with `account.` or `org.` depending on the scope
* Update the Account-level variable `Custom Template Library Repo` to contain the scoped path to your repository based on your connector setup. ***Note**: If you connector points to the root of your SCM, such as <https://github.com>, then be sure to provide the full repository path excluding the Connector root details.*

### Create a new template <a href="#create-a-new-template" id="create-a-new-template"></a>

A Terraform scaffold is included within the baseline repository (`scaffolds/terraform`). This scaffold includes everything required to begin building out new templates for use with the Solutions Factory.

[Learn more about creating new templates](/harness-solutions-factory/use-hsf/configurations/developer-env-setup.md)

### Update Harness-provided samples and baseline templates <a href="#update-harness-provided-samples-and-baseline-templates" id="update-harness-provided-samples-and-baseline-templates"></a>

Often, the provided samples and baseline templates do not cover 100% of your use cases and require adjustment. In order to customize the Templates, follow the below steps.

1. In your CTL repository, open the `.harness/catalog_template.yaml` file

   ***Note**: This file contains the details for the IDP workflow and will need to be adjusted for your SCM repository*

   a. In the yaml, find the property `template_library_connector` and edit the variable. By default, the value should be adjusted from `<+variable.account.solutions_factory_template_library_connector>` to `<+variable.account.custom_template_library_connector>`

   b. In the yaml, find the property `template_library_repo` and edit the variable. By default, the value should be adjusted from `<+variable.account.solutions_factory_template_library_repo>` to `<+variable.account.custom_template_library_repo>`

   c. **STOP** If you plan first test the template using a feature branch and not using the `main` branch, then you will need to modify the value for the property `template_library_branch` to point to your specific branch. ***Note**: Make sure to follow the steps in the section titled `Production Readiness` to ensure that all adjustments are ready to be merged into the main branch.*
2. Optionally, the `metadata.name` can be modified to support registering a new copy without first having to replace the original version.
3. Commit and push your changes back to your SCM repository.

### Test and update IDP with your new workflow <a href="#test-and-update-idp-with-your-new-workflow" id="test-and-update-idp-with-your-new-workflow"></a>

***STOP**: It is important to note that two templates of the same `metadata.name` cannot be registered at the same time to the same IDP environment. To resolve this, you will need to first unregister the current version of workflow within IDP.*

This step is only required when under the following conditions

* Replacing the Harness provided version
* Modifying the source repository branch

When replacing or modifying a workflow branch, you will need to `Unregister` the template from your IDP environment. If you modified the `metadata.name` to a new value, then skip to `Step 8`

1. Navigate to Internal Developer Portal (IDP) module within your Harness account
2. In the left hand navigation, select `Catalog` and change the Kind dropdown to `Template`
3. Find the workflow that you need to replace and open the template within IDP. ***Note**: Click the hyperlink for the template name. Do not click the edit buttons*
4. Click the three dots in the upper right-hand corner
5. Choose `Unregister Entity`
6. In the pop-up window, choose `Unregister Location`
7. Wait for the unregistration to complete
8. In the left hand navigation, select `Register`
9. Copy the full repository URL to your new `catalog_template.yaml` file. ***Note**: This should be the entire HTTPS path.*
10. Paste the URL in the field and click Analyze
11. Click `Import`. ***Note**: If a matching template `metadata.name` is registered or the original template had not been removed, the button will say `Refresh`. If this is the case, then **STOP** and retry the steps from `Step 2` in this list*
12. After the import completes, you can open the link to the `template:<template-name>` provided.
13. Verify that the `View Source` is pointed to the correct repository and branch.
14. Click `Launch Template` to test the build

### Production readiness for custom templates <a href="#production-readiness-for-custom-templates" id="production-readiness-for-custom-templates"></a>

{% hint style="warning" %}
**TEMPLATE CHANGES**

***STOP**: Review the below prior generating a Pull-Request and finalizing your template changes*

As part of the testing of the new template, it is entirely likely that you created these changes on a non-default branch. Prior to making the final edits, change any `branch` or `metadata.name` changes you have made to the template.
{% endhint %}
