### Create agent pool and install agent using helm chart Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/agent_pool.md This example demonstrates how to create a basic agent pool and then use the `helm_release` resource to install the env0 agent using its Helm chart. It highlights the use of `env0_agent_secret` to securely pass the agent access token. ```terraform variable "agent_custom_configuration" { type = map(any) description = "See https://docs.envzero.com/guides/admin-guide/self-hosted-kubernetes-agent/custom-optional-configuration" } resource "env0_agent_pool" "default" { name = "default self-hosted agent" } resource "env0_agent_secret" "first" { agent_id = env0_agent_pool.default.id } resource "helm_release" "this" { repository = "https://env0.github.io/self-hosted" chart = "env0-agent" namespace = "env0-agent-default" name = "env0-agent-default" create_namespace = true timeout = 600 set_sensitive { name = "agentAccessToken" value = env0_agent_secret.first.secret } values = [ yamlencode(var.agent_custom_configuration) ] } ``` -------------------------------- ### Install Mockgen Source: https://github.com/env0/terraform-provider-env0/blob/main/README.md Install the mockgen tool from Uber's Go libraries, which is used for generating mock implementations of interfaces. ```shell go install go.uber.org/mock/mockgen@v0.5.0 ``` -------------------------------- ### Example Usage of env0 Templates Data Source Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/data-sources/templates.md This example demonstrates how to fetch all template names using the `env0_templates` data source and then retrieve individual template details using the `env0_template` data source for each name. It also shows how to output the names of the fetched templates. ```terraform data "env0_templates" "all_templates" {} data "env0_template" "templates" { for_each = toset(data.env0_templates.all_templates.names) name = each.value } output "template1_name" { value = data.env0_template.templates["Github Test-111"].name } output "template2_name" { value = data.env0_template.templates["Github Test-222"].name } ``` -------------------------------- ### Install Pre-commit Hooks Source: https://github.com/env0/terraform-provider-env0/blob/main/README.md Commands to install pre-commit and pre-push hooks for maintaining code style and quality during development. ```bash pre-commit install pre-commit install --hook-type pre-push ``` -------------------------------- ### env0_github_installation_id Data Source Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/data-sources/github_installation_id.md Example of how to use the env0_github_installation_id data source to retrieve the GitHub installation ID for a repository. ```APIDOC ## env0_github_installation_id Data Source ### Description Returns the GitHub installation ID of a GitHub repository. ### Method GET (Implicitly through Terraform data source) ### Endpoint N/A (Terraform data source) ### Parameters #### Query Parameters - **repository** (String) - Required - The URL of the GitHub repository (e.g., "https://github.com/env0/templates"). ### Request Example ```terraform data "env0_github_installation_id" "example" { repository = "https://github.com/env0/templates" } output "github_installation_id" { value = data.env0_github_installation_id.example.github_installation_id } ``` ### Response #### Success Response (200) - **github_installation_id** (Number) - The GitHub installation ID. - **id** (String) - The ID of this resource. #### Response Example ```json { "github_installation_id": 123456, "id": "example" } ``` ``` -------------------------------- ### Basic env0_environment Resource Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/environment.md This example shows how to create a basic environment resource. It requires data sources for the template and project. ```terraform data "env0_template" "example" { name = "Template Name" } data "env0_project" "default_project" { name = "Default Organization Project" } resource "env0_environment" "example" { name = "environment" project_id = data.env0_project.default_project.id template_id = data.env0_template.example.id } ``` -------------------------------- ### env0_git_token Resource and Data Sources Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/data-sources/git_token.md This example demonstrates how to create a git token resource and then reference it using data sources by ID and by name. ```terraform resource "env0_git_token" "git_token_sample" { name = "name" value = "value" } data "env0_git_token" "git_token_sample_by_id" { id = env0_git_token.git_token_sample.id } data "env0_git_token" "git_token_sample_by_name" { name = env0_git_token.git_token_sample.name } ``` -------------------------------- ### Import env0_api_key by Name Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/api_key.md This example demonstrates importing an existing env0 API key using its name. This method is an alternative to importing by ID for managing existing resources. ```shell terraform import env0_api_key.by_name api-key-name ``` -------------------------------- ### env0_oci_credentials Resource Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/oci_credentials.md Example usage of the env0_oci_credentials resource to configure OCI credentials. ```APIDOC ## env0_oci_credentials (Resource) ### Description Manages OCI credentials within env0. ### Method Not applicable (Terraform resource) ### Endpoint Not applicable (Terraform resource) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (String) - Required - name for the oci credentials - **tenancy_ocid** (String) - Required - OCI tenancy OCID - **user_ocid** (String) - Required - OCI user OCID - **fingerprint** (String) - Required - OCI API key fingerprint - **private_key** (String, Sensitive) - Required - OCI API private key - **region** (String) - Required - OCI region - **project_id** (String) - Optional - the env0 project id to associate the credentials with ### Request Example ```terraform resource "env0_oci_credentials" "example" { name = "my-oci-credentials" tenancy_ocid = "ocid1.tenancy.oc1..exampleuniqueID" user_ocid = "ocid1.user.oc1..exampleuniqueID" fingerprint = "12:34:56:78:90:ab:cd:ef:12:34:56:78:90:ab:cd:ef" private_key = <- (Examples: 12-h, 3-d, 1-w, 1-M). Default value is 'inherit' which inherits the organization policy. must be equal or shorter than max_ttl - **disable_destroy_environments** (Boolean) - Disallow destroying environment in the project - **drift_detection_cron** (String) - default cron expression for new environments - **force_remote_backend** (Boolean) - if 'true' all environments created in this project will be forced to use env0 remote backend. Default is 'false' - **include_cost_estimation** (Boolean) - Enable cost estimation for the project - **max_ttl** (String) - the maximum environment time-to-live allowed on deploy time. Format is - (Examples: 12-h, 3-d, 1-w, 1-M). Default value is 'inherit' which inherits the organization policy. must be equal or longer than default_ttl - **number_of_environments** (Number) - Max number of environments a single user can have in this project. Omitting removes the restriction. - **number_of_environments_total** (Number) - Max number of environments in this project. Omitting removes the restriction. - **outputs_as_inputs_enabled** (Boolean) - if 'true' enables 'environment outputs'. Default is 'false' - **requires_approval_default** (Boolean) - Requires approval default value when creating a new environment in the project - **run_pull_request_plan_default** (Boolean) - Run Terraform Plan on Pull Requests for new environments targeting their branch default value - **skip_apply_when_plan_is_empty** (Boolean) - Skip apply when plan has no changes - **skip_redundant_deployments** (Boolean) - Automatically skip queued deployments when a newer deployment is triggered - **vcs_pr_comments_enabled_default** (Boolean) - if 'true' all environments created in this project will be created with an 'enabled' running VCS PR plan/apply commands using PR comments. Default is 'false' ### Read-Only Properties - **id** (String) - id of the policy - **updated_by** (String) - updated by ### Example Usage ```terraform data "env0_project" "default_project" { name = "Default Organization Project" } resource "env0_project_policy" "example" { project_id = data.env0_project.default_project.id number_of_environments = 1 number_of_environments_total = 1 requires_approval_default = true include_cost_estimation = true skip_apply_when_plan_is_empty = true disable_destroy_environments = true skip_redundant_deployments = true drift_detection_cron = "0 4 * * *" # Run drift detection daily at 4 AM auto_drift_remediation = "CODE_TO_CLOUD" # Optional, defaults to "DISABLED" } ``` ``` -------------------------------- ### Retrieve Self-hosted VCS Connection (GitHub Enterprise Example) Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/data-sources/vcs_connection.md Use this snippet to fetch a self-hosted VCS connection, such as GitHub Enterprise. The `access_scope` should start with 'url:' followed by the base URL or repository URL. ```terraform data "env0_vcs_connection" "github_enterprise" { access_scope = "url:https://github.mycompany.com" connection_type = "DeploymentPipeline" } ``` -------------------------------- ### env0_gcp_cloud_configuration Example Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/gcp_cloud_configuration.md Use this resource to configure a GCP cloud account. Ensure the credential configuration file content is provided. ```terraform resource "env0_gcp_cloud_configuration" "example" { name = "example-gcp-config" gcp_project_id = "your-gcp-project-id" credential_configuration_file_content = file("path/to/your-gcp-service-account.json") } ``` -------------------------------- ### Create Azure Cost Credentials and Assign to Project Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/cost_credentials_project_assignment.md This example demonstrates how to create Azure cost credentials and then assign them to a project. Ensure you have the necessary Azure credentials configured. ```terraform resource "env0_azure_cost_credentials" "azure_cost_credentials" { name = "cost credentials" client_id = "client id" client_secret = "client secret" subscription_id = "43242342dsdfsdfsdf" tenant_id = "fsdf-fsdfdsfs-fsdfsdfsd-fsdfsd" } resource "env0_project" "project" { name = "project" } resource "env0_cost_credentials_project_assignment" "cost_project_assignment" { credential_id = env0_azure_cost_credentials.azure_cost_credentials.id project_id = env0_project.project.id } ``` -------------------------------- ### env0_environment Resource with HCL Configuration Source: https://github.com/env0/terraform-provider-env0/blob/main/docs/resources/environment.md This example demonstrates creating an environment with a specific HCL configuration. Ensure the configuration name and type are set correctly. ```terraform resource "env0_environment" "example_with_hcl_configuration" { name = "environment with hcl" project_id = data.env0_project.default_project.id template_id = data.env0_template.example.id configuration { name = "TEST1234" type = "terraform" value = <