IBM Cloud Terraform Provider

repository·master·Indexed 18 days ago

https://github.com/ibm-cloud/terraform-provider-ibm

The IBM Cloud Terraform Provider allows users to manage IBM Cloud resources using Terraform's declarative configuration language. It supports various services, including Classic Infrastructure, IBM Cloud Internet Services (CIS), Kubernetes Services, Satellite, Schematics, Key Management Service (KMS), Power Systems, and High Performance Computing (HPCS).

Tokens
276.5K
Snippets
524
Records
995
Agent score
62%

What's inside terraform-provider-ibm

  1. Manage IBM Hyper Protect Crypto Services (HPCS) with ibm_hpcs

    master

    The ibm_hpcs resource manages IBM Cloud Hyper Protect Crypto Services (HPCS) instances. This resource allows you to initialize an instance and add HPCS sub-resources.

    Important Regional Limitation: Because recovery crypto units are currently only available in us-south and us-east, using Terraform to initialize HPCS instances is only supported in these two regions.

    resource ibm_hpcs hpcs {
      location             = "us-south"
      name                 = "test-hpcs"
      plan                 = "standard"
      units                = 2
      signature_threshold  = 1
      revocation_threshold = 1
      admins {
        name  = "admin1"
        key   = "/cloudTKE/1.sigkey"
        token = "<sensitive1234>"
      }
      admins {
        name  = "admin2"
        key   = "/cloudTKE/2.sigkey"
        token = "<sensitive1234>"
      }
    }
  2. Access IBM Provider documentation and resources

    master

    The terraform-provider-ibm repository is primarily for contributors and maintainers. End-users looking to use the provider should refer to the official documentation and API references provided in the links below.

  3. Access IBM Provider documentation and Cloud Shell resources

    master

    This file serves as a landing page for IBM provider contributors. For end-users looking to use the IBM Terraform provider or manage Cloud Shell resources, use the following official documentation links:

    • IBM Provider Documentation Home: The primary source for all Terraform resource and data source documentation.
    • Cloud Shell Resource Documentation: Specific documentation for managing Cloud Shell account settings via Terraform.
    • IBM Cloud Shell API Docs: Reference for the underlying REST APIs used by the provider.
    • IBM Cloud Shell SDK: The Go SDK for interacting with Cloud Shell services directly.
  4. Understand flow_job_data and workitems in ibm_schematics_job

    master

    The flow_job_data block provides details about the execution of a Flow, including its ID, name, and the specific workitems involved in the job.

    Workitems and Sources

    Each workitem contains a source_type and a source defining where the templates or playbooks originate.

    Supported source_type values: local, git_hub, git_hub_enterprise, git_lab, ibm_git_lab, ibm_cloud_catalog, external_scm, cos_bucket.

    Git Source Configuration

    If the source_type is a Git provider, the git block allows configuration via:

    • git_repo_url: The URL to clone.
    • git_token: Personal Access Token.
    • git_branch: The branch to fetch.
    • git_release: The release tag to fetch.
    • git_repo_folder: The specific folder within the repo containing the template.
    • computed_git_repo_url: The fully computed URL (read-only).
    # Conceptual structure of flow_job_data
    flow_job_data {
      flow_id   = "flow-123"
      flow_name = "deployment-flow"
    
      workitems {
        command_object_name = "provision-layer"
        source_type         = "git_hub"
        source {
          source_type = "git_hub"
          git {
            git_repo_url    = "https://github.com/org/repo"
            git_token       = "ghp_token"
            git_branch      = "main"
            git_repo_folder = "templates/provision"
          }
        }
      }
    }
  5. Configure Maintenance Mode for Protection Sources

    master

    The external_metadata attribute allows you to define maintenance mode configurations for a protection source. This is useful for scheduling windows where maintenance actions are permitted.

    Within external_metadata.maintenance_mode_config, you can specify:

    • activation_time_intervals: Absolute time ranges (using start_time_usecs and end_time_usecs) where the maintenance schedule is valid.
    • maintenance_schedule: A list of schedules, which can be of type PeriodicTimeWindows or CustomIntervals.
    • periodic_time_windows: Defines specific days of the week (Sunday through Saturday) and time ranges (start_time and end_time in hours and minutes).
    • workflow_intervention_spec_list: Defines how specific workflows (e.g., BackupRun) should behave when maintenance mode begins (e.g., NoIntervention or Cancel).
  6. Recover Kubernetes Namespaces

    master

    To recover Kubernetes resources, use the recover_namespace_params block. This allows for granular control over which objects (like volumes or specific resources) are included or excluded during the recovery process.

    Key components:

    • kubernetes_target_params: Contains include_params and exclude_params to filter objects.
    • label_combination_method: Determines how labels are evaluated. Valid values are AND or OR.
    • label_vector: A two-dimensional array of labels (each containing a key and value) used to identify objects via intersection or union.
    • selected_resources: Identifies specific resource types using api_group and kind (e.g., apps and VirtualMachine).
  7. Bind an IBM Cloud service to a Kubernetes cluster with ibm_container_bind_service

    master

    The ibm_container_bind_service resource binds an existing IBM Cloud service instance to an IBM Cloud Kubernetes Service (IKS) cluster. This process creates service credentials using the service's public endpoint and stores them in a Kubernetes secret within the specified namespace. The secret is automatically encrypted in etcd.

    Note: This resource is marked for deprecation. For modern service binding implementations, refer to the IBM Cloud binding guide.

    Prerequisite: You must have already provisioned an instance of the service you wish to bind.

    resource "ibm_container_bind_service" "bind_service" {
      cluster_name_id       = "cluster_name"
      service_instance_name = "service_name"
      namespace_id          = "default"
    }
  8. Use the ibm_code_engine_app data source

    master

    The ibm_code_engine_app data source is a read-only resource used to retrieve information about an existing IBM Cloud Code Engine application. Once retrieved, you can use its attributes (via interpolation) to configure other Terraform resources in your configuration.

    To use it, you must provide the application's name and the project_id of the project it belongs to.

    data "ibm_code_engine_app" "code_engine_app" {
    	name = ibm_code_engine_app.code_engine_app_instance.name
    	project_id = ibm_code_engine_app.code_engine_app_instance.project_id
    }
  9. Configure nameservers for IBM DNS domain registrations

    master

    The ibm_dns_domain_registration_nameservers resource manages the custom name servers associated with a DNS domain registration. By default, when a domain is registered, it uses IBM Cloud name servers. Using this resource replaces those default name servers with custom values.

    This resource is primarily used to hand over DNS management from the standard IBM Cloud DNS Registration Service to IBM Cloud Internet Services (CIS). To enable CIS for a domain, you must update the domain registration with the specific name servers provided by your CIS resource instance. This is a prerequisite for the domain in CIS to become active and serve web traffic.

    resource "ibm_dns_domain_registration_nameservers" "dnstestdomain" {
        dns_registration_id = data.ibm_dns_domain_registration.dnstestdomain.id
        name_servers = ibm_cis_domain.dnstestdomain.name_servers 
    }
    
    data "ibm_dns_domain_registration" "dnstestdomain" {
        name = "dnstestdomain.com"
    }
    
    resource "ibm_cis_domain" "dnstestdomain" {
       
    }
  10. Filter objects using include_params or exclude_params

    master

    You can control which objects (such as volumes or specific resources) are included or excluded during backup/recovery operations using include_params or exclude_params. Both blocks use a similar schema to define filters based on labels or specific resource identities.

    Label-based Filtering

    Use the label_vector to specify objects by their labels.

    • label_combination_method (String): Determines how labels are evaluated. Allowable values: AND, OR.
    • label_vector (List): A two-dimensional array where each inner array contains a key and a value representing a label.

    Resource-based Filtering

    Use selected_resources to target specific Kubernetes-style resources.

    • api_group (String): The API group (e.g., apps, kubevirt.io).
    • kind (String): The resource kind (e.g., VirtualMachine).
    • resource_list (List): A list of specific instances, where each instance contains:
      • entity_id (Integer): The specific entity ID.
      • name (String): The name of the entity.
      • version (String): The API version (ignored during recovery selection).
  11. Understand Backup Policy Plan nested configurations

    master

    The ibm_is_backup_policy_plan data source exposes several complex nested structures:

    clone_policy

    Used to manage snapshot clones.

    • max_snapshots (Integer): Maximum number of recent snapshots to keep per source.
    • zones (List): List of zones where snapshot clones will be created.

    deletion_trigger

    Defines how backups are removed.

    • delete_after (Integer): Maximum number of days to keep each backup after creation.
    • delete_over_count (Integer): Maximum number of recent backups to keep. If absent, there is no maximum.

    remote_region_policy

    Defines cross-region backup rules.

    • region (Required, String): The globally unique name of the target region.
    • delete_over_count (Optional, Integer): Maximum number of recent remote copies to keep in this region.
    • encryption_key (Optional, String): The CRN of the Key Protect Root Key or Hyper Protect Crypto Services Root Key to use for rewrapping the data encryption key. If unspecified, the source's encryption_key is used.
  12. Manage Instance Group scaling with ibm_is_instance_group_manager

    master

    The ibm_is_instance_group_manager resource is used to manage the scaling behavior of an IBM Cloud VPC Instance Group. It can be used to create autoscale managers (using policies) or scheduled managers (using actions).

    To build a complete scalable infrastructure, you typically use this resource in conjunction with:

    • ibm_is_instance_group: To create the underlying instance group.
    • ibm_is_instance_group_manager_policy: To define scaling rules (e.g., CPU utilization) for autoscale managers.
    • ibm_is_instance_group_manager_action: To define specific scaling events for scheduled managers.
    • ibm_is_lb and ibm_is_lb_pool: To distribute traffic across the instances managed by the group.
    import "github.com/IBMCloud/terraform-provider-ibm"
    
    # Note: This is a conceptual relationship of resources
    resource "ibm_is_instance_group" "example" {
      name = "my-instance-group"
    }
    
    resource "ibm_is_instance_group_manager" "example" {
      instance_group_id = ibm_is_instance_group.example.id
      # Configuration for autoscale or scheduled management
    }