> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formae.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a target

> Register a cloud account and region with formae so it can deploy there and discover what already exists.

A target is the cloud account and region formae works in. You need at least one
before you can deploy resources or [discover](/documentation/concepts/discovery)
what is already there, so it is usually the first thing you set up. formae learns
about a target when you declare it in a forma and apply it. A target is just
another thing you describe in code, registered the moment you apply.

<Note>
  **Before you start:** the formae agent needs credentials for the account you are
  targeting, and you need a formae project (a `PklProject` with the schema
  dependencies). Starting fresh? Run `formae project init`, or follow
  [Write your first forma](/documentation/get-started/write-your-first-forma).
</Note>

<Tabs>
  <Tab title="CLI">
    <Steps>
      <Step title="Declare the target">
        A target lives in a forma, with a label and a provider `config`. Each
        cloud has its own config type, so pick yours:

        <Tabs>
          <Tab title="AWS">
            ```kotlin theme={"languages":{"custom":["/languages/pkl.json"]}}
            amends "@formae/forma.pkl"
            import "@formae/formae.pkl"
            import "@aws/aws.pkl"

            forma {
              new formae.Target {
                label = "prod-us-west-2"
                config = new aws.Config {
                  region = "us-west-2"
                }
              }
            }
            ```
          </Tab>

          <Tab title="Azure">
            ```kotlin theme={"languages":{"custom":["/languages/pkl.json"]}}
            amends "@formae/forma.pkl"
            import "@formae/formae.pkl"
            import "@azure/azure.pkl"

            forma {
              new formae.Target {
                label = "prod-azure"
                config = new azure.Config {
                  subscriptionId = "your-subscription-id"
                }
              }
            }
            ```
          </Tab>

          <Tab title="GCP">
            ```kotlin theme={"languages":{"custom":["/languages/pkl.json"]}}
            amends "@formae/forma.pkl"
            import "@formae/formae.pkl"
            import "@gcp/gcp.pkl"

            forma {
              new formae.Target {
                label = "prod-gcp"
                config = new gcp.Config {
                  project = "your-project-id"
                  region = "us-central1"
                }
              }
            }
            ```
          </Tab>
        </Tabs>

        The `label` is how you refer to the target from resources and on the CLI;
        `config` carries the provider settings. Targets are discoverable by
        default, which is what lets formae scan them for existing resources. Add
        `discoverable = false` to make a target deploy-only.
      </Step>

      <Step title="Apply it">
        ```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
        formae apply --mode reconcile target.pkl
        ```

        formae shows the plan and asks you to confirm:

        <div className="fa-term">
          <div className="fa-term-body">  <span style={{color:'rgb(232,232,232)',fontWeight:'600'}}>formae</span> <span style={{color:'rgb(255,133,51)',fontWeight:'600'}}>apply · reconcile</span>                                                                        target.pkl<br /><span style={{color:'rgb(232,232,232)',fontWeight:'600'}} /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(85,85,102)'}} />  <span style={{color:'rgb(232,232,232)'}}>+</span> 1 <span style={{color:'rgb(232,232,232)'}}>create</span><br /><br />  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(255,133,51)',fontWeight:'600'}}>▌ Targets</span><br />  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(232,232,232)',fontWeight:'600'}} /><span style={{color:'rgb(232,232,232)',fontWeight:'600'}}>Operation ▲   </span><span style={{color:'rgb(170,170,170)'}}>Label</span><br />  <span style={{color:'rgb(232,232,232)'}}>+ create      prod-us-west-2</span><br /><br /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(85,85,102)'}} />  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>↑↓</span><span style={{color:'rgb(153,153,153)'}}>: select</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>space</span><span style={{color:'rgb(153,153,153)'}}>: expand</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>→←</span><span style={{color:'rgb(153,153,153)'}}>: column</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>s</span><span style={{color:'rgb(153,153,153)'}}>: sort</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>y</span><span style={{color:'rgb(153,153,153)'}}>: confirm</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>q</span><span style={{color:'rgb(153,153,153)'}}>: abort</span> This operation will create 1<br />target(s).  Do you want to continue? (y/N)  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>?</span><span style={{color:'rgb(153,153,153)'}}>: help</span></div>
        </div>

        On confirmation it registers the target. No cloud resources are created: a
        target is a destination, not infrastructure. Because it is discoverable,
        formae also starts scanning the account for resources you can later bring
        under management.
      </Step>

      <Step title="Verify">
        ```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
        formae inventory targets
        ```

        Your new target appears in the list:

        <div className="fa-term">
          <div className="fa-term-body">  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(232,232,232)',fontWeight:'600'}}>formae</span> <span style={{fontWeight:'600'}} /><span style={{color:'rgb(255,133,51)',fontWeight:'600'}}>inventory</span><br /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(85,85,102)'}} />                <span style={{color:'rgb(129,209,219)'}}>╭───────────╮</span><br /> <span style={{color:'rgb(170,170,170)'}}> 1 Resources </span>  <span style={{color:'rgb(129,209,219)'}}>│</span><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}> 2 Targets </span><span style={{color:'rgb(129,209,219)'}}>│</span>  <span style={{color:'rgb(170,170,170)'}}> 3 Stacks </span>  <span style={{color:'rgb(170,170,170)'}}> 4 Policies </span><br /><span style={{color:'rgb(129,209,219)'}}>────────────────╯           ╰───────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(129,209,219)'}} /><br /><span style={{color:'rgb(129,209,219)'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}} /><span style={{color:'rgb(232,232,232)',fontWeight:'600'}}>Label ▲                   </span><span style={{color:'rgb(170,170,170)',fontWeight:'600'}}>Namespace              Discoverable    Config                                         </span><br /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(232,232,232)'}} /><span style={{color:'rgb(232,232,232)'}}>prod-us-west-2            AWS                    </span><span style={{color:'rgb(129,209,219)'}}>yes</span>             <span style={{color:'rgb(232,232,232)'}}>Region: us-west-2, Type: AWS                   </span><br /><br />Showing 1 of 1 targets<br /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(85,85,102)'}} />  <span style={{color:'rgb(153,153,153)'}}>/: query</span><br /><span style={{color:'rgb(85,85,102)'}}>────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────</span><br /><span style={{color:'rgb(85,85,102)'}} />  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>↑↓/j/k</span><span style={{color:'rgb(153,153,153)'}}>: navigate</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>enter</span><span style={{color:'rgb(153,153,153)'}}>: detail</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>/</span><span style={{color:'rgb(153,153,153)'}}>: search</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>s</span><span style={{color:'rgb(153,153,153)'}}>: sort</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>r</span><span style={{color:'rgb(153,153,153)'}}>: refresh</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>1-4</span><span style={{color:'rgb(153,153,153)'}}>: tab</span>  <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>q</span><span style={{color:'rgb(153,153,153)'}}>: quit</span>                           <span style={{fontWeight:'600'}} /><span style={{color:'rgb(129,209,219)',fontWeight:'600'}}>?</span><span style={{color:'rgb(153,153,153)'}}>: help</span></div>
        </div>

        Filter if you have many:

        ```bash theme={"languages":{"custom":["/languages/pkl.json"]}}
        formae inventory targets --query="discoverable:true"
        ```
      </Step>
    </Steps>
  </Tab>

  <Tab title="AI assistants">
    With the [formae MCP plugin](/documentation/guides/ai-coding-assistants)
    connected, you describe the target you want and let the assistant write and
    apply the forma:

    <div className="fa-convo">
      <div className="fa-convo-head">Conversation</div>
      <div className="fa-turn fa-you"><div className="fa-tag">You</div><div className="fa-body">Set up an AWS target in us-west-2.</div></div>
      <div className="fa-turn fa-bot"><div className="fa-tag">Assistant</div><div className="fa-body">I'll add a target <code>prod-us-west-2</code> for AWS <code>us-west-2</code> and simulate first: it creates one target, discoverable, and no cloud resources. Because it's discoverable, formae will then scan <code>us-west-2</code> for existing resources. Apply it?</div></div>
      <div className="fa-turn fa-you"><div className="fa-tag">You</div><div className="fa-body">Yes.</div></div>
      <div className="fa-turn fa-bot"><div className="fa-tag">Assistant</div><div className="fa-body">Done. <code>prod-us-west-2</code> is registered and discoverable, and discovery is scanning it now. Once it finishes I can show you what's there to bring under management.</div></div>
    </div>

    The assistant writes the same forma you would by hand, simulates it, and
    applies on your confirmation. Ask it to make a target deploy-only
    (`discoverable = false`) or to add more regions in one go.
  </Tab>
</Tabs>

## See also

* [Target](/documentation/concepts/target): what a target is and how it relates to stacks and resources.
* [Discovery](/documentation/concepts/discovery): how formae finds existing resources once a target is discoverable.
* [Bring resources under management](/documentation/guides/bring-resources-under-management): adopt what discovery finds.
