Hi all! Please help. How can I determine dependenc...
# atmos
p
Hi all! Please help. How can I determine dependencies in another Stack if I have a custom name.template in atmos.yaml:
Copy code
name_template: "{{.settings.context.tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}"`
āœ… 1
From docs:
Copy code
components:
  terraform:
    top-level-component1:
      settings:
        depends_on:
          1:
            # If the `context` (namespace, tenant, environment, stage) is not provided,
            # the `component` is from the same Atmos stack as this component
            component: "test/test-component-override"
          2:
            # This component (in any stage) depends on `test/test-component`
            # from the `dev` stage (in any `environment` and any `tenant`)
            component: "test/test-component"
            stage: "dev"
          3:
            # This component depends on `my-component`
            # from the `tenant1-ue2-staging` Atmos stack
            component: "my-component"
            tenant: "tenant1"
            environment: "ue2"
            stage: "staging"
Would it works?
Copy code
depends_on:
          2:
            component: "test/test-component"
            .settings.context.tenant: "tenant1"
a
on which tenant do you want the component to depend on?
Copy code
depends_on:
          2:
            component: "test/test-component"
p
its different tenants
Copy code
blabla: tenant2
depends_on:
          2:
            component: "test/test-component"
            .settings.context.tenant: "tenant1"
a
if you don't specify
tenant
in
depends_on
, it will be from the current stack (which means if you want it from the current stack, you don't need to specify it)
if you want that depends_on component to be from a diff tenant, you specify it in
tenant
Copy code
depends_on:
          2:
            component: "test/test-component"
            tenant: "........"
the problem here is that
depends_on
uses
vars
to detect the
tenant
, not
settings
(as you have in
name_template: "{{.settings.context.tenant}}
)
it looks like what you want is: instead of
tenant
(and other "hardcoded" attributes, you want to use any possible values for the keys from
{{.settings.context.tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
(and in a general case, from any Atmos section)
p
I would like to separate stack detection from the variables var.tenant and var.subscription, as we often use them in modules, but they may not match what we pass to atmos.
it looks like what you want is: instead of
tenant
(and other "hardcoded" attributes, you want to use any possible values for the keys from
{{.settings.context.tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
(and in a general case, from any Atmos section)
Yes, that would be just great!
a
what exactly do you want to use for in
Copy code
depends_on:
          2:
            component: "test/test-component"
e.g. the component
test/test-component
is from one of the values in
{{.settings.context.tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
it's even painfull to think about šŸ™‚ we usually say "depends on this component from the same stack" or "depends on this component from the account xxxx" or "depends on this component from the region yyyyy"
p
I can give an example of my stack structure if necessary.
I understand, but I would like some flexibility in this regard. We have an established structure.
a
but in this generic case, we need to be able to say "depends on this component from ... any possible attribute in
.settings.context
p
Yes, that's right.
Is it difficult to implement?
I can do feature request if it possible)
a
it's difficult to implement b/c the "keys are dynamic", meaning they can be anuthing
but...
we can add
Copy code
depends_on:
          2:
            component: "test/test-component"
            stack: tenantABC-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
we can add
stack
as another field (instead of breaking it down to parts), and would be able to use the full expression for stacks with some parts "hardcoded" (bc/ obviously, w/o hardcoding at least one value, it will mean the current stack)
p
Copy code
ā”œā”€ā”€ stacks
│   ā”œā”€ā”€ networks.yaml
│   ā”œā”€ā”€ orgs
│   │   ā”œā”€ā”€ organization1
│   │   │   ā”œā”€ā”€ _defaults.yaml
│   │   │   ā”œā”€ā”€ dev
│   │   │   │   ā”œā”€ā”€ aks-us-3
│   │   │   │   │   ā”œā”€ā”€ aks.yaml
│   │   │   │   │   ā”œā”€ā”€ kubeflow.yaml
│   │   │   │   ā”œā”€ā”€ _defaults.yaml
│   │   │   │   └── stn-us-1
│   │   │   │       └── main.yaml
│   │   │   └── prod
│   │   │       ā”œā”€ā”€ aks-us-2
│   │   │       │   ā”œā”€ā”€ aks.yaml
│   │   │       │   └── webrdr.yaml
│   │   │       ā”œā”€ā”€ aks-us-3
│   │   │       │   ā”œā”€ā”€ aks.yaml
│   │   │       │   ā”œā”€ā”€ artifacts.yaml
│   │   │       ā”œā”€ā”€ _defaults.yaml
│   │   │       └── stn-us-1
│   │   │           └── main.yaml
│   │   └── _defaults.yaml
a
i think this would work for you
Copy code
depends_on:
          2:
            component: "test/test-component"
            stack: tenantABC-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
p
This is the structure that makes it necessary to specify a custom name.template.
OMG! Sounds good!
I'll check it now
a
stack
is not implemented yet šŸ˜ž
we can implement it
p
oh ok
a
@Gabriela Campana (Cloud Posse) please create a task for Atmos
Copy code
Add support for `stack` as one of the context keys in `depends_on`
āœ… 1
p
Will it be possible to specify the tenant through the settings?
Copy code
depends_on:
          2:
            component: "test/test-component"
            stack: {{.settings.context.tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
I can do feature request in the GitHub repo
a
> Will it be possible to specify the tenant through the settings? In general, yes. Since those are templates, you could reference any Atmos sections and attributes inside the sections. In practice, specifying the tenant through the settings would mean the same tenant as the current component (since we execute the templates in
depends_on
on the current component, not on the dependent component). You would be able to add any other field to
settings.context
, e.g.
settings.context.depends_on_tenant
and then use it like this
Copy code
depends_on:
          2:
            component: "test/test-component"
            stack: {{.settings.context.depends_on_tenant}}-{{.settings.context.env}}-{{.settings.context.resource.name}}-{{.settings.context.region}}-{{.settings.context.resource.number}}
p
Ok thanx!
Feature request
I made duplicate from oher account, sorry)
np 1
g
a
p
Thanx a lot! It works!
šŸš€ 2