Skip to content

Commit fee7f1e

Browse files
feat(config): dbt-env selects the local dbt target when a profile is configured
1 parent bf4b029 commit fee7f1e

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/g3dt/cli/config_cmds.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ def dbt_env(
219219
"G3DT_S3_GOLD_DATA_DIR": f"s3://{rc.get('buckets/rawGold')}/dbt/",
220220
}
221221
if profile:
222+
# A named profile means a laptop run: select the dbt target that
223+
# carries aws_profile_name (CodeBuild/EC2 stay on `default`, ambient).
222224
values["G3DT_AWS_PROFILE"] = profile
225+
values["G3DT_DBT_TARGET"] = "local"
223226
for key, value in values.items():
224227
if value is not None:
225228
typer.echo(f"export {key}={shlex.quote(str(value))}")

tests/test_release_cmds.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,5 +170,35 @@ def test_config_dbt_env_emits_every_dbt_setting():
170170
assert "export G3DT_DB_RAW_GOLD=etl_test_raw_gold_db" in out
171171
assert f"export G3DT_S3_SILVER_DATA_DIR=s3://etl-test-raw-silver-{ACCOUNT}-{REGION}/dbt/" in out
172172
assert f"export G3DT_S3_GOLD_DATA_DIR=s3://etl-test-raw-gold-{ACCOUNT}-{REGION}/dbt/" in out
173-
# no profile configured -> no G3DT_AWS_PROFILE line (ambient credentials)
173+
# no profile configured -> ambient credentials and the default dbt target
174174
assert "G3DT_AWS_PROFILE" not in out
175+
assert "G3DT_DBT_TARGET" not in out
176+
177+
178+
@mock_aws
179+
def test_config_dbt_env_selects_local_target_with_profile(tmp_path, monkeypatch):
180+
"""
181+
Inputs: a marker whose profiles: map covers the env
182+
Expected Output: dbt-env additionally exports G3DT_AWS_PROFILE and
183+
G3DT_DBT_TARGET=local, selecting the profiles.yml target that carries
184+
aws_profile_name — so a laptop run authenticates with the named profile
185+
while CodeBuild (no profiles map) stays on ambient credentials.
186+
"""
187+
marker = tmp_path / "g3dt.yaml"
188+
marker.write_text(
189+
"project: etl\nregion: ap-southeast-2\nprofiles:\n test: etl_test\n"
190+
)
191+
monkeypatch.setenv("G3DT_MARKER", str(marker))
192+
creds = tmp_path / "aws_credentials"
193+
creds.write_text(
194+
"[etl_test]\naws_access_key_id = testing\naws_secret_access_key = testing\n"
195+
)
196+
monkeypatch.setenv("AWS_SHARED_CREDENTIALS_FILE", str(creds))
197+
config._load_yaml_cached.cache_clear()
198+
resolver.resolve.cache_clear()
199+
200+
_seed()
201+
result = runner.invoke(app, ["config", "dbt-env", "--env", "test"])
202+
assert result.exit_code == 0, result.output
203+
assert "export G3DT_AWS_PROFILE=etl_test" in result.output
204+
assert "export G3DT_DBT_TARGET=local" in result.output

0 commit comments

Comments
 (0)