Skip to content

Can't use the variables defined in AWS OpsWorks console #26

@diegodurante

Description

@diegodurante

Now in AWS is possible to define environment variables directly inside the AWS OpsWorks console.
To do that we have to go to "Apps" section and click on the actions "edit" related to our app.
Then, under "Environment Variables" we can declare all env variables we need.

These variables are passed to Chef inside the JSON and we can refer to them with: deploy[:environment_variables]

To let this recipe works both with deploy[:environment_variables] and variables passed with a custom JSON (like this documentation says) I changed a bit the write_config.rb file.

recipes/write_config.rb now is:

node[:deploy].each do |application, deploy|
  environment_variables = deploy[:custom_env].to_h.merge(deploy[:environment_variables].to_h)

  custom_env_template do
    application application
    deploy deploy
    env environment_variables
  end
end

Where my custom JSON is:

{
  "deploy" : {
    "app_name" : {
      "symlink_before_migrate" : {
        "config/application.yml": "config/application.yml"
      },
      "custom_env" : {
        "ENV1" : "foobar",
        "ENV2" : "barfoo"
      }
    }
  }
}

@joeyAghion what do you think about this change?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions