# template

LLMS index: [llms.txt](https://docs.e.samsungsdscloud.com/en/userguide/management/llms.txt)

---

# template {#template}

A template is a file that defines infrastructure as code. Write in JSON or YAML format, including definitions of the resources to be created, input values, and output values.

Templates do not create resources by themselves. A stack must be created based on the template for the actual resources to be deployed. You can configure development, test, and production environments with the same definition by specifying only different parameters in the same template.

# Template configuration {#section}

The template consists of the following elements.


| Category | Explanation |
|---------|--------|
| Resources(Resources) | Define the resources to be created and their properties<ul><li>the only required element in the template</li></ul> |
| Parameter(Parameters) | Define input values received from external sources when creating or updating a stack<ul><li>Used when reusing the same template across environments</li></ul> |
| Result Output (Outputs) | Define values to be exposed externally as a result of stack creation<ul><li>If you specify an export name, it can be referenced from other stacks</li></ul> |
| built-in function | A function used to reference or combine values within a template |
| Mapping (Mappings) | A table that maps values in a key-value format<ul><li>used to branch values by region and environment</li></ul> |
| Conditions(Conditions) | A logical expression that controls the creation and attributes of a resource based on specific conditions |
| Rules (Rules) | Rules for validating parameter values entered when creating or updating a stack |
| Metadata (Metadata) | Additional information about the template |

_Table. Template components_


Refer to [Template Management](/en/userguide/management/infrastructure_builder/how_to_guides/template/#write) for how to write each element.

Each resource is identified by a logical ID within the template. A logical ID is the name that refers to a resource within a stack, and after deployment, the actual created resource is identified by a physical ID.

> **Caution**: If you change the logical ID of a resource in an already deployed stack, the existing resource may be deleted and a new resource may be created. Check the change type with the change set before modifying the logical ID.

# Template storage location {#location}

The template can be specified as follows.


| Category | Explanation |
|---------|--------|
| Object Storage URL | Specify the URL of the template stored in Object Storage<ul><li>The template at deployment time is fixed, allowing the same results to be reproduced</li></ul><ul><li>Required when using nested stacks</li></ul> |
| File upload | Upload and use a local template file<ul><li>The uploaded template is stored in Object Storage regardless of its size</li></ul> |
| Write in the console | After writing and reviewing a template directly in the Console, creating it stores the template in Object Storage. |

_Table. Template storage location_


If you store the template in Object Storage, a specific object is locked to a specific version, so the template at deployment time does not change. This allows the same definition to be reused during rollback or audit.

When Infrastructure Builder stores templates or stack policies in Object Storage, it creates and uses one bucket of the following format for each account and region.

* Bucket name: `ib-templates-{random string 12 characters}-{region}`
* Templates and stack policies stored in the same account and region are all saved in this bucket.
* Buckets are created in the user's account, so Object Storage charges apply to the bucket and stored files.
* Deleting a bucket or files stored in a bucket does not affect existing stacks, change sets, or drift detection. If you delete the bucket, it will be recreated when you next save a template or stack policy.

> **Information**: Since the Infrastructure Builder creates a dedicated bucket in the user's account, the user needs permission to create an Object Storage bucket. If you lack permission, bucket creation will fail, preventing template upload, template creation, and stack policy storage.

> **Reference**: Infrastructure Builder retrieves the template from Object Storage based on the logged-in user's credentials (IAM permissions). Therefore, if a bucket policy or access control is applied, the user performing the operation must have read permission for that bucket.

# Nested Stack {#nested-stack}

A nested stack is a structure in which one stack invokes another stack to create it. When the template becomes large and difficult to manage, you can separate and organize the template by functional units.

A stack that calls a lower stack from the top level is called a root stack, and the root stack is responsible for assembling each nested stack.

For example, a three-tier architecture can be separated as follows.


```text
Root stack
 ├─ Network stack (VPC, Subnet)
 ├─ Security stack (Security Group, IAM)
 ├─ Application Stack (Virtual Server, Load Balancer)
 └─ Storage Stack (Bucket)
```

_Code block. Example of nested stack configuration._

When using nested stacks, keep the following points in mind.

* Values cannot be directly referenced between stacks. Pass values as parameters from the parent stack to the child stack, and pass values as output results from the child stack back to the parent stack.
* When referencing the result output of a child stack, inter-stack dependencies are handled automatically, causing the referenced stack to be created first.
* If a child stack fails, the parent stack is also treated as failed.
* Nested stacks can be configured up to 5 levels.
* Since each nested stack's template is referenced by URL, it must be stored in Object Storage.

> **Reference**: By using nested stacks, you can make independent changes at the functional level, such as modifying only the network configuration or updating only the application configuration.

# Export {#export}

Export is a feature that shares a stack's result output so it can be reused in another stack. If you define an export name in the output, you can reference that value from other stacks in the same account and region.

While a nested stack passes values between the parent and child stacks, an export shares values between independent stacks.

Exports that are referenced in another stack cannot be deleted or modified. To modify or delete a stack that defines an export, first remove the reference to that export from any stack that references it.
