Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
diegodurante opened this issue Mar 11, 2016 · 2 comments
Open

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

diegodurante opened this issue Mar 11, 2016 · 2 comments

Comments

@diegodurante
Copy link

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?

@joeyAghion
Copy link
Owner

Out of curiosity, why do you want to combine the built-in environment support with this cookbook? If the built-in support works for your needs, maybe you don't need this? I built this cookbook before that support was available. When I tried to switch my apps to use the built-in version, I ran into problems (such as with the number of supported environment variables being limited).

Also, your code example changes the prescribed JSON location for custom environment values (from custom_env.app_name to deploy.app_name.custom_env). This is a fine location, but represents a breaking change with how the cookbook worked in the past. It's fine for you to use that, but I wouldn't want to merge that into this repo. Feel free to make a pull request in any case if you'd like more detailed feedback.

@diegodurante
Copy link
Author

Because without this cookbook the environment variables declared in AWS console built-in support are not available for my rails app!

The built-in support just allow to provide variables to Chef recipes, but then we need to handle this variables in someway to let's our app to use it.

You said that:

When I tried to switch my apps to use the built-in version, I ran into problems (such as with the number of supported environment variables being limited).

That was the past. Now as the official documentation says:
There is no specific limit on the number of environment variables.

About the custom JSON, is just a way as I prefer to access to it. Never mind about that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants