Hello, is the `--chdir` flag working as expected?...
# atmos
a
Hello, is the
--chdir
flag working as expected? pwd:
repository-name/components/terraform/dynamodb
atmos --chdir full/path/to/repository-name terraform generate varfile -s foo-stack foo-component
āœ… works
atmos --chdir full/path/to/repository-name terraform plan -s foo-stack foo-component
🟄 fails with:
The  atmos.yaml  CLI config file was not found.
ls -ls  full/path/to/repository-name
atmos.yaml here
e
I use the
--chdir
flag extensively everyday (implemented it so that I could test atmos easier across multiple codebases)
where is your
atmos.yaml
?
a
it is in here:
full/path/to/repository-name/atmos.yaml
e
what happens if you run with
--logs-level=Debug
a
checking
Copy code
DEBU Set logs-level=debug logs-file=/dev/stderr
DEBU 'atmos.yaml' CLI config was not found paths="system dir, home dir, current dir, ENV vars"
DEBU Refer to https://atmos.tools/cli/configuration for details on how to configure 'atmos.yaml'
DEBU Using the default CLI config
Copy code
repo-name
ā”œā”€ā”€ atmos.yaml
ā”œā”€ā”€ components
│   └── terraform
│       └── dynamodb <---- I'm running the command from there, with atmos --chdir ../../../repo-name/ 
└── stacks
    ā”œā”€ā”€ catalog
    ā”œā”€ā”€ mixins
    │   ā”œā”€ā”€ environment
    │   └── region
    └── orgs
        └── foo
            └── something
e
just to try to figure out what's going on, can you try using an absolute path instead of a relative path like ../../../repo-name?
a
sure
e
Also, if you run Atmos anywhere within a Git repository, it automatically resolves the location of the
atmos.yml
So I just want to make sure that the reason you're using
--chdir
is for the appropriate reason.
a
Copy code
atmos --chdir ../../../repo-name/ -- fails
atmos --chdir /Users/albertorm95/Projects/repo-name/ -- fails
The reason I'm trying to change dir is because Atlantis starts its process in the root directory of terraform, in this case will be in the
dynamodb
dir I'm doing
cd
to the
repo-name/
path where the
atmos.yaml
is in order for it to work
Also, if you run Atmos anywhere within a Git repository, it automatically resolves the location of the
atmos.yml
This is not happening, if I move to any dir and run
atmos list stacks
for example, it ask for the
atmos.yaml
e
what version of atmos?
a
Atmos 1.196.0 on darwin/arm64
e
Copy code
atmos --chdir $(pwd) describe config
What happens if you go to the root of your repository where the atmos.yaml is and run this command?
a
I got a long json, do you need something in particual?
Copy code
"base_path": "",
  "components": {
    "terraform": {
      "base_path": "components/terraform",
e
Well, what's interesting about it is you're not getting that error. I'm still trying to figure out how we triage this.
What if you run that same command describe config from the other directory where you're getting the error?
šŸ‘€ 1
a
"cli_config_path": "/Users/alberto.rojas/Projects/repo-name",
it does work when changing dir, btw, just to clarify, this is happening when
terraform plan
the other commands looks to be working
e
Okay, wait, taking a step back. I think I might understand. It's only affecting Terraform plan. That's helpful.
a
yes, hehe
atmos --chdir full/path/to/repository-name terraform plan -s foo-stack foo-component
🟄 fails with:
The  atmos.yaml  CLI config file was not found.
e
Aha, okay. Then let me see if I can create a test to reproduce that, and we'll look into seeing if that's confirmed.
a
really appreciated! šŸ™‚
e
I was able to reproduce this.
šŸ™Œ 1
This is why we are doing this refactoring to avoid these kinds of issues. That said, we will patch this up before then, and I'll post a PR here when it's ready.
šŸ™Œ 1
a
Thanks you so much! šŸ˜„
e
a
let me try that
I tried it, and it failed differently:
atmos --chdir full/path/to/repository-name terraform plan -s foo-stack foo-component
Copy code
Error 

 invalid component: Could not find the component  terraform  in the stack  foo-stack .
 Check that all the context variables are correctly defined in the stack manifests.
 Are the component and stack names correct? Did you forget an import?
atmos --chdir full/path/to/repository-name list stacks
and
atmos --chdir full/path/to/repository-name list components
Works
e
can you confirm the stack configuration AND component exist within the
chdir
location?
in otherwords,
--chdir
is like :
Copy code
cd $CHDIR
atmnos terraform ...

# And the following should be true
ls -l path/to/my/components
ls -l atmos.yaml
ls -l stacks/mystack.yaml
(so it works like
git -C
and
make -C
)
a
šŸ¤”
the
chdir
location is
Copy code
repo-name <---- HERE
ā”œā”€ā”€ atmos.yaml
ā”œā”€ā”€ components
│   └── terraform
│       └── dynamodb <---- I'm running the command from there, with atmos --chdir full/path/to/repo-name/
└── stacks
    ā”œā”€ā”€ catalog
    ā”œā”€ā”€ mixins
    │   ā”œā”€ā”€ environment
    │   └── region
    └── orgs
        └── foo
            └── something
šŸ‘ 1
e
so a few more questions.
šŸ‘ 1
running from repo-name/compoennts/terraform/dynamodb - this shouldn't need
--chdir
(although this should totally work, this is not the use case that it was designed for, because this is supported automatically in Atmos, provided you're running inside of a Git repository) we resolve the location of the root of the repository automatically at runtime and look for Atmos at that root. Everything is based on that root. This makes me think that there might be other configuration problems, but without looking at the configs, it's hard to say.
Are you running this inside of a Git repository?
are you setting any base-path settings in
atmos.yaml
a
yes, it is a git repo. no, no base-path setting
e
If you don't specify the
--chdir
, what error do you get?
a
running this: pwd:
repository-name/components/terraform/dynamodb
atmos terraform plan -s foo-stack foo-component
Copy code
## Missing Configuration

 The  atmos.yaml  CLI config file was not found.

 The default Atmos stacks directory is set to  stacks , but the directory does not exist in the current path.
ā˜¹ļø
e
This is just so freaking weird. Would you be open to doing a screen share this week or something? Maybe we can look into it.
a)
--chdir
shouldn't even be needed
b) using
--chdir
gives you an unexpected outcome.
a
so you cannot longer replicate this scenario with the code changes in the PR?
e
Let me try one more thing.
šŸ‘ 1
would you happen to be doing a
git clone
inside of this repository, meaning that you have multiple git clones inside of git clones.
e.g. more than one
.git
folder
a
I only have one .git in my repo
e
are you using git worktrees?
a
no, I think I'm not doing anything weird, I'm in main branch
I ran this with Debug - https://sweetops.slack.com/archives/C031919U8A0/p1762296827857399?thread_ts=1762281109.329649&cid=C031919U8A0
Copy code
DEBU Set logs-level=debug logs-file=/dev/stderr
DEBU ProcessCommandLineArgs input componentType=terraform args="[terraform plan -s foo-stack foo-component --logs-level=Debug]"
DEBU After ParseFlags identity.Value="" identity.Changed=false
DEBU Set using command line argument --logs-level=Debug
e
So loading the Atmos config from the repo root looks like it was lost in probably one of the refactors that we did early on, decomposing that implementation into smaller pull requests. As a result, that isn't working. Also, a spiritual regression, if you will, meaning that it was intended to be there but isn't. So I'm going to fix that as well.
but the chdir issue you have, is confirmed to be broken in 1.196.0, but this PR addresses that issue with the Packer, Helm file, and Terraform commands. I'm going to continue trying to reproduce it and see what I can find. Since you have clearly pointed out a couple issues.
šŸ‘ 1
in your `atmos.yaml`: what if you set:
Copy code
base_path: !repo-root
a
Copy code
Error 

 invalid component: Could not find the component  terraform  in the stack  foo-stack .
 Check that all the context variables are correctly defined in the stack manifests.
 Are the component and stack names correct? Did you forget an import?
same error, that with you branch atmos version
e
We don't have a YAML JSON schema for the Atmos.yaml.
šŸ‘ 1
(it is planned, but no ETA)
a
Still same error
e
aha, of course, it's a catch-22
and if you set
ATMOS_BASE_PATH=full/path/to/repository-name
does that work? My assertion is then it discovers where the Atmos config is, and then everything else starts to work, even though that is not the intended fix.
a
No, it didn't work: With your version:
invalid component: Could not find the component  plan  in the stack  foo-stack .
With 1.196.0:
invalid component: Could not find the component  terraform  in the stack  foo-stack .
e
the branch is currently unstable
a
let me know if there is something else I can help with
e
Please try 1.198.0
a
šŸŖ„ Thanks! working now!
e
Thanks for reporting the issue!