[Yandex Cloud documentation](../../../index.md) > [Tutorials](../../index.md) > Application solutions > Creating a website > WordPress website > [WordPress website using Marketplace](index.md) > Terraform

# Creating a WordPress website using Terraform

To create and set up a [WordPress website](index.md) using Terraform:

1. [Get your cloud ready](#before-begin).
1. [Create the infrastructure](#deploy).
1. [Get credentials for authentication in the web interface](#get-auth-data).
1. [Connect to the WordPress web interface](#connect-wordpress-interface).

If you no longer need the resources you created, [delete them](#clear-out).

## Get your cloud ready {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../../billing/quickstart/index.md) and [link](../../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../../resource-manager/concepts/resources-hierarchy.md).

Make sure the selected [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) has a [cloud network](../../../vpc/concepts/network.md#network) with a [subnet](../../../vpc/concepts/network.md#subnet) in at least one [availability zone](../../../overview/concepts/geo-scope.md). To do this, select **VPC** on the folder page. If the list contains a network, click its name to see the list of subnets. If the subnets or network you need are not listed, [create them](../../../vpc/quickstart.md).

### Required paid resources {#paid-resources}

The cost of maintaining a WordPress website includes:
* Fee for a continuously running VM (see [Yandex Compute Cloud pricing](../../../compute/pricing.md)).
* Fee for using a dynamic or static [public IP address](../../../vpc/concepts/address.md#public-addresses) (see [Yandex Virtual Private Cloud pricing](../../../vpc/pricing.md)).
* Fee for public DNS queries and [DNS zones](../../../dns/concepts/dns-zone.md) if using [Yandex Cloud DNS](../../../dns/index.md) (see [Cloud DNS pricing](../../../dns/pricing.md)).

## Create an infrastructure {#deploy}

With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.

For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

To create your infrastructure via Terraform:
1. [Install Terraform](../../infrastructure-management/terraform-quickstart.md#install-terraform), [get authentication credentials](../../infrastructure-management/terraform-quickstart.md#get-credentials), and specify the source for installing the Yandex Cloud provider. For details, see [Configure your provider](../../infrastructure-management/terraform-quickstart.md#configure-provider), step 1.
1. Prepare the infrastructure description files.

   {% list tabs group=infrastructure_description %}

   - Ready-made archive {#ready}

     1. Create a directory.
     1. Download the [archive](https://storage.yandexcloud.net/doc-files/wordpress.zip) (1 KB).
     1. Unpack the archive to the directory. As a result, the `wordpress.tf` configuration file should appear in it.

   - Manually {#manual}

     1. Create a directory.
     1. Create a configuration file named `wordpress.tf` in the folder:

        {% cut "wordpress.tf" %}

        ```hcl
        terraform {
          required_providers {
            yandex = {
              source  = "yandex-cloud/yandex"
              version = ">= 0.47.0"
            }
          }
        }
        
        provider "yandex" {
          zone = "ru-central1-a"
        }
        
        resource "yandex_compute_image" "wordpress" {
          source_family = "wordpress"
        }
        
        resource "yandex_compute_disk" "boot-disk" {
          name     = "bootvmdisk"
          type     = "network-hdd"
          zone     = "ru-central1-a"
          size     = "20"
          image_id = yandex_compute_image.wordpress.id
        }
        
        resource "yandex_compute_instance" "vm-wordpress" {
          name        = "wordpress"
          platform_id = "standard-v3"
        
          resources {
            core_fraction = 20
            cores         = 2
            memory        = 1
          }
        
          boot_disk {
            disk_id = yandex_compute_disk.boot-disk.id
          }
        
          network_interface {
            subnet_id          = yandex_vpc_subnet.subnet-1.id
            nat                = true
            security_group_ids = ["${yandex_vpc_security_group.sg-1.id}"]
          }
        
          metadata = {
            ssh-keys = "<username>:<SSH_key_contents>"
          }
        }
        
        resource "yandex_vpc_security_group" "sg-1" {
          name        = "wordpress"
          description = "Description for security group"
          network_id  = yandex_vpc_network.network-1.id
        
          ingress {
            protocol       = "TCP"
            description    = "ext-http"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 80
          }
        
          ingress {
            protocol       = "TCP"
            description    = "ext-https"
            v4_cidr_blocks = ["0.0.0.0/0"]
            port           = 443
          }
        
          egress {
            protocol       = "ANY"
            description    = "any"
            v4_cidr_blocks = ["0.0.0.0/0"]
          }
        }
        
        resource "yandex_vpc_network" "network-1" {
          name = "network1"
        }
        
        resource "yandex_vpc_subnet" "subnet-1" {
          name           = "subnet1"
          zone           = "ru-central1-a"
          network_id     = yandex_vpc_network.network-1.id
          v4_cidr_blocks = ["192.168.1.0/24"]
        }
        
        resource "yandex_dns_zone" "zone-1" {
          name        = "example-zone-1"
          description = "Public zone"
          zone        = "example.com."
          public      = true
        }
        
        resource "yandex_dns_recordset" "rs-1" {
          zone_id = yandex_dns_zone.zone-1.id
          name    = "example.com."
          ttl     = 600
          type    = "A"
          data    = ["${yandex_compute_instance.vm-wordpress.network_interface.0.nat_ip_address}"]
        }
        
        resource "yandex_dns_recordset" "rs-2" {
          zone_id = yandex_dns_zone.zone-1.id
          name    = "www"
          ttl     = 600
          type    = "CNAME"
          data    = ["example.com"]
        }
        ```

        {% endcut %}

   {% endlist %}

   Learn more about the properties of Terraform resources in the relevant provider guides:
    * [VM instance](../../../compute/concepts/vm.md): [yandex_compute_instance](../../../terraform/resources/compute_instance.md)
    * [Security groups](../../../vpc/concepts/security-groups.md): [yandex_vpc_security_group](../../../terraform/resources/vpc_security_group.md)
    * [Network](../../../vpc/concepts/network.md#network): [yandex_vpc_network](../../../terraform/resources/vpc_network.md)
    * [Subnets](../../../vpc/concepts/network.md#subnet): [yandex_vpc_subnet](../../../terraform/resources/vpc_subnet.md)
    * [DNS zone](../../../dns/concepts/dns-zone.md): [yandex_dns_zone](../../../terraform/resources/dns_zone.md)
    * [DNS resource record](../../../dns/concepts/resource-record.md): [yandex_dns_recordset](../../../terraform/resources/dns_recordset.md)
1. Under `metadata`, specify the metadata for creating a VM: `<username>:<SSH_key_contents>`. Regardless of the username specified, the key is assigned to the user set in the WordPress image configuration. Such users differ depending on the image. For more information, see [Keys processed in public images Yandex Cloud](../../../compute/concepts/metadata/public-image-keys.md).
1. Create the resources:

   1. In the terminal, navigate to the configuration file directory.
   1. Make sure the configuration is correct using this command:
   
      ```bash
      terraform validate
      ```
   
      If the configuration is valid, you will get this message:
   
      ```bash
      Success! The configuration is valid.
      ```
   
   1. Run this command:
   
      ```bash
      terraform plan
      ```
   
      You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
   1. Apply the configuration changes:
   
      ```bash
      terraform apply
      ```
   
   1. Type `yes` and press **Enter** to confirm the changes.

## Get credentials for authentication in the web interface {#get-auth-data}

When creating a VM, an administrator account for the web interface is created automatically. To get the authentication credentials:

1. Use SSH to connect to the VM you created:

   ```bash
   ssh <username>@<VM_public_IP_address>
   ```

1. Switch to the `root` account:

   ```bash
   sudo su
   ```

1. Open the file for reading:

   ```bash
   cat root/default_passwords.txt
   ```

1. Copy the username and user password from the `WP_ADMIN_USER` and `WP_ADMIN_PASSWORD` lines.

## Connect to the WordPress web interface {#connect-wordpress-interface}

To connect to the WordPress web interface, do the following:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), go to the VM page, find the VM public IP address under **Network**, and add it to the [type A](../../../dns/concepts/resource-record.md#a) [resource record](../../../dns/concepts/dns-zone.md) you created earlier.
  
     ![add-ssh](../../../_assets/tutorials/wordpress/vm-create-5.png)
  
  1. In your browser, open the WordPress admin panel using the domain name you configured or the VM's address: `http://<domain_name_or_VM_public_address>/wp-admin`.
  1. Enter the username and password you saved earlier.

{% endlist %}

## How to delete the resources you created {#clear-out}

To stop paying for the resources you created:

1. Open the `wordpress.tf` file and delete your infrastructure description from it.
1. Apply the changes:

   1. In the terminal, navigate to the configuration file directory.
   1. Make sure the configuration is correct using this command:
   
      ```bash
      terraform validate
      ```
   
      If the configuration is valid, you will get this message:
   
      ```bash
      Success! The configuration is valid.
      ```
   
   1. Run this command:
   
      ```bash
      terraform plan
      ```
   
      You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
   1. Apply the configuration changes:
   
      ```bash
      terraform apply
      ```
   
   1. Type `yes` and press **Enter** to confirm the changes.

#### Useful links {#see-also}

* [Creating a WordPress website using the management console](console.md).