TencentCloud Terraform Provider

repository·master·Indexed 42 days ago

https://github.com/tencentcloudstack/terraform-provider-tencentcloud

A Terraform provider that allows users to manage Tencent Cloud infrastructure using a declarative configuration language. It provides resources and data sources to automate the provisioning and management of Tencent Cloud services, including CVM, Cloud Log Service (CLS), DNSPod, and Kubernetes addons.

Tokens
272.6K
Snippets
576
Records
990
Agent score
50%

What's inside TencentCloud Terraform Provider

  1. Manage TencentDB for Redis (crs) instances with tencentcloud_redis_instance

    master

    The tencentcloud_redis_instance resource allows you to create and manage Redis or Memcached instances within TencentCloud.

    Important Requirements:

    • vpc_id and subnet_id are required because Basic Network Instances are no longer supported.
    • While you can add or remove replications in a single change, it is not recommended.

    Common use cases include creating base Redis instances, multi-AZ (Availability Zone) deployments, prepaid instances, and Memcached instances.

    resource "tencentcloud_redis_instance" "example" {
      name               = "tf-example"
      availability_zone  = "ap-guangzhou-a"
      type_id            = 7
      password           = "Password@123"
      mem_size           = 8192
      redis_shard_num    = 1
      redis_replicas_num = 1
      port               = 6379
      vpc_id             = "vpc-xxxxxxxx"
      subnet_id          = "subnet-xxxxxxxx"
    }
  2. Available TencentCloud Resources and Data Sources

    master

    The TencentCloud Terraform provider supports a wide range of services including databases, monitoring, and serverless functions. Each service provides both Resources (for managing the lifecycle of a component) and Data Sources (for fetching information about existing components).

    Key service groups include:

    • TencentDB for MongoDB (mongodb): Manage MongoDB instances, accounts, backups, and sharding.
    • TencentDB for MySQL (cdb): Manage MySQL instances, databases, accounts, privileges, and backup policies.
    • Cloud Monitor (Monitor): Manage alarm policies, notification channels, and monitor data.
    • Managed Service for Prometheus (TMP): Manage Prometheus instances, alert rules, and scrape jobs.
    • TencentCloud Managed Service for Grafana (TCMG): Manage Grafana instances, plugins, and notification channels.
    • TencentDB for PostgreSQL (PostgreSQL): Manage PostgreSQL instances, accounts, and backup plans.
    • TencentDB for Redis (crs): Manage Redis instances, accounts, and backup configurations.
    • Serverless Cloud Function (SCF): Manage SCF functions, namespaces, layers, and triggers.
    • SQLServer: Manage SQLServer instances, databases, and accounts.
  3. Manage Cloud Virtual Machine (CVM) instances with tencentcloud_instance

    master

    The tencentcloud_instance resource allows you to provision and manage Cloud Virtual Machine (CVM) instances on TencentCloud.

    Key Constraints and Behaviors:

    • VPC Networking: To launch an instance in a VPC network, specify the vpc_id parameter. An instance can only belong to a single VPC.
    • Prepaid Instances: PREPAID instances cannot be deleted directly; they must expire and be released automatically.
    • Placement Groups: The placement_group_id field supports setting and modification, but does not support deletion.
    • Launch Templates: If you use a launch_template_id and simultaneously specify other parameters, the values provided in the parameters will overwrite the template definitions.
    • Anti-DDoS EIP: For Anti-DDoS EIPs, it is recommended to create a tencentcloud_eip resource first, then use tencentcloud_eip_association to bind it to your tencentcloud_instance.
    • Data Disks for Prepaid Instances: When binding a data disk to a PREPAID CVM instance, you must explicitly set delete_with_instance to false.
    • Dedicated Resource Pool Packs: When using pre-purchased resource pool packs (via tencentcloud_cvm_resource_pool_packs), you must specify both dedicated_resource_pack_tenancy and dedicated_resource_pack_ids together.
  4. Configure Master Node Settings via master_config

    master

    The master_config block allows for advanced node settings when attaching instances to a TKE cluster.

    Key Configuration Options:

    • mount_target: The mount target path. Defaults to not mounting.
    • docker_graph_path: Path for Docker graph. Defaults to /var/lib/docker.
    • unschedulable: Set to 0 to allow the node to participate in scheduling; any non-zero value prevents scheduling. Use this in conjunction with user_script for pre-join initialization.
    • user_script: A base64-encoded user script executed after k8s components run. Logs are available at /data/ccs_userscript/. To make the node schedulable after script completion, run: kubectl uncordon <nodename> --kubeconfig=/root/.kube/config.
    • labels: A list of key-value pairs to apply as node labels. Requires name and value.
    • taints: A list of node taints. Supports key, value, and effect.
    • data_disk: Configuration for an additional data disk:
      • auto_format_and_mount: (Bool) Whether to auto format and mount. Defaults to false.
      • disk_partition: Name of the device/partition (e.g., /dev/vdb). Note: This is not supported in node pools.
      • disk_type: Valid values include LOCAL_BASIC, LOCAL_SSD, CLOUD_BASIC, CLOUD_PREMIUM, CLOUD_SSD, CLOUD_HSSD, CLOUD_TSSD, and CLOUD_BSSD.
      • file_system: e.g., ext3, ext4, xfs.
    • extra_args: Custom parameters for cluster components. Supports:
      • kubelet: Format ["k1=v1", "k2=v2"].
      • etcd, kube_api_server, kube_controller_manager, kube_scheduler (primarily for independent clusters).
    • gpu_args: Parameters for GPU drivers, including cuda, cudnn, driver, custom_driver, and mig_enable.
  5. Configure Sub-rules and Branching in TEO L7 Rules

    master

    The tencentcloud_teo_l7_acc_rule_v2 resource allows for hierarchical rule matching using branches and sub_rules.

    Branching Logic:

    • branches: An object containing a condition (match condition) and actions or sub_rules.
    • sub_rules: A list of rules executed sequentially from top to bottom.
    • Constraints:
      • Only one layer of sub-rules is supported.
      • A branch must contain either actions or sub_rules (they cannot both be empty).
      • The actions list within a branch currently supports only one rule; multiple entries are invalid.
  6. Understand the composite ID and ForceNew behavior

    master

    The tencentcloud_captcha_ip_white_list_international resource uses a composite ID to ensure global uniqueness, as a white list ID is only unique within a specific CaptchaAppid.

    Composite ID Format

    CaptchaAppid#Id (e.g., 2100000000#12345)

    ForceNew Triggers

    Certain changes cannot be updated in place and will trigger the destruction and recreation of the resource:

    • Changing captcha_appid: This value is a component of the resource ID.
    • Changing ip: The ModifyIpWhiteListInternational API does not support updating the Ip field directly; therefore, changing the IP requires a new resource creation.
  7. How MongoDB instance CPU updates work

    master

    Updating the cpu parameter on a tencentcloud_mongodb_instance follows a specific lifecycle to ensure the instance specification is modified correctly without downtime or resource recreation:

    1. Detection: Terraform detects a change to the cpu field via d.HasChange("cpu").
    2. API Call: The provider calls the ModifyDBInstanceSpec API, passing the new CPU value into the Cpu request field.
    3. Polling: Because specification changes are asynchronous, the provider polls the returned deal ID using the DescribeDBInstanceDeal API.
    4. Completion: The process continues until the deal succeeds (indicated when in_maintenance == 0).
    5. State Update: Once the modification is successful, the resource state is updated to reflect the new CPU count.

    If you omit the cpu field during an update of unrelated fields (like tags or project_id), the provider will not trigger a specification modification.

  8. Understand the lifecycle of tencentcloud_cbs_copy_snapshot_cross_region

    master

    This resource follows a CRD (Create, Read, Delete) pattern and does not support in-place updates.

    • Creation (Async): When you create the resource, the provider calls the CopySnapshotCrossRegions API. Because this is an asynchronous operation, the provider will automatically poll the DescribeSnapshots API until all copied snapshots reach the NORMAL state.
    • Immutability: Most configuration fields (like snapshot_id and destination_regions) are marked as ForceNew. If you change these values in your configuration, Terraform will destroy the existing resource and create a new one.
    • Deletion: When the resource is deleted, the provider calls the DeleteSnapshots API for all snapshot IDs identified in the snapshot_copy_result_set. If delete_bind_images is set to true, the provider will also attempt to force-delete associated images.
  9. Configure video resolution and scaling

    master

    When setting width and height in a video_template (either in override_parameter or raw_parameter), the following scaling logic applies:

    • Both 0: Resolution remains the same as the source video.
    • Width 0, Height > 0: Width is scaled proportionally to the target height.
    • Width > 0, Height 0: Height is scaled proportionally to the target width.
    • Both > 0: The custom resolution is used exactly.

    Resolution Adaptation

    The resolution_adaptive parameter controls how dimensions are interpreted:

    • open: Enabled. width represents the long side, and height represents the short side. Note: width cannot be smaller than height.
    • close: Disabled. width and height represent the actual horizontal and vertical dimensions.
  10. Use the tencentcloud_dbdc_db_custom_nodes data source

    master

    The tencentcloud_dbdc_db_custom_nodes data source allows you to query and retrieve information about DBDC custom nodes. You can filter nodes by specific IDs, cluster attributes, or tags. The data source automatically handles pagination and retries for transient API errors.

    data "tencentcloud_dbdc_db_custom_nodes" "example" {
      # Filter by specific node IDs (max 100)
      node_ids = ["node-1", "node-2"]
    
      # Filter by cluster-id, node-name, status, or zone
      filters {
        name   = "cluster-id"
        values = ["cluster-123"]
      }
    
      # Filter by tag key-value pairs
      tags {
        key   = "env"
        value = "prod"
      }
    }
    
    output "node_info" {
      value = data.tencentcloud_dbdc_db_custom_nodes.example.node_set
    }
  11. Manage EMR Clusters v2 with tencentcloud_emr_cluster_v2

    master

    The tencentcloud_emr_cluster_v2 resource allows you to manage Tencent Cloud EMR clusters using the EMR 2019-01-03 API. This resource is designed to mirror the CreateCluster request parameters directly in its schema.

    Key Attributes

    Required Attributes: To pass terraform validate, you must provide at least these six top-level attributes:

    • product_version
    • enable_support_ha_flag
    • instance_name
    • instance_charge_type
    • login_settings
    • scene_software_config

    Other Top-Level Attributes (snake_case): enable_remote_login_flag, enable_kerberos_flag, client_token, need_master_wan, custom_conf, tags, disaster_recover_group_ids, enable_cbs_encrypt_flag, meta_db_info, depend_service, zone_resource_configuration, cos_bucket, node_marks, load_balancer_id, default_meta_version, need_cdb_audit, sg_ip, partition_number, web_ui_version, security_group_ids, script_bootstrap_action_config, instance_charge_prepaid.

    Sensitive Fields: The following fields are marked as Sensitive and will be masked in logs/output:

    • login_settings.password
    • meta_db_info.meta_data_pass

    Lifecycle and Timeouts

    Because cluster operations are asynchronous, you can configure custom timeouts in a timeouts block. The default values are:

    • Create: 60 minutes
    • Read: 20 minutes
    • Delete: 30 minutes

    Note: The Update operation is currently a no-op (it only re-invokes the Read operation) and does not support modifying existing clusters via the API yet.

    ```hcl
    resource "tencentcloud_emr_cluster_v2" "example" {
      product_version        = "...