Passing yaml config file to submodule


I hope someone could help me out here or at least point me in the right direction.

here is the structure of my project

folder project-foo

- workspaces:
    - name: foo-test-dev
      execution_mode: local
        - team_name: foo-bar
          type: restricted

module "workspaces" {
  source                  = "../workspace/"
  workspaces_config_file  = "./configs/permissions.yaml"

folder workspace

locals {
  config      = flatten(yamldecode(file(var.workspaces_config_file)))

  workspaces = flatten([for x in local.config : [for w in x.workspaces : w]])

  workspace_config = flatten([
    for w in local.workspaces : {
      terraform_version = try(w.terraform_version, null)
      execution_mode    = try(w.execution_mode, null)

I am getting the following error

│ Error: Unsupported attribute
│   on ../workspace/ line 5, in locals:
│    5:   workspaces = flatten([for x in local.config : [for w in x.workspaces : w]])
│ This object does not have an attribute named "workspaces".

I am assuming I am not passing the config files the right way, although it’s not complaining about not being able to find the files.

You’ve said your file is called workspace.yaml

but you’ve referenced a file called permissions.yaml

Separately, you appear to be habitually using flatten() all over the place, which IMO is adds confusion. It looks to me like two out of your three flatten() calls are unnecessary and pass through the value unchanged, so I would remove them, personally.

Sorry was just a typo as I have multiple files, however I am calling the right file.

I understand I use flatten a bit too often, however I want to get everything working first then I will refactor.

Please don’t think I am disregarding your feedback, I am just trying to work out what is causing my problem or if I am passing the file correctly.

If that is true, then what you have posted in this topic, fails to demonstrate the problem you are experiencing.

I copy/pasted into local files, and it ran successfully.

Just to confirm as mentioned in my first post.

I have module called workspace that is outside my project called project-foo and I am sourcing it as below

As you can see from the error message,

A. It’s not complaining that it can’t find the file, it seems like the error is with this line

Thanks again

I repeat: I copy/pasted your stated configuration into local files and it ran successfully.

No-one can help you if you are accidentally fixing your problem in the process of simplifying it for posting.

Probably the best thing you could do now is to publish a Git repository on Github that actually reproduces your error, and provide the link here.

@maxb Thanks, I worked it out, and honestly 90% of my problems are when I refactor, I seem to always leave something out.

:man_facepalming: I was calling the wrong files in other places…