-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Container Instance Terraform module (#8)
- Loading branch information
Showing
6 changed files
with
266 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,74 @@ | ||
data "oci_identity_availability_domains" "local_ads" { | ||
compartment_id = var.compartment_ocid | ||
} | ||
|
||
|
||
resource "oci_container_instances_container_instance" "container_instance" { | ||
count = length(var.container_instance) | ||
|
||
availability_domain = data.oci_identity_availability_domains.local_ads.availability_domains.0.name | ||
compartment_id = var.compartment_ocid | ||
|
||
display_name = var.container_instance[count.index]["container_name"] | ||
container_restart_policy = "ALWAYS" | ||
shape = var.container_instance[count.index]["shape"] | ||
shape_config { | ||
memory_in_gbs = var.container_instance[count.index]["mem"] | ||
ocpus = var.container_instance[count.index]["cpu"] | ||
} | ||
availability_domain = var.availability_domain | ||
compartment_id = var.compartment_ocid | ||
|
||
vnics { | ||
subnet_id = var.subnet_id | ||
is_public_ip_assigned = false | ||
} | ||
display_name = var.display_name | ||
container_restart_policy = var.container_restart_policy | ||
shape = var.shape | ||
shape_config { | ||
memory_in_gbs = var.memory_in_gbs | ||
ocpus = var.ocpus | ||
} | ||
|
||
containers { | ||
image_url = var.container_instance[count.index]["container_image_url"] | ||
display_name = var.container_instance[count.index]["container_name"] | ||
vnics { | ||
subnet_id = var.subnet_id | ||
is_public_ip_assigned = false | ||
hostname_label = var.display_name | ||
} | ||
|
||
environment_variables = var.container_instance[count.index]["env_variables"] | ||
dynamic "containers" { | ||
for_each = var.containers | ||
content { | ||
display_name = containers.value.display_name | ||
image_url = containers.value.image_url | ||
environment_variables = try(containers.value.environment_variables, null) | ||
|
||
command = try(var.container_instance[count.index]["command"], null) | ||
arguments = try(var.container_instance[count.index]["arguments"], null) | ||
command = try(containers.value.command, null) | ||
arguments = try(containers.value.arguments, null) | ||
|
||
dynamic "volume_mounts" { | ||
for_each = try(var.container_instance[count.index]["volumes"], {}) | ||
content { | ||
volume_name = volume_mounts.key | ||
mount_path = volume_mounts.value.path | ||
} | ||
} | ||
dynamic "volume_mounts" { | ||
for_each = containers.value.volume_mounts == null ? [] : containers.value.volume_mounts | ||
content { | ||
volume_name = volume_mounts.value.volume_name | ||
mount_path = volume_mounts.value.mount_path | ||
} | ||
} | ||
|
||
resource_config { | ||
memory_limit_in_gbs = try(var.container_instance[count.index]["memory_limit"], null) | ||
} | ||
|
||
security_context { | ||
run_as_group = try(var.container_instance[count.index]["run_as_group"], null) | ||
run_as_user = try(var.container_instance[count.index]["run_as_user"], null) | ||
security_context_type = "LINUX" | ||
resource_config { | ||
memory_limit_in_gbs = try(containers.value.memory_limit_in_gbs, null) | ||
vcpus_limit = try(containers.value.vcpus_limit, null) | ||
} | ||
|
||
working_directory = try(containers.value.working_directory, null) | ||
} | ||
} | ||
|
||
working_directory = try(var.container_instance[count.index]["working_directory"], null) | ||
} | ||
|
||
dynamic "image_pull_secrets" { | ||
for_each = try(var.image_pull_secrets, {}) | ||
content { | ||
registry_endpoint = image_pull_secrets.value.registry_endpoint | ||
secret_type = image_pull_secrets.value.secret_type | ||
dynamic "volumes" { | ||
for_each = var.volumes | ||
content { | ||
name = volumes.value.name | ||
volume_type = volumes.value.volume_type | ||
|
||
secret_id = try(image_pull_secrets.value.secret_id, null) | ||
username = base64encode(try(image_pull_secrets.value.username, null)) | ||
password = base64encode(try(image_pull_secrets.value.password, null)) | ||
dynamic "configs" { | ||
for_each = try(volumes.value.configs, []) | ||
content { | ||
data = configs.value.data | ||
file_name = configs.value.file_name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
dynamic "volumes" { | ||
for_each = try(var.container_instance[count.index]["volumes"], {}) | ||
content { | ||
name = volumes.key | ||
volume_type = volumes.value.volume_type | ||
backing_store = try(volumes.value.backing_store, null) | ||
dynamic "configs" { | ||
for_each = try(volumes.value.configs, {}) | ||
dynamic "image_pull_secrets" { | ||
for_each = var.image_pull_secrets | ||
content { | ||
data = try(configs.value, null) | ||
file_name = try(configs.key, null) | ||
registry_endpoint = image_pull_secrets.value.registry_endpoint | ||
secret_type = image_pull_secrets.value.secret_type | ||
|
||
secret_id = try(image_pull_secrets.value.secret_id, null) | ||
username = base64encode(try(image_pull_secrets.value.username, null)) | ||
password = base64encode(try(image_pull_secrets.value.password, null)) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
required_providers { | ||
oci = { | ||
source = "oracle/oci" | ||
version = ">= 4.101.0" | ||
experiments = [module_variable_optional_attrs] | ||
required_version = "~> 1.2" | ||
required_providers { | ||
oci = { | ||
source = "oracle/oci" | ||
version = "5.18.0" | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
title: "Container Instance Creation" | ||
description: "Container Instance Creation on OCI" | ||
outputGroups: | ||
- title: "Container Instance" | ||
schemaVersion: 1.1.0 | ||
locale: "en" | ||
variableGroups: | ||
- title: "OCI (Oracle Cloud Infrastructure) details" | ||
variables: | ||
- compartment_ocid | ||
- availability_domain | ||
- subnet_id | ||
|
||
- title: "Container Instance configuration details" | ||
variables: | ||
- display_name | ||
- shape | ||
- container_restart_policy | ||
- memory_in_gbs | ||
- ocpus | ||
- containers | ||
- volumes | ||
- image_pull_secrets | ||
|
||
variables: | ||
compartment_ocid: | ||
type: string | ||
required: true | ||
description: "The OCID of the compartment." | ||
title: "Compartment OCID" | ||
availability_domain: | ||
type: string | ||
required: true | ||
visible: complexExpression | ||
subnet_id: | ||
type: string | ||
title: "Subnet ID" | ||
description: "The OCID of the subnet to create the VNIC in." | ||
required: true | ||
display_name: | ||
type: string | ||
pattern: "^[a-z-]+$" | ||
title: "Display Name" | ||
description: "A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information. If you don't provide a name, a name is generated automatically." | ||
required: true | ||
shape: | ||
type: string | ||
title: "Shape" | ||
description: "The shape of the container instance. The shape determines the resources available to the container instance." | ||
required: true | ||
container_restart_policy: | ||
type: string | ||
pattern: "^(ALWAYS|NEVER|ON_FAILURE)$" | ||
title: "Container Restart Policy" | ||
description: "The container restart policy is applied for all containers in container instance." | ||
required: true | ||
memory_in_gbs: | ||
type: number | ||
title: "Memory in GBs" | ||
description: "The total amount of memory available to the container instance, in gigabytes." | ||
required: true | ||
ocpus: | ||
type: number | ||
title: "OCPUs" | ||
description: "The total number of OCPUs available to the container instance." | ||
required: true | ||
containers: | ||
type: list(map) | ||
title: "Containers" | ||
description: "The containers to create on this container instance." | ||
required: true | ||
volumes: | ||
type: list(map) | ||
title: "Volumes" | ||
description: "A volume is a directory with data that is accessible across multiple containers in a container instance." | ||
required: false | ||
image_pull_secrets: | ||
type: list(map) | ||
title: "Image Pull Secrets" | ||
description: "The image pulls secrets so you can access private registry to pull container images." | ||
required: false |
Oops, something went wrong.