API
The Gcore Customer Portal is being updated. Screenshots may not show the current version.
CDN
CDN
BillingCDN resources overviewOrigin groupPurgePrefetchReports
API
Chosen image
Home/CDN

Add an SSL certificate to a CDN resource via Terraform

If a CDN resource was created via Terraform, you can add an SSL certificate via Terraform. To do this, use the following steps. 

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 section.  

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

3. At this step, you will add the necessary strings for issuing an SSL certificate. 

Add the code below before the following string: resource "gcore_cdn_resource" "(name of your resource in Terraform)" {. Replace the hints in the brackets with your values and remove the brackets. 

resource "gcore_cdn_sslcert" "make up Terraform name for your certificate; you can use any name, it will be linked to the certificate inside the Terraform system" { name = "make up a certificate name that will be displayed in the Gcore Customer Portal; it should not match the names of other SSL certificates in the same account" cert = "specify a public key of your certificate, including the BEGIN CERTIFICATE----- and-----END CERTIFICATE---- strings" private_key ="specify a private key of your SSL certificate, including the -----BEGIN RSA PRIVATE KEY----- and -----END RSA PRIVATE KEY----- string" }

4. Add the code below after the secondary_hostnames string, if any (if not, after origin_protocol). Replace the hints in the brackets with your values and remove the brackets. 

ssl_enabled = true  ssl_data = gcore_cdn_sslcert.Terraform name of the certificate.id 

Here is an example of adding a certificate. Let's suppose your values are as follows: 

  • example_cert — the name of the certificate that will be displayed in Terraform, 
  • example_certificate — the name of the certificate that will be displayed in the Gcore Customer Portal, 
  • -----BEGIN CERTIFICATE-----MIIDkjCCAnqgAwIBAgIgTfqoZeTGCEvm...T7XH8IlQY0SGq2FSZKJAlrfX+UOpIMWQcOwcuDB97DXl5Bjs+QEXO203GW0C-----END CERTIFICATE----- — the public key of the certificate,
  • -----BEGIN RSA PRIVATE KEY-----MIIEpAIBAAKCAQEAzzj54zBOWxBIJRFMBtG...xyf2T9RZYRpIVbkatg977nXryEZC8Sp8U76c3Oww==-----END RSA PRIVATE KEY----- — the private key of the certificate.

To add such a certificate, you have inserted the necessary strings into the configuration file. The file is supposed to look as follows:

configuration file

5. Save the changes in the configuration file. 

6. 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.  

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

Was this article helpful?

Not a Gcore user yet?

Learn more about our next-gen CDN

Go to the product page