> ## Documentation Index
> Fetch the complete documentation index at: https://gcore-doc-1046.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a CDN rule via Terraform

If a CDN resource was created via Terraform, you can [add a rule](/cdn/cdn-resource-options/rules-for-particular-files/create-a-rule-manually-or-from-a-template-to-configure-settings-for-particular-files) to it via Terraform. To do this, use the following instructions.

1\. Open the *main.tf* file.

2\. The file is supposed to contain the code for the creation of your CDN resource. If it is missing, add the code according to the [Create a new CDN resource](/cdn/terraform/manage-a-cdn-resource-with-terraform#create-a-new-cdn-resource) section.

Don't worry, Terraform won't duplicate a resource. Terraform requires the code used to create a resource only to identify a resource that should be changed.

3\. At this step, you will add the necessary strings for creating a rule to the configuration file.

Add the code below to a new string. Replace the hints in the brackets with your values and remove the brackets.

```
resource "gcore_cdn_rule" "make up Terraform name for the rule; you can use any name, it will be linked to the rule inside the Terraform system" {   
  resource_id = gcore_cdn_resource.Terraform name of the CDN resource for which you are adding the rule.id   
  name = "make up a name for the rule that will be displayed in the Gcore Customer Portal"   
  rule = "specify path to the files for which you are adding the rule; the path should always start with "^/" or "/""   
  rule_type   = 0 
```

4\. If you want to add options to the rule, paste the code below. Replace the hints in the brackets with your values and remove the brackets.

```
options {   
code to configure the necessary options; for set-up guides, refer to the Terraform documentation for the Gcore provider, an example of configuration can be found in the "Configure CDN resource options" section   
} 
```

If you don't need options, do not add the *options* code segment.

5\. Be aware to add a curly bracket to a new string below.

```
} 
```

Here is an example of a configuration file. Let's say you want to add a rule with the following characteristics:

* example\_rule — the name of the rule for Terraform
* cdn\_example\_com — the name of the CDN resource in Terraform
* PNG images — the name of the rule from the Gcore Customer Portal
* /folder/images/\*.png — the path to the files
* The "WebP Compression" option with a final quality of 66 is required

The final code in the configuration file will look as follows:

<Frame>
  <img src="https://mintcdn.com/gcore-doc-1046/VOq4jXcdwrEXEzq8/images/docs/cdn/grafana-terraform/manage-a-cdn-resource-with-terraform/image_1712-2.png?fit=max&auto=format&n=VOq4jXcdwrEXEzq8&q=85&s=72972326077cfb72eb16f02f617d99aa" alt="configuration file" width="1014" height="894" data-path="images/docs/cdn/grafana-terraform/manage-a-cdn-resource-with-terraform/image_1712-2.png" />
</Frame>

6\. Save the changes in the configuration file.

7\. Access the "Terraform" folder in the command-line interface unless you are already in it, and run the `terraform plan` command — it will show what changes Terraform is going to make. If the code contains an error, the output will give a brief description of it.

8\. Run the `terraform apply` command — it will make changes to the CDN. Terraform will ask you to confirm the action — enter "yes".
