Repository: dbt-labs/dbt-core

Issue:
[CT-569] [Feature] Allow profile_template to prompt and name a `target`
### Is this your first time opening an issue?

- [X] I have read the [expectations for open source contributors](https://docs.getdbt.com/docs/contributing/oss-expectations)

### Describe the Feature

I'm not 100% sure if this is or isn't yet an option, but I didn't find it anywhere online in searching.

It'd be nice if `profile_template.yml` allowed to set the `target` name, like so:

```yaml
prompts:
  target:
    type: string
    hint: the target name
```

or, 

```yaml
fixed:
    target: somethig_here
```

### Describe alternatives you've considered

_No response_

### Who will this benefit?

_No response_

### Are you interested in contributing this feature?

_No response_

### Anything else?

_No response_


Discussion:
@alexrosenfeld10 Right on! I think this would be a self-contained change, and probably a simple one:
https://github.com/dbt-labs/dbt-core/blob/f633e9936f62702a59fa661d261caaff9cefbe92/core/dbt/task/init.py#L187-L189

It might look like inspecting the output of `generate_target_from_input`, and if `target` is among the prompts provided, pulling it up to be the higher-level key (instead of the default `dev`).

Is this something you might be interested in contributing?

There's just one tricky piece of this, which will be writing an automated test. We need to refactor and convert the tests for `init` behavior (https://github.com/dbt-labs/dbt-core/issues/5180) to account for some changes to `mypy` (https://github.com/dbt-labs/dbt-core/pull/5171). As long as there's a test case recorded in there, to be converted along with the rest of `040_init_tests`, that should be fine.

Resolving patch:
diff --git a/core/dbt/task/init.py b/core/dbt/task/init.py
--- a/core/dbt/task/init.py
+++ b/core/dbt/task/init.py
@@ -186,7 +186,8 @@ def create_profile_from_profile_template(self, profile_template: dict, profile_n
         initial_target = profile_template.get("fixed", {})
         prompts = profile_template.get("prompts", {})
         target = self.generate_target_from_input(prompts, initial_target)
-        profile = {"outputs": {"dev": target}, "target": "dev"}
+        target_name = target.pop("target", "dev")
+        profile = {"outputs": {target_name: target}, "target": target_name}
         self.write_profile(profile, profile_name)
 
     def create_profile_from_target(self, adapter: str, profile_name: str):
diff --git a/plugins/postgres/setup.py b/plugins/postgres/setup.py
--- a/plugins/postgres/setup.py
+++ b/plugins/postgres/setup.py
@@ -42,7 +42,7 @@ def _dbt_psycopg2_name():
 
 package_name = "dbt-postgres"
 package_version = "1.2.0a1"
-description = """The postgres adpter plugin for dbt (data build tool)"""
+description = """The postgres adapter plugin for dbt (data build tool)"""
 
 this_directory = os.path.abspath(os.path.dirname(__file__))
 with open(os.path.join(this_directory, "README.md")) as f:


Test patch:
diff --git a/test/integration/040_init_tests/test_init.py b/test/integration/040_init_tests/test_init.py
--- a/test/integration/040_init_tests/test_init.py
+++ b/test/integration/040_init_tests/test_init.py
@@ -205,7 +205,11 @@ def exists_side_effect(path):
   host: localhost
   dbname: my_db
   schema: my_schema
+  target: my_target
 prompts:
+  target:
+    hint: 'The target name'
+    type: string
   port:
     hint: 'The port (for integer test purposes)'
     type: int
@@ -220,12 +224,14 @@ def exists_side_effect(path):
         manager.attach_mock(mock_prompt, 'prompt')
         manager.attach_mock(mock_confirm, 'confirm')
         manager.prompt.side_effect = [
+            'my_target',
             5432,
             'test_username',
             'test_password'
         ]
         self.run_dbt(['init'])
         manager.assert_has_calls([
+            call.prompt('target (The target name)', default=None, hide_input=False, type=click.STRING),
             call.prompt('port (The port (for integer test purposes))', default=5432, hide_input=False, type=click.INT),
             call.prompt('user (Your username)', default=None, hide_input=False, type=None),
             call.prompt('pass (Your password)', default=None, hide_input=True, type=None)
@@ -234,7 +240,7 @@ def exists_side_effect(path):
         with open(os.path.join(self.test_root_dir, 'profiles.yml'), 'r') as f:
             assert f.read() == """test:
   outputs:
-    dev:
+    my_target:
       dbname: my_db
       host: localhost
       pass: test_password
@@ -243,7 +249,7 @@ def exists_side_effect(path):
       threads: 4
       type: postgres
       user: test_username
-  target: dev
+  target: my_target
 """
 
     @use_profile('postgres')