Creating a resource
To create a resource:
-
In the management console, select the folder where you want to create a resource.
-
Select Cloud CDN.
-
If you don't have any CDN resources, click Activate provider. A connection is established automatically.
-
Click Create resource.
-
Under Content, select Content query
From one origin
orFrom origin group
:-
When requesting content
From one origin
, select an Origin type:Server
,Bucket
, orL7 load balancer
. Specify an origin. For more information about types, see Origins and origin groups. -
When requesting content from an
Origin group
, select an origin group or create a new one:- Click Create new.
- Enter a Group name.
- Configure Origins:
- Specify the Origin type:
Server
,Bucket
, orL7 load balancer
. For more information about types, see Origins and origin groups. - Specify an origin.
- Select the Priority:
Active
orBackup
. For more information about priorities, see Origin groups.
- Specify the Origin type:
- Add other origins if needed.
- Click Create. In the Origin group field, you will see the name of the created group.
For more information, see Origins and origin groups.
-
-
Under Domain names for content distribution, enter the Domain name. You can add multiple Domain names. Names containing characters other than ASCII (for example, Сyrillic) and Punycode are supported. The first name is considered the primary domain name.
Warning
After you create a resource, you can't change the primary domain name.
In the settings of your DNS hosting, create CNAME records for the specified domain names using the value displayed at the bottom of the Domain names for content distribution section. For more information, see Domain names for content distribution.
-
In the Advanced section:
- Select Origin request protocol.
- Select a client redirect method:
Don't use
,HTTP to HTTPS
, orHTTPS to HTTP
. - Enable or disable End-user access to content.
- If you selected the
HTTP
protocol, under Certificate type, selectDon't use
. Otherwise, selectLet's Encrypt®
orYour certificate
. For more information, see Configuring TLS certificates for HTTPS connections between clients and the CDN. - Select a Host header value:
Primary domain name
,Forward
, or selectCustom
and input the Header value. For more information, see Host header in CDN server requests to origins.
-
Click Create.
If you don't have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
If it's your first time creating a resource, start by connecting to the provider:
yc cdn provider activate --type gcore
-
View a description of the CLI create resource command:
yc cdn resource create --help
-
Get a list of origin groups in the folder:
yc cdn origin-group list --format yaml
Result:
- id: "90209" folder_id: somefolder7p3l5eobbd 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: b1g86q4m5vej8lkljme5 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
-
Create a resource:
yc cdn resource create <resource domain name> \ --origin-group-id <origin group ID> \ --origin-protocol <protocol for origins>
- Instead of the
--origin-group-id
, you can specify the origin domain name using the--origin-custom-source
flag. - Possible
--origin-protocol
values areHTTP
,HTTPS
, andMATCH
(same as the client's).
For more information about the
yc cdn resource create
command, see the CLI reference. - Instead of the
Make sure the CDN provider is activated before you start using CDN resources. You can activate it in the management console or using the YC CLI command:
yc cdn provider activate --folder-id <folder ID> --type gcore
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the configuration file, describe the parameters of the CDN resource to create:
cname
: The primary domain name used for content distribution. Required parameter.active
: A flag that indicates if content is available to end users.True
: Content from the CDN is available to clients. Optional parameter, defaults toTrue
.origin_protocol
: Origin protocol. Optional parameter, defaults tohttp
.secondary_hostnames
: Additional domain names. Optional.origin_group_id
: ID of the origin group. Required parameter. Use the ID from the description of the origin group in theyandex_cdn_origin_group
resource.
Example configuration file structure:
terraform { required_providers { yandex = { source = "yandex-cloud/yandex" version = "0.69.0" } } } provider "yandex" { token = "<OAuth>" cloud_id = "<cloud ID>" folder_id = "<folder ID>" zone = "<availability zone>" } resource "yandex_cdn_resource" "my_resource" { cname = "cdn1.yandex-example.ru" active = false origin_protocol = "https" secondary_hostnames = ["cdn-example-1.yandex.ru", "cdn-example-2.yandex.ru"] origin_group_id = yandex_cdn_origin_group.my_group.id }
For more information about
yandex_cdn_resource
parameters in Terraform, see the provider documentation. -
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If there are errors in the configuration, Terraform points them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the changes to the CDN resource in the management console or using the CLI:
yc cdn resource list
It takes approximately 15 minutes to create a resource.
Examples
Create a resource with HTTP:
yc cdn resource create testexample.com \
--origin-group-id 90209 \
--origin-protocol HTTP
Result:
id: someidkfjqjfl325fw
...
cname: testexample.com
active: true
...
origin_group_id: "90209"
origin_group_name: test-group-1
origin_protocol: HTTP
ssl_certificate:
type: DONT_USE
status: READY