Skip to content

CDNVideo Terraform Provider

Introduction

What is Terraform?

Terraform is a tool for creating, modifying, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

Key features of Terraform:

  • Declarative configuration language
  • Planning changes before applying
  • Resource dependency management
  • Support for multiple cloud providers

What is a Terraform provider?

A Terraform provider is a plugin that allows Terraform to interact with the APIs of various services and platforms. The provider defines a set of resources and data sources that can be used in Terraform configuration.

Why do you need the CDNVideo Terraform Provider?

The CDNVideo Terraform Provider allows you to manage caching resources using Terraform. This provides the following benefits:

  1. Automation: manage CDN resources as code (Infrastructure as Code).
  2. Consistency: ensure uniform state of infrastructure.
  3. Versioning: track changes in CDN configuration.
  4. Integration: easily incorporate resource management into existing CI/CD processes.

Getting Started with CDNVideo Terraform Provider

Requirements

  • Terraform version 1.8 or higher
  • CDNVideo account

Installation

  1. Install Terraform by downloading it from the official website.

  2. (Optional) Configuring a Terraform mirror

If you don't have access to the official Terraform registry (e.g., due to VPN restrictions), you can set up a mirror. To do this, create or edit the ~/.terraformrc file (for Linux/macOS) or %APPDATA%\terraform.rc (for Windows):

$ touch ~/.terraformrc  # For Linux/macOS

Add the following configuration to the file:

provider_installation {
  network_mirror {
    url = "https://terraform-mirror.yandexcloud.net/"
    include = ["registry.terraform.io/*/*"]
  }
  direct {
    exclude = ["registry.terraform.io/*/*"]
  }
}

This configuration tells Terraform to use the Yandex Cloud mirror to download providers, which can be useful if direct access to the official Terraform registry is difficult.

  1. Create a main.tf file in your working directory with the following content:
terraform {
  required_version = ">= 1.8"
  required_providers {
    cdnvideo = {
      source  = "opensource-cdnvideo/cdnvideo"
      version = "1.0.1"
    }
  }
}
  1. Run the command to initialize the Terraform working directory:
terraform init

If you've configured a mirror, Terraform will use it to download the CDNVideo provider.

Provider Configuration

Add the following configuration to your Terraform file:

provider "cdnvideo" {
  account_name = "your_account_name"
  username     = "your_email@example.com"
  password     = "your_password"
}

It's recommended to use environment variables or a secure secret management solution instead of storing sensitive information in plain text.

Basic Usage

After configuring the provider, you can start defining CDNVideo resources in your Terraform configuration.

Example:

resource "cdnvideo_resource" "example" {
  name   = "testname"
  origin = {
    servers = {
      "google.com" = {
        port = 443
      }
    }
  }
}
This example creates a basic CDNVideo resource named "testname" with an origin server at google.com using port 443.

Important Features and Limitations

Lack of Import Functionality

It's important to note that the current version of the CDNVideo Terraform Provider does not implement the import function for existing resources. This means you won't be able to import already existing CDN resources into your Terraform configuration.

Configuration Application Sequence

If you've started managing your CDN infrastructure using the CDNVideo Terraform Provider, it's strongly recommended to continue using this method for all subsequent changes. This will ensure consistency between your Terraform configuration and the actual state of the infrastructure.

Recommendations:

  1. Always apply changes through Terraform using the terraform plan and terraform apply commands.
  2. Avoid making changes directly through the CDNVideo web interface or API, as this can lead to discrepancies between the state described in Terraform and the actual state of the resources.
  3. If you need to make changes outside of Terraform, be sure to reflect these changes in your Terraform configuration and run terraform apply to synchronize the state.

Troubleshooting

Here are some common issues and their solutions:

  1. Provider download fails:

    • Check your internet connection
    • Verify that you have the correct provider source in your configuration
    • If using a mirror, ensure it's correctly configured in your .terraformrc file
  2. Authentication fails:

    • Double-check your account name, username, and password
    • Ensure you have the necessary permissions in your CDNVideo account
  3. Resource creation fails:

    • Check the error message for specific details
    • Verify that all required fields are filled in your resource configuration
    • Ensure that the values you're providing are valid (e.g., correct port numbers, valid domain names)

Additional Information

  • Detailed usage examples can be found in the examples/ directory of the provider repository.
  • Full documentation is available in the Terraform Registry.
  • If you have any questions or issues, please contact CDNVideo support.