[Yandex Cloud documentation](../../../index.md) > [Yandex Cloud CDN](../../index.md) > [Step-by-step guides](../index.md) > Origin groups > Adding an origin group to a resource

# Adding an origin group to a resource

To add an [origin group](../../concepts/origins.md#groups) to a [resource](../../concepts/resource.md), under **Content**, select the appropriate **Origin group** when [creating](../resources/create-resource.md) or [updating the resource settings](../resources/configure-basics.md).

## Adding an origin group when creating a resource {#connect-while-creating}

{% list tabs group=instructions %}

- Management console {#console}
  
  1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a resource.

  1. Navigate to **Cloud CDN**.

  1. Click **Create resource**.

  1. Under **Content**, select `From origin group` in the **Content query** field.

  1. Select an origin group.

  1. Specify the other resource settings. To learn more, see [Creating a resource](../resources/create-resource.md).

  1. Click **Create**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the CLI command to create a resource:

     ```
     yc cdn resource create --help
     ```
  
  1. Get a list of all origin groups in the default folder:

     ```
     yc cdn origin-group list --format yaml
     ```

     Result:

     ```
     - id: "90209"
       folder_id: b1g86q4m5vej********
       name: test-group-1
       use_next: true
       origins:
       - id: "561547"
         origin_group_id: "90209"
         source: www.example2.com
         enabled: true
         backup: true
       - id: "561546"
         origin_group_id: "90209"
         source: www.example1.com
         enabled: true
     - id: "90208"
       folder_id: b1g86q4m5vej********
       name: test-group
       use_next: true
       origins:
       - id: "561545"
         origin_group_id: "90208"
         source: www.a2.com
         enabled: true
         backup: true
       - id: "561544"
         origin_group_id: "90208"
         source: www.a1.com
         enabled: true
     ```
  
  1. Create a resource with the origin group added to it:

     ```
     yc cdn resource create --cname <resource_domain_name> \
       --origin-group-id <origin_group_ID> \
       --origin-protocol https
     ```

     Where:

     * `--origin-group-id`: Origin group ID.
     * `--origin-protocol`: Protocol for origins.

     Result:

     ```
     id: bc855oumelrq********
     folder_id: b1g86q4m5vej********
     cname: res1.example.com
     created_at: "2022-01-15T15:13:42.827643Z"
     updated_at: "2022-01-15T15:13:42.827671Z"
     active: true
     options:
       edge_cache_settings:
         enabled: true
         default_value: "345600"
       cache_http_headers:
         value:
         - accept-ranges
         - cache-control
         - connection
         - content-encoding
         - content-length
         - content-type
         - date
         - etag
         - expires
         - keep-alive
         - last-modified
         - server
         - vary
       stale:
         enabled: true
         value:
         - error
         - updating
       allowed_http_methods:
         value:
         - GET
         - POST
         - HEAD
         - OPTIONS
     origin_group_id: "90208"
     origin_group_name: test-group-22
     origin_protocol: HTTPS
     ssl_certificate:
       type: DONT_USE
       status: READY
     ```

     For more information about the `yc cdn resource create` command, see the [CLI reference](../../../cli/cli-ref/cdn/cli-ref/resource/create.md).

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  1. Describe the `yandex_cdn_resource` properties in the configuration file:

     Here is an example of the configuration file structure:

     ```hcl
     resource "yandex_cdn_resource" "my_resource" {
       cname           = "<resource_domain_name>"
       active          = true
       origin_protocol = "https"
       origin_group_id = <origin_group_ID>
     }
     ```

     For more information about the resources you can create with Terraform, see [this provider guide](../../../terraform/resources/cdn_origin_group.md).

  1. Make sure the settings are correct.

     1. In the command line, navigate to the directory that contains the current Terraform configuration files defining the infrastructure.
     1. Run this command:
     
        ```bash
        terraform validate
        ```
     
        Terraform will show any errors found in your configuration files.

  1. Create an origin group.

     1. Run this command to view the planned changes:
     
        ```bash
        terraform plan
        ```
     
        If you described the configuration correctly, the terminal will display a list of the resources to update and their parameters. This is a verification step that does not apply changes to your resources.
     
     1. If everything looks correct, apply the changes:
        1. Run this command:
     
           ```bash
           terraform apply
           ```
     
        1. Confirm updating the resources.
        1. Wait for the operation to complete.

- API {#api}

  To add an origin group when creating a resource, use the [create](../../api-ref/Resource/create.md) REST API method for the [Resource](../../api-ref/Resource/index.md) resource or the [ResourceService/Create](../../api-ref/grpc/Resource/create.md) gRPC API call.

{% endlist %}

## Adding an origin group when editing the resource settings {#connect-while-changing}

{% list tabs group=instructions %}

- Management console {#console}
  
  1. In the [management console](https://console.yandex.cloud), select the folder where your resource is located.

  1. Navigate to **Cloud CDN**.

  1. Click the resource name.

  1. In the top-right corner, click ![image](../../../_assets/console-icons/pencil.svg) **Edit**.

  1. Select an origin group.

  1. Enter the other resource settings if needed. To learn more, see [Updating the basic settings of a resource](../resources/configure-basics.md). 

  1. Click **Save**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. View the description of the CLI command for updating a resource:

     ```
     yc cdn resource update --help
     ```

  1. Get a list of all resources in the default folder:

     ```
     yc cdn resource list --format yaml
     ```

     Result:

     ```
     - id: bc82xll34xuc********
       folder_id: b1g86q4m5vej********
       cname: res1.example.com
       created_at: "2022-01-21T08:17:48.850086Z"
       updated_at: "2022-01-21T08:17:48.850125Z"
       active: true
       options:
         edge_cache_settings:
           enabled: true
           default_value: "345600"
         cache_http_headers:
           value:
           - accept-ranges
           - cache-control
           - connection
           - content-encoding
           - content-length
           - content-type
           - date
           - etag
           - expires
           - keep-alive
           - last-modified
           - server
           - vary
         stale:
           enabled: true
           value:
           - error
           - updating
         allowed_http_methods:
           value:
           - GET
           - POST
           - HEAD
           - OPTIONS
       origin_group_id: "90208"
       origin_group_name: test-group
       origin_protocol: HTTPS
       ssl_certificate:
         type: DONT_USE
         status: READY
     ```
  
  1. Get a list of all origin groups in the default folder and select the relevant group's `ID`:

     ```
     yc cdn origin-group list --format yaml
     ```

     Result:

     ```
     - id: "90209"
       folder_id: b1g86q4m5vej********
       name: test-group-1
       use_next: true
       origins:
       - id: "561547"
         origin_group_id: "90209"
         source: www.example2.com
         enabled: true
         backup: true
       - id: "561546"
         origin_group_id: "90209"
         source: www.example1.com
         enabled: true
     - id: "90208"
       folder_id: b1g86q4m5vej********
       name: test-group
       use_next: true
       origins:
       - id: "561545"
         origin_group_id: "90208"
         source: www.a2.com
         enabled: true
         backup: true
       - id: "561544"
         origin_group_id: "90208"
         source: www.a1.com
         enabled: true
     ```

  1. Update the resource settings by specifying the ID of the origin group:

     ```
     yc cdn resource update \
       --id <resource_ID> \
       --origin-group-id <origin_group_ID>
     ```

     Result:

     ```
     id: bc8krsk72icw********
     folder_id: b1g86q4m5vej********
     cname: res2.example.com
     created_at: "2022-01-15T15:29:19.103653Z"
     updated_at: "2022-01-15T15:33:22.819916Z"
     active: true
     options:
       edge_cache_settings:
         enabled: true
         default_value: "345600"
       cache_http_headers:
         value:
         - accept-ranges
         - cache-control
         - connection
         - content-encoding
         - content-length
         - content-type
         - date
         - etag
         - expires
         - keep-alive
         - last-modified
         - server
         - vary
       stale:
         enabled: true
         value:
         - error
         - updating
       allowed_http_methods:
         value:
         - GET
         - POST
         - HEAD
         - OPTIONS
     origin_group_id: "90209"
     origin_group_name: test-group-1
     origin_protocol: HTTPS
     ssl_certificate:
       type: DONT_USE
       status: READY
     ```

     For more information about the `yc cdn resource update` command, see the [CLI reference](../../../cli/cli-ref/cdn/cli-ref/resource/update.md).

- API {#api}

  To add an origin group when editing the resource settings, use the [update](../../api-ref/Resource/update.md) REST API method for the [Resource](../../api-ref/Resource/index.md) resource or the [ResourceService/Update](../../api-ref/grpc/Resource/update.md) gRPC API call.

{% endlist %}

It may take up to 15 minutes for the new settings of the existing resource to apply to the CDN servers. After that, we recommend [purging the resource cache](../resources/purge-cache.md).