OCI Terraform Provider

repository·master·Indexed 21 days ago

https://github.com/oracle/terraform-provider-oci

The OCI Terraform Provider enables the management of Oracle Cloud Infrastructure resources using Terraform configuration files. It includes functionality to export existing OCI resources to Terraform HCL and state files, as well as an HTTP Replay library for recording and replaying network interactions during SDK testing.

Tokens
281.9K
Snippets
412
Records
948
Agent score
71%

What's inside terraform-provider-oci

  1. Use the Oracle Cloud Infrastructure (OCI) Provider

    master

    The Oracle Cloud Infrastructure (OCI) provider enables Terraform to manage and interact with resources within the Oracle Cloud Infrastructure ecosystem. It is compatible with various Terraform distributions, including the standard Terraform CLI, Terraform Cloud, and the OCI Resource Manager service.

    To begin using the provider, you must configure it with valid credentials for your Oracle Cloud Account.

  2. Understand generated Terraform configuration behavior

    master

    When using the export command, the following behaviors apply to the generated .tf files:

    • Active Resources Only: Only resources in an active or usable state are discovered. Terminated or inactive resources are excluded.
    • Naming: By default, Terraform resource names match the resource's display name.
    • Missing Attributes: If a required or optional attribute cannot be discovered via OCI APIs, a placeholder is used to prevent plan failure: admin_password = "<placeholder for missing required attribute>" #Required attribute not found in discovery, placeholder value set to avoid plan failure
    • Lifecycle Management: Missing attributes are automatically added to lifecycle { ignore_changes = [...] }. This prevents Terraform from trying to overwrite these values during a plan. To manage these fields manually, you must remove them from the ignore_changes block.
    • Availability Domains: Resources dependent on availability domains (e.g., oci_core_boot_volume, oci_file_storage_file_system) are generated in an availability_domain.tf file.
  3. Configure automatic backup windows and retention

    master

    The db_backup_config attribute allows you to manage automatic backups.

    • Backup Windows: There are twelve available two-hour time windows. If no option is selected, a start time between 12:00 AM to 7:00 AM in the region is automatically chosen. For example, selecting SLOT_TWO starts the job between 2:00 AM and 4:00 AM.
    • Retention Policy: Use backup_deletion_policy to define when backups are deleted:
      • DELETE_IMMEDIATELY: Keeps the backup for 72 hours and then deletes it permanently.
      • DELETE_AFTER_RETENTION_PERIOD: Keeps backups according to the defined policy.
    • Termination Policy: For Autonomous Databases, backup_retention_policy_on_terminate can be set to RETAIN_PER_RETENTION_WINDOW or RETAIN_FOR_72_HOURS (default).
  4. Configure GoldenGate routing methods

    master

    The routing_method attribute determines how network traffic flows from GoldenGate to your target connection:

    • SHARED_DEPLOYMENT_ENDPOINT: Traffic flows from the assigned deployment's private endpoint through the deployment's subnet.
    • DEDICATED_ENDPOINT: A dedicated private endpoint is created in the target VCN subnet. Note: This requires providing a subnetId.
    • SHARED_SERVICE_ENDPOINT: Traffic flows through the GoldenGate Service's network to public hosts. This method cannot be used for private targets.
  5. Configure Autonomous Database compute model and count

    master

    When configuring the compute resources for an Autonomous AI Database, you must choose between the ECPU and OCPU models.

    • ECPU (Recommended): The modern compute model. When using the ECPU model, use the compute_count parameter. If cpu_core_count is used, it must be set to 0 for ECPU.
    • OCPU (Legacy): The older compute model.

    Important Constraints:

    • If you use cpu_core_count, it is an error to also specify compute_count with a non-null value.
    • Providing both compute_model and compute_count is the preferred method for both OCPU and ECPU.
  6. Configure Container and Function execution

    master

    The oci_devops_deploy_stage supports specific configurations for container-based and function-based deployments:

    Container Configuration

    Managed via container_config, which includes:

    • shape_name: The shape of the ContainerInstance.
    • shape_config: Resource sizing (e.g., ocpus, memory_in_gbs).
    • network_channel: Configuration for private network access (e.g., subnet_id, nsg_ids).
    • availability_domain and compartment_id.

    Function Configuration

    • function_deploy_environment_id: The environment OCID.
    • function_timeout_in_seconds: Execution timeout.
    • max_memory_in_mbs: Maximum usable memory for the Function.
  7. Configure APM Agent configuration with overrides

    master

    The oci_apm_config_config resource allows you to manage APM Agent configuration files. You can use a templating syntax within the body of a config_map to apply different settings to specific subsets of agents using the overrides block.

    Templating and Overrides Workflow

    1. Define a variable in the configuration body: Use the syntax {{ <variable_name> | default <default_value> }}.
      • Example: com.oracle.apm.agent.tracer.enable.jfr = {{ isJfrEnabled | default false }}
    2. Define an Agent Filter: Use the agent_filter field in the override_list to target specific agents (e.g., "agentFilter": "ApplicationType='Tomcat'").
    3. Provide the override value: Use the override_map to map the variable name to a new value.
      • Example: "overrideMap": { "isJfrEnabled": true }
    # Conceptual example of the templating logic described in the documentation
    # Configuration Body:
    # com.oracle.apm.agent.tracer.enable.jfr = {{ isJfrEnabled | default false }}
    
    # Overrides block structure:
    overrides = [
      {
        agent_filter = "ApplicationType='Tomcat'"
        override_map = {
          "isJfrEnabled" = true
        }
      }
    ]
  8. Use Secret OCIDs for Sensitive GoldenGate Connection Attributes

    master

    To follow security best practices and avoid the deprecated practice of using plain-text fields with vault_id and key_id, always use the corresponding _secret_id attributes.

    Example mapping for sensitive fields:

    • Instead of password, use passwordSecretId (or the specific attribute like trust_store_password_secret_id).
    • Instead of wallet, use wallet_secret_id (the OCID of the Secret containing the wallet file).
    • Instead of tlsCertificateKeyFile, use tls_certificate_key_file_secret_id.

    Note on wallet_secret_id: When providing wallet_secret_id, you must not provide the wallet field.

  9. Configure and monitor database backup settings

    master

    The db_backup_config attribute provides details on the database's backup configuration.

    Automatic Backups

    • auto_backup_enabled: Enables automatic backups.
    • auto_backup_window: A two-hour time window (e.g., SLOT_TWO).
    • auto_full_backup_day: Day of the week for full backups (defaults to Sunday).
    • auto_full_backup_window: Two-hour time window for full backups.
    • recovery_window_in_days: Number of days of recoverability covered by automatic backups.
    • run_immediate_full_backup: If true, triggers the first full backup immediately in the local region.

    Backup Deletion and Retention

    • backup_deletion_policy:
      • DELETE_IMMEDIATELY: Keeps backup for 72 hours, then deletes permanently.
      • DELETE_AFTER_RETENTION_PERIOD: Keeps backups according to the defined policy.
    • backup_retention_policy_on_terminate: Defines retention for Autonomous Database termination. Options: RETAIN_PER_RETENTION_WINDOW or RETAIN_FOR_72_HOURS (default).
    • is_retention_lock_enabled: If enabled, the retention window cannot be decreased. Once applied to an Autonomous Container Database, the lock cannot be removed (or the period decreased) after a 14-day period.

    Backup Destinations

    • backup_destination_details includes type, is_remote (cross-region vs local), remote_region, and id (OCID of the destination).
  10. Secure GoldenGate connection credentials using Secrets

    master

    Sensitive attributes for GoldenGate connections (such as passwords) are deprecated when provided as plain-text attributes encrypted with vaultId and keyId.

    Best Practice: Use the corresponding Secret OCID attributes (e.g., password_secret_id) instead of plain-text attributes. This aligns with the GoldenGate "Plain Text Fields in Connections" deprecation policy.

    When using Secret IDs:

    • Set does_use_secret_ids to true.
    • Provide the OCID of the secret in the appropriate _secret_id field.
  11. Configure Data Guard protection modes and transport types

    master

    The data_guard_group attribute provides information about the Data Guard setup. The transport_type for a member depends on the specified protection_mode:

    Protection ModeSupported Transport Types
    MAXIMUM_AVAILABILITYSYNC or FASTSYNC
    MAXIMUM_PERFORMANCEASYNC
    MAXIMUM_PROTECTIONSYNC

    IMPORTANT: The only transport type currently supported by the Database service is ASYNC.

  12. Configure MACS APM Extension with config_type=MACS_APM_EXTENSION

    master

    When config_type is set to MACS_APM_EXTENSION, the resource is used to provision an APM Agent via a Management Agent. The following arguments are required:

    • apm_domain_id: The APM Domain OCID.
    • attach_install_dir: The directory owned by the run_as_user.
    • management_agent_id: The OCID of the Management Agent.
    • process_filter: Filter patterns used to discover active Java processes.
    • run_as_user: The OS user used to discover Java processes.
    • service_name: The name of the service being monitored (used for filtering in the APM Explorer).
    • agent_version: The version of the referenced agent bundle.