### Include Example Usage in Documentation Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/README.md Uncomment this block to include example resource/data source usage in your documentation. Ensure example files exist at the specified path. ```markdown {{- /* Uncomment this block as you add "examples/{serviceName}/resources/example_1.tf" ## Example Usage {{tffile "examples/{serviceName}/resources/example_1.tf" }} */ -}} ``` -------------------------------- ### Example Usage Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/storage_bucket_grant.md Provides examples of how to configure the `yandex_storage_bucket_grant` resource for different scenarios, including managing grants for individual users and groups. ```APIDOC ## Example Usage ```terraform provider "yandex" { cloud_id = "" folder_id = "" storage_access_key = "" storage_secret_key = "" token = "" } resource "yandex_storage_bucket_grant" "my_grant_0" { bucket = "my_bucket_name_0" grant { id = "" permissions = ["READ", "WRITE", "FULL_CONTROL"] type = "CanonicalUser" } } resource "yandex_storage_bucket_grant" "my_grant_1" { bucket = "my_bucket_name_1" grant { id = "" permissions = ["FULL_CONTROL"] type = "CanonicalUser" } grant { uri = "" permissions = ["READ"] type = "Group" } } ``` ```terraform // // Create new grants on an existing Storage Bucket. // resource "yandex_storage_bucket_grant" "my_bucket_grant" { bucket = "my_bucket_name_0" grant { id = "" permissions = ["READ", "WRITE"] type = "CanonicalUser" } grant { id = "" permissions = ["FULL_CONTROL"] type = "CanonicalUser" } grant { uri = "http://acs.amazonaws.com/groups/global/AuthenticatedUsers" permissions = ["READ"] type = "Group" } } ``` ``` -------------------------------- ### Example Usage Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/backup_policy_bindings.md Example of how to create a new Cloud Backup Policy Binding using Terraform. ```APIDOC ```terraform # # Create a new Cloud Backup Policy Binding # resource "yandex_iam_service_account" "test_sa" { name = "sa-backup-editor" } resource "yandex_resourcemanager_folder_iam_member" "test_binding" { folder_id = yandex_iam_service_account.test_sa.folder_id role = "backup.editor" member = "serviceAccount:${yandex_iam_service_account.test_sa.id}" } resource "yandex_vpc_network" "test_backup_network" {} resource "yandex_vpc_subnet" "test_backup_subnet" { zone = "ru-central1-a" network_id = yandex_vpc_network.test_backup_network.id v4_cidr_blocks = ["192.168.0.0/24"] } # https://yandex.cloud/ru/docs/backup/concepts/vm-connection#vm-network-access resource "yandex_vpc_security_group" "test_backup_security_group" { name = "cloud-backup" network_id = yandex_vpc_network.test_backup_network.id egress { protocol = "TCP" from_port = 7770 to_port = 7800 v4_cidr_blocks = ["84.47.172.0/24"] } egress { protocol = "TCP" port = 443 v4_cidr_blocks = ["213.180.204.0/24", "213.180.193.0/24", "178.176.128.0/24", "84.201.181.0/24", "84.47.172.0/24"] } egress { protocol = "TCP" port = 80 v4_cidr_blocks = ["213.180.204.0/24", "213.180.193.0/24"] } egress { protocol = "TCP" port = 8443 v4_cidr_blocks = ["84.47.172.0/24"] } egress { protocol = "TCP" port = 44445 v4_cidr_blocks = ["51.250.1.0/24"] } } data "yandex_compute_image" "ubuntu" { family = "ubuntu-2004-lts" } resource "yandex_compute_instance" "test_backup_compute" { name = "test-backup-compute" platform_id = "standard-v1" zone = "ru-central1-a" service_account_id = yandex_iam_service_account.test_sa.id network_interface { subnet_id = yandex_vpc_subnet.test_backup_subnet.id security_group_ids = [yandex_vpc_security_group.test_backup_security_group.id] nat = true } boot_disk { initialize_params { image_id = data.yandex_compute_image.ubuntu.id } } resources { cores = 2 memory = 4 } metadata = { user-data = "#cloud-config\npackages:\n - curl\n - perl\n - jq\nruncmd:\n - curl https://storage.yandexcloud.net/backup-distributions/agent_installer.sh | sudo bash\n" } } data "yandex_backup_policy" "test_backup_policy" { name = "Default daily" } resource "yandex_backup_policy_bindings" "test_backup_binding" { instance_id = yandex_compute_instance.test_backup_compute.id policy_id = data.yandex_backup_policy.test_backup_policy.id } ``` ``` -------------------------------- ### Shared Credentials File Example Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/index.md Example structure for a shared credentials file, defining different profiles with storage access and secret keys. ```shell [prod] storage_access_key = prod_access_key_here storage_secret_key = prod_secret_key_here [testing] storage_access_key = testing_access_key_here storage_secret_key = testing_secret_key_here [default] storage_access_key = default_access_key_here storage_secret_key = default_secret_key_here ``` -------------------------------- ### Example Usage Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/storage_bucket_policy.md Demonstrates how to configure the `yandex_storage_bucket_policy` resource in Terraform. ```APIDOC ```terraform provider "yandex" { cloud_id = "" folder_id = "" storage_access_key = "" storage_secret_key = "" token = "" } resource "yandex_storage_bucket_policy" "my_policy_0" { bucket = "my_bucket_name_0" policy = < ``` ``` -------------------------------- ### Create Disk Placement Group and IAM Binding Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/compute_disk_placement_group_iam_binding.md This example demonstrates how to create a new disk placement group and then assign an IAM policy binding to it. Ensure the disk placement group is created before attempting to bind IAM policies. ```terraform resource "yandex_compute_disk_placement_group" "group1" { name = "test-pg" folder_id = "abc*********123" description = "my description" } resource "yandex_compute_disk_placement_group_iam_binding" "editor" { disk_placement_group_id = data.yandex_compute_disk_placement_group.group1.id role = "editor" members = [ "userAccount:some_user_id", ] } ``` -------------------------------- ### All Bucket Settings Example Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/storage_bucket.md This comprehensive example configures a Yandex Cloud Storage bucket with various settings including lifecycle rules, CORS, versioning, encryption, logging, size limits, folder ID, default storage class, anonymous access, HTTPS, and tags. It also includes provider configuration and a KMS key resource. ```terraform // // All Bucket settings example. // provider "yandex" { token = "" folder_id = "" storage_access_key = "" storage_secret_key = "" } resource "yandex_storage_bucket" "log_bucket" { bucket = "my-tf-log-bucket" lifecycle_rule { id = "cleanupoldlogs" enabled = true expiration { days = 365 } } } resource "yandex_kms_symmetric_key" "key-a" { name = "example-symetric-key" description = "description for key" default_algorithm = "AES_128" rotation_period = "8760h" // equal to 1 year } resource "yandex_storage_bucket" "all_settings" { bucket = "example-tf-settings-bucket" website { index_document = "index.html" error_document = "error.html" } lifecycle_rule { id = "test" enabled = true prefix = "prefix/" expiration { days = 30 } } lifecycle_rule { id = "log" enabled = true prefix = "log/" transition { days = 30 storage_class = "COLD" } expiration { days = 90 } } lifecycle_rule { id = "everything180" prefix = "" enabled = true expiration { days = 180 } } lifecycle_rule { id = "cleanupoldversions" prefix = "config/" enabled = true noncurrent_version_transition { days = 30 storage_class = "COLD" } noncurrent_version_expiration { days = 90 } } lifecycle_rule { id = "abortmultiparts" prefix = "" enabled = true abort_incomplete_multipart_upload_days = 7 } cors_rule { allowed_headers = ["*"] allowed_methods = ["GET", "PUT"] allowed_origins = ["https://storage-cloud.example.com"] expose_headers = ["ETag"] max_age_seconds = 3000 } versioning { enabled = true } server_side_encryption_configuration { rule { apply_server_side_encryption_by_default { kms_master_key_id = yandex_kms_symmetric_key.key-a.id sse_algorithm = "aws:kms" } } } logging { target_bucket = yandex_storage_bucket.log_bucket.id target_prefix = "tf-logs/" } max_size = 1024 folder_id = "" default_storage_class = "COLD" anonymous_access_flags { read = true list = true } https = { certificate_id = "" } tags = { some_key = "some_value" } } ``` -------------------------------- ### Get OrganizationManager MFA Enforcement Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/data-sources/organizationmanager_mfa_enforcement.md Use this data source to get information about an MFA enforcement configuration. Required arguments include `acr_id`. ```terraform // // OrganizationManager MFA Enforcement. // data "yandex_organizationmanager_mfa_enforcement" "example_mfa_enforcement" { acr_id = "any-mfa" } ``` -------------------------------- ### Create a ClickHouse User with Permissions and Quotas Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/mdb_clickhouse_user.md This example demonstrates how to provision a ClickHouse user with specific database permissions and resource quotas. Ensure the ClickHouse cluster and database are created prior to this resource. ```terraform resource "yandex_vpc_network" "foo" {} resource "yandex_vpc_subnet" "foo" { zone = "ru-central1-a" network_id = yandex_vpc_network.foo.id v4_cidr_blocks = ["10.5.0.0/24"] } resource "yandex_mdb_clickhouse_cluster" "foo" { name = "test" environment = "PRESTABLE" network_id = yandex_vpc_network.foo.id resources { resource_preset_id = "s2.micro" disk_type_id = "network-ssd" disk_size = 32 } config { } host { type = "CLICKHOUSE" zone = "ru-central1-a" subnet_id = yandex_vpc_subnet.foo.id } service_account_id = "your_service_account_id" maintenance_window { type = "ANYTIME" } lifecycle { ignore_changes = [database, user, ] } } resource "yandex_mdb_clickhouse_database" "foo" { cluster_id = yandex_mdb_clickhouse_cluster.foo.id name = "database1" } resource "yandex_mdb_clickhouse_user" "foo" { cluster_id = yandex_mdb_clickhouse_cluster.foo.id name = "user" password = "your_password" permission { database_name = yandex_mdb_clickhouse_database.foo.name } settings { max_memory_usage_for_user = 1000000000 read_overflow_mode = "throw" output_format_json_quote_64bit_integers = true } quota { interval_duration = 3600000 queries = 10000 errors = 1000 } quota { interval_duration = 79800000 queries = 50000 errors = 5000 } } ``` -------------------------------- ### Get User SSH Key Information Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/data-sources/organizationmanager_user_ssh_key.md Use this data source to get information about an existing User SSH Key. You must specify the `user_ssh_key_id`. ```terraform // // Get information about existing OrganizationManager User SSH Key. // data "yandex_organizationmanager_user_ssh_key" "my_user_ssh_key" { user_ssh_key_id = "some_user_ssh_key_id" } output "my_user_ssh_key_name" { value = "data.yandex_organizationmanager_user_ssh_key.my_user_ssh_key.name" } ``` -------------------------------- ### Import IAM Binding Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/container_registry_iam_binding.md This example shows how to import an existing IAM binding for a Container Registry. Ensure you have the correct registry ID and role. ```shell # terraform import yandex_container_registry_iam_binding. "," terraform import yandex_container_registry_iam_binding.puller "crps9**********k9psn,container-registry.images.puller" ``` -------------------------------- ### Create Certificates with Per-Domain DNS Challenges Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/cm_certificate.md This example demonstrates creating multiple managed certificates for a set of domains, each requiring a unique DNS CNAME challenge. It also shows how to provision DNS records using the `yandex_dns_recordset` resource, with `challenge_count` set to match the number of domains. ```terraform resource "yandex_cm_certificate" "example" { name = "example" domains = ["one.example.com", "two.example.com"] managed { challenge_type = "DNS_CNAME" challenge_count = 2 # for each domain } } resource "yandex_dns_recordset" "example" { count = yandex_cm_certificate.example.managed[0].challenge_count zone_id = "example-zone-id" name = yandex_cm_certificate.example.challenges[count.index].dns_name type = yandex_cm_certificate.example.challenges[count.index].dns_type data = [yandex_cm_certificate.example.challenges[count.index].dns_value] ttl = 60 } ``` -------------------------------- ### Get DNS Zone Information Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/data-sources/dns_zone.md Use this data source to get information about an existing DNS Zone. Ensure that either `dns_zone_id` or `name` is provided. ```terraform data "yandex_dns_zone" "foo" { dns_zone_id = yandex_dns_zone.zone1.id } output "zone" { value = data.yandex_dns_zone.foo.zone } ``` -------------------------------- ### Get Datasphere Community Information Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/data-sources/datasphere_community.md Use this data source to get information about an existing Datasphere Community by its ID. Ensure the `community_id` is correctly specified. ```terraform // // Get information about existing Datasphere Community. // data "yandex_datasphere_community" "my_datasphere_community" { community_id = "community-id" } ``` -------------------------------- ### Create a Compute Disk in a Placement Group Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/resources/compute_disk.md This example demonstrates creating a non-replicated SSD disk and associating it with a specific disk placement group. Ensure the placement group is defined. ```terraform resource "yandex_compute_disk" "my_vm" { name = "non-replicated-disk-name" size = 93 // Non-replicated SSD disk size must be divisible by 93G type = "network-ssd-nonreplicated" zone = "ru-central1-b" disk_placement_policy { disk_placement_group_id = yandex_compute_disk_placement_group.my_pg.id } } resource "yandex_compute_disk_placement_group" "my_pg" { zone = "ru-central1-b" } ``` -------------------------------- ### Get Cloud Registry Information Source: https://github.com/yandex-cloud/terraform-provider-yandex/blob/master/docs/data-sources/cloudregistry_registry.md Use this data source to get information about an existing Cloud Registry. You need to provide the `registry_id` to identify the registry. ```terraform data "yandex_cloudregistry_registry" "source" { registry_id = "some_registry_id" } ```