# juju_machine (Resource)

A resource that represents a Juju machine deployment. Refer to the juju add-machine CLI command for more information and limitations.

## Example Usage

```terraform
resource "juju_machine" "this_machine" {
  model_uuid  = juju_model.development.uuid
  base        = "ubuntu@22.04"
  name        = "this_machine"
  constraints = "tags=my-machine-tag"

  # If you face timeouts destroying machines, add the following lifecycle
  # directive, which instructs Terraform to update any dependent resources
  # before destroying the machine - in the case of applications this means
  # that application units get removed from units before Terraform attempts
  # to destroy the machine.
  lifecycle {
    create_before_destroy = true
  }
}
```

<!-- schema generated by tfplugindocs -->

## Schema

### Required

- `model_uuid` (String) The Juju model’s UUID to specify the model in which to add a new machine. Changing this value will cause the machine to be destroyed and recreated by terraform.

### Optional

- `annotations` (Map of String) Annotations are key/value pairs that can be used to store additional information about the machine. May not contain dots (.) in keys.
- `base` (String) The operating system to install on the new machine(s). E.g. ubuntu@22.04. Changing this value will cause the machine to be destroyed and recreated by terraform.
- `constraints` (String) Machine constraints that overwrite those available from ‘juju get-model-constraints’ and provider’s defaults. Changing this value will cause the application to be destroyed and recreated by terraform.
- `disks` (String) Storage constraints for disks to attach to the machine(s). Changing this value will cause the machine to be destroyed and recreated by terraform.
- `name` (String) A name for the machine resource in Terraform.
- `placement` (String) Additional information about how to allocate the machine in the cloud. Changing this value will cause the application to be destroyed and recreated by terraform.
- `private_key_file` (String) The file path to read the private key from.
- `public_key_file` (String) The file path to read the public key from.
- `ssh_address` (String) The user@host directive for manual provisioning an existing machine via ssh. Requires public_key_file & private_key_file arguments. Changing this value will cause the machine to be destroyed and recreated by terraform.
- `timeouts` (Block, Optional) (see [below for nested schema]())
- `wait_for_hostname` (Boolean) If true, waits for the machine’s hostname to be set during creation. A side effect is that this also waits for the machine to reach ‘active’ state in Juju.

### Read-Only

- `hostname` (String) The machine’s hostname. This is set only if ‘wait_for_hostname’ is true.
- `id` (String) The ID of this resource.
- `instance_id` (String) The provider-specific instance id of the machine Juju creates.
- `machine_id` (String) The id of the machine Juju creates.

<a id="nestedblock--timeouts"></a>

### Nested Schema for `timeouts`

Optional:

- `create` (String) A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) consisting of numbers and unit suffixes, such as “30s” or “2h45m”. Valid time units are “s” (seconds), “m” (minutes), “h” (hours).

### Notes

Juju will automatically remove a machine if all application units deployed to that machine are removed.

## Import

Import is supported using the following syntax:

```shell
# Machines can be imported using the format: `model_uuid:machine_id:machine_name`.
# The value of machine_id is the Juju Machine ID. machine_name is an optional 
# name you can define in Terraform for the machine. It is not used in Juju.
# Here is an example to import a machine from a model with machine ID 1 and a 
# name "machine_one":
$ terraform import juju_machine.machine_one 4ffb2226-6ced-458b-8b38-5143ca190f75:1:machine_one
```
