question
stringlengths
11
28.2k
answer
stringlengths
26
27.7k
tag
stringclasses
130 values
question_id
int64
935
78.4M
score
int64
10
5.49k
I'm not able to find many examples of what a .dockerignore file should look like. Using puppet to install a few packages on a docker container causes the image to explode from 600MB to 3GB. I'm trying to use a .dockerignore file to keep the size to a minumum $ cat Dockerfile FROM centos:centos6 #Work around selinux...
The .dockerignore file is similar to the .gitignore syntax. Here are some example rules: # Ignore a file or directory in the context root named "modules" modules # Ignore any files or directories within the subdirectory named "modules" # in the context root modules/* # Ignore any files or directories in the context ...
Puppet
25,490,911
89
We're planning to use AMI EC2 instances which are not "pre-baked". I.e. when they are spun up, they are bare installs of AWS linux. Our bootstrap process will pull in the various installs that we need e.g. python, tomcat. We'll have min of 3 instances and max of 8. Given these requirements, would using Puppet/Chef be ...
Is there an advantage over CloudInit? Yes, absolutely, many of them! Sure, you can write top to bottom run once CloudInit scripts to provision a server. But what happens when you need to change a configuration file, add a user, update a package, or install a new package? You will end up logging into servers or writing ...
Puppet
11,995,290
87
Given the option between using GPG and OpenSSL for local encryption before pushing archives to an off-site backup location, what are the benefits and drawbacks of each solution? Background: I currently manage a server infrastructure based on Ubuntu 14.04.1 with all current patches applied as they become available. All ...
I would pick GPG for file encryption, it's got decades of secure tested encryption, and is very easy to have multiple "recipients" (backup keys?) or signatures with it's public keys & even servers (if they would be useful). With GPG, all the simple mistakes have been avoided/fixed, it picks a longer "random" key for th...
Puppet
28,247,821
78
In the dark ages, my usual setup for development of LAMP web applications was to test locally on my machine. PHP (in my case), the database and the web server were all installed natively. The server was set up with standard installs of Apache and MySQL, and I had multiple virtual hosts for different parts of the web ap...
Should there be separate Docker containers for the web server (such as Apache), the database server (such as MySQL) and each part of the web application? There is no correct answer to that question. If you will be using Docker in production, then try to run your Docker containers in your development environment as th...
Puppet
26,139,472
71
Here is my naive approach: # puppet/init.pp $x = 'hello ' + 'goodbye' This does not work. How does one concatenate strings in Puppet?
Keyword variable interpolation: $value = "${one}${two}" Source: http://docs.puppetlabs.com/puppet/4.3/reference/lang_variables.html#interpolation Note that although it might work without the curly braces, you should always use them.
Puppet
14,885,263
57
I'm trying to create puppet module which automates installation of zend server CE, this is not important here, but steps are as following update /etc/apt/source.list download repos key via wget do apt-get update do apt-get install zend-server-ce-5.2 I have init.pp file class zendserverce { # https://github.com/puppe...
Since Puppet 2.6.0 a new feature "relationship syntax" was introduced. An example in Puppet 2.6.0 and above would look like this: exec { "apt-update": command => "/usr/bin/apt-get update" } Exec["apt-update"] -> Package <| |> Every time a package command is executed, the dependency (in our case 'apt-update') will...
Puppet
10,845,864
52
I'm learning about puppet and trying to experiment with it on a VM at home. I'm not using a puppet server yet, just running things locally. It works okay, but every time I run puppet apply ..., I get a delay of several seconds, after which it displays the message warning: Could not retrieve fact fqdn I assume the mess...
Since puppet uses the fqdn fact to determine which node it is running as, it may not be possible to run if it can't be determined. Given what you're describing, the simplest thing to debug is facter fqdn instead of your puppet command-line. If the "several seconds" is very close to exactly 5 seconds, it's very likely t...
Puppet
7,780,322
48
I need to create a test user with a password using puppet. I've read that puppet cannot manage user passwords in a generic cross-platform way, which is a pity. I am doing this for Red Hat Enterprise Linux Server release 6.3. I do as follows: user { 'test_user': ensure => present, password => sha1('hello'), } pu...
Linux users have their passwords stored as hash in /etc/shadow file. Puppet passes the password supplied in the user type definition in the /etc/shadow file. Generate your hash password using openssl command: #openssl passwd -1 #Enter your password here Password: Verifying - Password: $1$HTQUGYUGYUGwsxQxCp3F/...
Puppet
19,114,328
38
I'm using puppet to provision a vagrant (ubuntu based) virtual machine. In my script I need to: sudo apt-get build-dep python-lxml I know I can install the apt puppet module so I can use: apt::builddep { 'python-lxml': } But I can't find any reference about installing a module from the script and how to include/requi...
I ran into this problem as well. The trick is to download the modules using a vagrant shell command before the puppet provisioner runs. config.vm.provision :shell do |shell| shell.inline = "mkdir -p /etc/puppet/modules; puppet module install puppetlabs/nodejs; puppet module install...
Puppet
17,508,081
38
I have the following setup: Many different projects which are separate git repositories, but all have mostly the same server configuration Each project in turn depends on many other projects and we use the composer dependency manager to get them together (PHP language here). I want to use Vagrant and include a Vagran...
The following article concerns yet another CM tool (ansible), but I think the author does an excellent job of explaining the benefits of transitioning away from shell scripts. http://devopsu.com/blog/ansible-vs-shell-scripts/ quote 1: What really surprised me was the response from some of these more famous devs. They ...
Puppet
19,879,747
37
When I define(?) a resource e.g. to ensure dir structure, are there any loops available? Like that: for X in [app1,app2] do: file { '/opt/app/' + X: ensure => directory, owner => 'root', group => 'root', mode => '0644', } I have tens of directories and I am really tired with decla...
Older versions of the puppet language have no support for loops. But you can use an array instead of a simple string for the title and declare several resources at the same time with the same params: $b = '/opt/app' file { [ "$b/app1", "$b/app2" ]: ensure => directory, owner => 'root', group => 'root', mode ...
Puppet
6,399,922
37
Recently I started to read about building development environments with virtualization software (I am a beginner) and it seems that 'infrastructure as a code' is a really powerful concept. I really like the workflow structure described here: The same base VirtualBox image is used around the team Vagrant is used to qui...
I'm the author of the article you linked, so my 0.02 If I understood correctly your question, you don't move the vms from dev to production, you create a repeatable process that allows you to create the same end state (OS + config + app) over and over again, no matter where the destination is. By using vagrant you guar...
Puppet
24,183,977
36
I know about puppet agent --disable "my message" --verbose but I would like to know at some point on a given machine, what is its puppet agent status. I don't see how to do it from man puppet-agent Is there an command that would tell me if the agent is enabled or disabled ? Thank you. - ------------------- EDIT Cen...
A one-liner to get the current status is: cat `puppet agent --configprint agent_disabled_lockfile` Generally, this must be run as root, so I use: sudo cat `sudo puppet agent --configprint agent_disabled_lockfile` There are a number of possible results. cat: \path\to\lock: No such file or directory Puppet is not disa...
Puppet
29,350,031
34
file { 'leiningen': path => '/home/vagrant/bin/lein', ensure => 'file', mode => 'a+x', source => 'https://raw.github.com/technomancy/leiningen/stable/bin/lein', } was my idea, but Puppet doesn’t know http://. Is there something about puppet:// I have missed? Or if not, is there a way to declaratively ...
Before Puppet 4.4, as per http://docs.puppetlabs.com/references/latest/type.html#file, the file source only accepts puppet:// or file:// URIs. As of Puppet 4.4+, your original code would be possible. If you're using an older version, one way to achieve what you want to do without pulling down the entire Git repository ...
Puppet
18,844,199
33
I'm trying to set up a non-default URL as part of a puppet script that installs Jenkins. I know how to edit the value via the web UI but I can't seem to find where the value is actually stored. I've looked through the jenkins_home folder and apache and have yet to find it.
It stores it in a rather unlikely place: hudson.tasks.Mailer.xml in Jenkins home folder.
Puppet
11,723,735
31
In puppet, if define command is > 80 characters, how can I wrap into two line to do it? exec { 'create_domain': command => "some command exceed 80 character...........................................................how to do how to do?.......", }
It's sort of ugly, but if the last character in a string is a \ followed by a newline, then the string is continued on the next line. My sample.pp manifest is below: exec { 'wrapped_string_example': command => "/bin/echo 12345678901234567890123456789012345678901234567890\ wrapped > /var/tmp/test.txt"; } Running thi...
Puppet
11,406,234
29
Question Can anyone explain why it would be better to choose the puppet or chef vagrant provisioners, rather than the shell provisioner? Background I'm in the process of getting started with Vagrant. One of the things I'm having trouble with is deciding which provisioner to use. So far, I've had some success using the...
Full disclosure: I'm a Puppet Labs employee. But I chose Puppet as a product over 2 years before joining them. I would recommend that you use Puppet or Chef over shell if your configurations are going to a) have any degree of complexity and b) going to change over time - or you expect your installation environment its...
Puppet
7,747,328
29
I'm using puppet to configure servers. I want to print current machine (node) name in *.erb template. There is hostname variable, but this holds puppetmaster hostname. Is there any good reference/list regarding to this topic?
Seems like I have miss-looked somewhere. I can get(print) node-hostname simply by invoking following code in *.erb template: <%= @hostname %> Edit: As of Puppet 3, using local variables (i.e. hostname is deprecated; Puppet 4 will remove support for them entirely. The recommended way is to use instance variables (pref...
Puppet
4,428,153
29
Is it possible to do a string substitution/transformation in Puppet using a regular expression? If $hostname is "web1", I want $hostname_without_number to be "web". The following isn't valid Puppet syntax, but I think I need something like this: $hostname_without_number = $hostname.gsub(/\d+$/, '')
Yes, it is possible. Check the puppet function reference: http://docs.puppetlabs.com/references/2.7.3/function.html There's a regular expression substitution function built in. It probably calls the same underlying gsub function. $hostname_without_number = regsubst($hostname, '\d+$', '') Or if you prefer to actually c...
Puppet
10,418,104
26
I would like to iterate over an array that is stored as a Facter fact, and for each element of the array create a new system user and a directory, and finally make API calls to AWS. Example of the fact: my_env => [shared1,shared2,shared3] How can I iterate over an array in Puppet?
This might work, depending on what you are doing # Assuming fact my_env => [ shared1, shared2, shared3 ] define my_resource { file { "/var/tmp/$name": ensure => directory, mode => '0600', } user { $name: ensure => present, } } my_resource { $my_env: } It will work if your requirements are simple...
Puppet
12,958,114
24
I'm new to puppet, but picking it up quickly. Today, I'm running into an issue when trying to run the following: $ puppet agent --no-daemonize --verbose --onetime **err: Could not request certificate: getaddrinfo: Name or service not known Exiting; failed to retrieve certificate and waitforcert is disabled** It woul...
D'oh! Need to sudo to do this! Then everything works.
Puppet
10,729,379
24
I don't understand even the basic difference between the services in the title. Do these services just provide software to help you configure/organize/manage your VM's, or do they also provide physical infrastructure for your VM's to run on? In other words, are they just convenient interfaces between developers and AWS...
Not exactly. Chef/Puppet are the "same", they are configuration management. While you can use them to manage virtual machines or public/private clouds, most people don't tend to use them that way. They are configuration management. They typically come into play after a virtual machine is fired up to get them in a desi...
Puppet
41,471,832
23
I am using vagrant with puppet to set up virtual machines for development environments. I would like to simply set a few environment variables in the .pp file. Using virtual box and a vagrant base box for Ubuntu 64 bit. I have this currently. $bar = 'bar' class foobar { exec { 'foobar': command => "export Fo...
If you only need the variables available in the puppet run for all exec resources, whats wrong with : Exec { environment => [ "foo=$bar" ] } ?
Puppet
18,411,795
23
What is the proper way to check if a variable is undef in a puppet template? In the manifest the variable is defined as follows $myvar = undef How is this checked in the template? Is saw the following two variants <% if @myvar -%> <% end -%> and <% if not @myvar.nil? and @myvar -%> <% end -%> They both seem to work ...
The Puppet documentation (at the time of writing this answer) explains it very well: https://puppet.com/docs/puppet/latest/lang_template_erb.html#concept-5365 Since undef is not the same as false, just using an if is not a good way to check for it. Also when a variable is defined, but has a value of false or nil it is ...
Puppet
17,096,934
22
I am using powershell script to set some environment variable-- $env:FACTER_Variable_Name = $Variable_Value FACTER is for using these in the puppet scripts. My problem is - the variable name and variable value both are dynamic and getting read from a text file. I am trying to use $env:FACTER_$Variable_Name = $Variabl...
On Powershell 5, to set dynamically an environment variable in the current shell I use Set-Item: >$VarName="hello" >Set-Item "env:$VarName" world once the variable is set, you can get its value like so: >$env:hello world and of course to persist the variable I use C# [Environment]::SetEnvironmentVariable("$VarName",...
Puppet
30,911,306
21
I am having a weird issue with having puppet enforce the package nc. I installed it manually in the end via: yum install nc I see puppet does it via: /usr/bin/yum -d 0 -e 0 -y list nc Returns: Error: No matching Packages to list I have tested this by command line as well: yum list nc Returns Error: No matching Packag...
Nc is a link to nmap-ncat. It would be nice to use nmap-ncat in your puppet, because NC is a virtual name of nmap-ncat. Puppet cannot understand the links/virtualnames your puppet should be: package { 'nmap-ncat': ensure => installed; }
Puppet
29,045,877
21
I want to create the directory structure /var/www/apps/example/current/public if it doesn't exist using puppet. If it already exists I don't want to purge the contents of the directories. How do I do this? Below is what I have so far: file { "/var/www/apps/example/current/public": owner => 'deploy', group => 'users...
The recurse parameter does not allow you to create parent directories. It is used to enforce property values such as owner, mode etc. on directory contents and subdirectories recursively. file { '/var/www': owner => 'www-data', recurse => true, } As a matter of fact, Puppet currently cannot automatically cre...
Puppet
26,433,115
21
I'm writing some puppet modules and have a package defined in two modules hence get the following error: err: Could not retrieve catalog from remote server: Error 400 on SERVER: Duplicate definition: Package[gnome-session-fallback] is already defined in file /etc/puppet/modules/vnc4server/manifests/init.pp at line 3; c...
You are missing Package[] inside defined(). The correct way to do it: if ! defined(Package['gnome-session-fallback']) { package { 'gnome-session-fallback': ensure => installed, } }
Puppet
15,266,347
20
I am trying to source files from local modules in a puppet manifest (using puppet in standalone mode): file { '/home/repowt/.crontab': ensure => present, source => 'puppet:///modules/site/crontab'; } but I get: Could not evaluate: Could not retrieve information from source(s) ... The file is in: config/pupp...
There are a couple of things going on here. First, as pwan notes, the fileserver.conf needs to be setup correctly. Keeping in mind that /vagrant contains the directory where Vagrantfile is (and therefore all of it content), that meant for me doing: vm_config.vm.provision :puppet, :module_path => "modules", :options => ...
Puppet
7,216,375
19
I run some containers with the option --restart always. It works good, so good, that I have now difficulties to stop these containers now :) I tried : sudo docker stop container && sudo docker rm -f container But the container still restarts. The docker documentation explains the restart policies, but I didn't find an...
Just sudo docker rm -f container will kill the process if it is running and remove the container, in one step. That said, I couldn't replicate the symptoms you described. If I run with --restart=always, docker stop will stop the process and it remains stopped. I am using Docker version 1.3.1.
Puppet
27,283,131
18
What is the best way to store and handle sensitive information with puppet and safely distribute it to your nodes? The version I am using is 2.7. One example would be database passwords. Plain text passwords are needed on your application servers. How can one store these without leaving them lying around inside of the...
Using Hiera for external data lookups and encrypting that data via eyaml or GPG is a good start. https://docs.puppet.com/hiera/ https://puppet.com/blog/encrypt-your-data-using-hiera-eyaml http://leebriggs.co.uk/blog/2016/11/15/using-hiera-eyaml-gpg.html
Puppet
11,171,472
18
I just came cross puppet inheritance lately. A few questions around it: is it a good practice to use puppet inheritance? I've been told by some of the experienced puppet colleagues Inheritance in puppet is not very good, I was not quite convinced. Coming from OO world, I really want to understand under the cover, how ...
That depends, as there are two types of inheritance and you don't mention which you mean. Node inheritance: inheriting from one node fqdn { } definition to another. This in particular is strongly recommended against, because it tends to fail the principle of least surprise. The classic example that catches people o...
Puppet
11,154,090
18
I'd like to ask about when and in what circumstances you'd use puppet and when you'd use chef. I've also found rump which is a puppet-solo type of thing where you iterate a single server to its configuration and then push that to a series of servers, allowing you to see changes directly. My question: which of the above...
Having used both, I would say that it depends on what you look for. In my opinion: Chef is more developer-oriented. If you're a Ruby guru, you'll love it. Puppet is more sysadmin-oriented. It has a non-ruby DSL so it's more difficult to propagate mistakes to your machines (imho). Puppet creates more readable and stab...
Puppet
6,403,894
18
I am new to Puppet and I am writing a module to setup configuration files. The problem is when multiple clients will be using my module they will have to edit it according to their system. I have heard that templates are way to solve this problem. But I am not able to get it how to use a template for setting up config...
The PuppetLabs docs on Using templates has an example of an Apache configuration for a Trac site. This should be enough to get you started. Per OP's request, here's a simple example. I'm using NTP rather than the Apache default config since that's a fairly large and complex file. NTP is much simpler. Directory looks li...
Puppet
22,948,509
17
I'm just getting started with Puppet. The example walkthroughs and tutorials were good at helping me understand Puppet's usefulness and the basic toolset, but I'm having a hard time conceptualizing a full stack. Even the advanced tutorial didn't seem to give me a clear picture of what needs to happen. Are there any ful...
Examples of a full stack are hard to come by. You should be able to find examples of modules that manage some of those specific examples, however. One problem is that it can be a lot of extra work to create a module that has abstracted away all site-specific assumptions and that is truly cross-platform. http://forge.p...
Puppet
5,784,264
17
I have a class definition which requires the build-essential package: class erlang($version = '17.3') { package { "build-essential": ensure => installed } ... } Another class in a different module also requires the build-essential package: class icu { package { "build-essential": ensure => installe...
This is common question when dealing with multiple modules. There's a number of ways of doing this, the best practise is to modularise and allow the installation of build essential as a parameter: class icu ($manage_buildessential = false){ if ($manage_buildessential == true) { package { "build-essential": ...
Puppet
26,205,727
16
I am trying to install a particular rpm using puppet, my init.pp is: class nmap { package {'nmap': provider => 'rpm', source => "<Local PATH to the RPM>", } } and the rpm is in ...modules/nmap/files If i move the rpm to manifests, and provide the rpm name in source => '' class nmap { package {'nmap': ...
Unlike the file resource type, the package type has no support for Puppet fileserver URLs. You will need to use a file resource to download the rpm prior to installing it. If this is a recurring problem for you, make a defined type that does those in one go (think macros), e.g. define fileserver_package($source, $ensur...
Puppet
23,179,577
16
This is hopefully a quick one to answer, I'm trying to provision a box on AWS with puppet and one of the steps involves a pip install from a requirements file. Something like this: - /usr/local/venv/ostcms/bin/pip install -r /vagrant/requirements.txt The step basically fails because it can't find any of the packages i...
Pip runs on 3128 so make sure you have that open in your AWS console. Otherwise pip will get blocked when attempting to talk to PyPi (or anywhere else it cares to download from).
Puppet
22,377,175
16
I have this in my Vagrantfile: Vagrant.configure("2") do |config| config.vm.provision "puppet" end Yet, when I run puppet --version I get : [vagrant@vagrant-centos65 ~]$ puppet --version -bash: puppet: command not found Do I need to manually install puppet?
No, (at the moment) Vagrant doesn't install it automatically. So you either need to use a basebox which already has it installed (Puppet Labs provides boxes too), or you need to install it yourself. Probably the easiest way to install is to use shell provisioner before the puppet provisioner(s).
Puppet
21,589,388
16
I need some help with erb templates, I can't seem to get my head around passing an array and then iterating over it. My problem is this. I want to pass a few arrays: ` device => ["eth0", "br0"], ipaddr => ["192.168.12.166", "192.168.12.199"], netmask => ["255.255.255.0", "255.255.255.0"], hwaddr =...
the basic syntax for using each in ruby is something like this: array.each do |item_from_array| BLOCK so if you only had one array then you could just do something like this: (I would use a different name inside the vertical bars for clarity) <% device.each do |dev| %> auto <%= dev %> inet static <% end %> However ...
Puppet
7,079,857
16
this puppet manifest will remove the file /etc/file.txt if it exists: file { "/etc/file.txt": ensure => absent, } how to tell puppet to remove all files /etc/*.txt? according to the reference, it seems that puppet file does not allow wildcards. https://puppet.com/docs/puppet/latest/types/file.html ps: I am aw...
There's a built-in type for this called 'tidy', which allows you to specify a file glob pattern of files to remove. Check it out at https://puppet.com/docs/puppet/latest/types/tidy.html.
Puppet
18,874,716
15
I have a private network VM for developing on my mac. I'd like for my android device to be able to communicate with the VM on my mac. Currently I can visit the IP defined in my Vagrantfile, 10.10.10.10, on my mac and access it just fine but I can't access it via my phone on the same wifi. What do I need to do to make ...
You are using a Private Network IP which is only accessible by the Host machine (NOT visible to other machines even they are in the same WLAN). In your case, the best choice is to use Public Network (bridged) so that your Android device can access it. add config.vm.network "public_network" in your Vagrant file in the c...
Puppet
18,689,014
15
Primary goal is to add all puppet modules automatically, so that all dev-env's and prod-env could be started with one command. How can I install puppet modules through puppet manifest?
We've been happily using librarian-puppet to sync all 3rd party modules, it supports setting the modules' locations and versions. So production and dev run the exact same code. The usage is one liner librarian-puppet install In other cases we have a shell script that runs puppet two times, one time a minimal module th...
Puppet
16,774,980
15
just starting with Puppet, really new to this world. I have CentOS 6 Puppet Master CentOS 6 Puppet Client In Master have one module: puppet module list /etc/puppet/modules âââ mstanislav-yum (v1.0.0) So I want to apply same module to my puppet client but I can't or I don't know why root@puppetclient: puppet agent ...
You haven't declared the module (assigned it to your node) yet... Add this to site.pp: node 'fqdn of client' { include yum } Then, you can run puppet agent -t to see it in action.
Puppet
13,911,798
15
2021 update Today I'm using Ansible for this and other devops tasks. Along the way I've experimented with Chef, Puppet, Saltstack and Docker images, but I've found that for me, as a solo developer working in smaller projects, a lightweight tool like Ansible is a great fit. Original question (from 2011) I'm starting ou...
Puppet may seem daunting and overkill for small projects since it's so often used for huge deployments, but I use it to manage just one machine in standalone mode without a client server setup so that I don't have to deal with SSL certs and multiple machines, which keeps things a lot simpler, but still gives me the ben...
Puppet
5,485,352
15
I have been using http://www.puphpet.com successfully to generate vagrant+puppet environments for a number of projects. Then this week I got tasked with writing a prototype for a project using Laravel 4. Since I'm not going to be the one working on the project full time, I figured it would be best to make a VM environm...
After some discussion on Twitter, figured out the following: There's a constraint from VirtualBox on vagrant that does not allow you to set permissions for the synced folder from inside the guest OS. See this issue on github. You can use the following code to set the synced folder permissions from the vagrant file: con...
Puppet
18,648,547
14
I am using Puppet 2.7 and I need to convert an array to comma separated list. $hosts_fqdn= ['host1','host2','host3'] And I need to convert it to desired result: 'host1,host2,host3' I guess that Puppet 3.2 offers lambda expression - reduce. But unfortunately that is not possible with 2.7.
Function join from puppetlabs/stdlib: join($hosts_fqdn,',')
Puppet
18,526,456
14
Is there a way to check in manifest files if a given class exists? I want to do something like this: class foo { if exists( Class["foo::${lsbdistcodename}"] ) { include foo::${lsbdistcodename} } } So I can easily add distrubution / version specific classes which are then automatically included.
You should use defined instead of exists statement. The following snippet works for me: class foo { if defined( "foo::${lsbdistcodename}") { notify {'defined':} include "foo::${lsbdistcodename}" } } class foo::precise { notify{'precise':} } [assuming you're running pup...
Puppet
15,096,706
14
I have a cluster of 500 linux boxes which now need to use the mount resource with the bind option (see man 8 mount) to support a chroot jail. The mount points need to be enforced and maintained after boot. I am unsure how to describe this state with puppet. Is it like this? mount { "/gpfs20/home": ensure => mounted,...
For the record it is done this way: mount { '/chroot/centos5/home': ensure => mounted, device => '/gpfs20/home', fstype => 'none', options => 'rw,bind', } ~Charles~
Puppet
11,139,569
14
I am creating a script which need to parse the yaml output that the puppet outputs. When I does a request agains example https://puppet:8140/production/catalog/my.testserver.no I will get some yaml back that looks something like: --- &id001 !ruby/object:Puppet::Resource::Catalog aliases: {} applying: false classe...
I have emailed Kirill Simonov, the creator of PyYAML, to get help to parse Puppet YAML file. He gladly helped with the following code. This code is for parsing Puppet log, but I'm sure you can modify it to parse other Puppet YAML file. The idea is to create the correct loader for the Ruby object, then PyYAML can read t...
Puppet
8,357,650
14
I know the basics of ordering in puppet to run apt-get update before a specific package but would like to specify to just run apt-get update only once and then execute the rest of the puppet file. Is that possible? All of the ways listed Here need to either run apt-get before every package or use arrows or requires to...
This would be my recommendation from that list: exec { "apt-update": command => "/usr/bin/apt-get update" } Exec["apt-update"] -> Package <| |> This will ensure that the exec is run before any package, not that the exec is run before each package. In fact, any resource in puppet will only ever be executed at most...
Puppet
17,689,180
13
I am new to puppet and while going through puppet courses, I found one person using 'puppet agent -t' command to configure an agent node while in another course, the instructor using 'puppet apply' command. What is the difference between these two commands?
These are: puppet apply - applies or "executes" Puppet code on the local machine. puppet agent -t also sometimes written puppet agent --test - calls the Puppet Agent to retrieve a catalog (compiled Puppet code) from a Puppet Master, and then applies it locally and immediately. Note that -t is badly-named, and it may ...
Puppet
53,371,289
12
Anaconda python is installed (in linux) via a bash script. I am trying to use Vagrant provisioning to get Anacaonda Python installed. In the bash script (following the documentation bootstrap.sh example) I have a bootstrap.sh script that: wget the install script chmod +x to make it executable ./<script>.sh to install...
In your bootstrap.sh just include something like: miniconda=Miniconda3-3.7.4-Linux-x86_64.sh cd /vagrant if [[ ! -f $miniconda ]]; then wget --quiet http://repo.continuum.io/miniconda/$miniconda fi chmod +x $miniconda ./$miniconda -b -p /opt/anaconda cat >> /home/vagrant/.bashrc << END # add for anaconda install P...
Puppet
25,321,139
12
I am using https://github.com/puphpet/puppetlabs-mysql to set up mysql configuration and I need to change bind-address variable to 0.0.0.0. I am trying to do that as mysql::config::override_options { 'mysqld' : 'bind-address' => '0.0.0.0' } but it doesn't work. Can you help me to advise how this should be done? Th...
The answers don't seem to comply to the latest version of the module (> 3.1). You can use: class { '::mysql::server': override_options => { mysqld => { bind-address => '0.0.0.0'} #Allow remote connections }, # ... other class options }
Puppet
20,245,225
12
Hi I'm new to puppet and trying to work on a sample to copy files from one location to another location. Any sample script to do that? Ex: I've my file at d:\temp\test.txt and I want to copy this file to E:\mycopy\ folder.
You can "ensure" that the file at target location exists and provide the file to be copied as source in file type. A partial code snippet only showing relevant parts: file { 'E:\mycopy\folder\filename': ensure => present, source => "d:\temp\test.txt", } Check the documentation of file type here and...
Puppet
19,995,172
12
I'm creating a virtual machine to mimic our production web server so that I can share it with new developers to get them up to speed as quickly as possible. I've been through the Vagrant docs however I do not understand the advantage of using a generic base box and provisioning everything with Puppet versus packaging a...
Advantages: As dependencies may change over time, building a new box from scratch will involve either manually removing packages, or throwing the box away and repeating the installation process by hand all over again. You could obviously automate the installation with a bash or some other type of script, but you'd be ...
Puppet
12,873,128
12
I'm doing my first steps in Puppet and ran into a problem. I've installed PHP on a Linux server and I want to do some slightly changes to php.ini file. I don't want to overwrite the whole ini file with one from repository, just change/create one simple config value. I want to ensure, that the property upload_max_filesi...
My preferred option would be to leave php.ini alone, and have puppet create a file in php's conf.d directory to override the values you want to change. The less changes you make to php.ini, the easier it is to see what's going on when you need to merge your changes with the package providers changes when you upgrade ph...
Puppet
10,800,199
12
In a puppet class how should I test if a variable has been set or not? Right now I am just checking if a variable is undefined: if $http_port != undef { $run_command = "$run_command --http-port $http_port" } Is there a better way to check if a variable has been declared or not?
If you are testing if an variable is undef, your way is correct. Writing if $http_port { $run_command = "$run_command --http-port $http_port" } would accomplish almost the same. If $http_port is undef or false, it will not run the command. If you want to test if the var has been defined you should do: if defined('$h...
Puppet
45,310,419
11
hiera.yaml --- :hierarchy: - node/%{host_fqdn} - site_config/%{host_site_name} - site_config/perf_%{host_performance_class} - site_config/%{host_type}_v%{host_type_version} - site/%{host_site_name} - environments/%{site_environment} - types/%{host_type}_v%{host_type_version} - hosts - sites - users ...
I think that @Xiong is right that you should go the variables way in Ansible. You can set up flexible inventory with vars precedence from general to specific. But you can try this snippet if it helps: --- - hosts: loc-test tasks: - include_vars: hiera/{{ item }} with_items: - common.yml - "n...
Puppet
39,473,719
11
I'm trying to build a puppet managed infrastructure (non-enterprise) in AWS with EC2 instances. Using puppetlabs-aws module I'm able to create the machines by convenient means. Next up is to make local settings on each node, most importantly setting a unique hostname. How can I do this? One way I know of is to provide ...
The problem is how to set up a new instance with so that it will load it's config from a particular class Let me try and explain the problem I think you are trying to address What I am trying to answer here You have an existing script that sets up EC2 virtual hosts on AWS using the aws-puppet module. This module calls...
Puppet
34,226,131
11
This is happening in Puppet's bundle. The Gemfile specifies gem "puppet", :path => File.dirname(__FILE__), :require => false But one of the gems I installed in $GEM_HOME appears in $: after all. $ bundle exec ruby -e 'puts $:' ... /home/puppy/puppet-git-clone/lib ... /usr/lib/ruby/vendor_ruby ... /home/puppy/gems/gems...
The quick fix is to add -Ilib to your ruby command: $ bundle exec ruby -e "require 'puppet'; puts Facter.value(:puppetversion)" 3.7.5 $ bundle exec ruby -Ilib -e "require 'puppet'; puts Facter.value(:puppetversion)" 3.7.3 If we compare the load paths, you can see that adding -Ilib results in 3.7.5 not being present i...
Puppet
29,709,146
11
In the official Puppet docs it says that there are two chaining arrows: https://docs.puppetlabs.com/puppet/latest/reference/lang_relationships.html -> (ordering arrow) Causes the resource on the left to be applied before the resource on the right. Written with a hyphen and a greater-than sign. ~> (notification arrow)...
The document you mentioned has given the best explanation. If you try to understand it by simple way, using the exist sample. Package['ntp'] -> File['/etc/ntp.conf'] ~> Service['ntpd'] For File['/etc/ntp.conf'], puppet needs to make sure that the package ntp has been installed before it creates or updates the file ntp...
Puppet
27,803,107
11
I'm using puppet as my provisioner in one of my vagrant project. I'm trying to add a module for a custom bash_profile. The module_path for puppet is set to: puppet.module_path = "puppet/modules" The class for my bash_profile module looks like this: class bash_profile { file { "/home/vagrant/bash_prof...
Yes, you are not supposed to include the literal files/ in the URL. Instead, it should just be puppet:///modules/bash_profile/bash_profile
Puppet
24,213,407
11
I have worked out how to fire up a vagrant box and apt-get install packages I now want to git clone a node.js repo from github before running npm install and running the app with node app.js I expected to be able to achieve this by issuing BASH commands, but I see now that puppet requires this to be done in a puppety w...
You can use the puppet-nodejs module to manage npm packages. Take a look at https://forge.puppetlabs.com/puppetlabs/nodejs Otherwise, this article should explain how to clone a git repo. http://livecipher.blogspot.com.au/2013/01/deploy-code-from-git-using-puppet.html More info can be found at https://github.com/puppet...
Puppet
18,329,821
11
Puppet 2.7.19 Vagrant version 1.0.6 VM OS Ubuntu 12.04 I am attempting to set the puppet module path from vagrant. Which seems like it should be very simple. In my Vagrant file I have: Vagrant::Config.run do |config| config.vm.provision :puppet, :module_path => "my_modules" config.vm.provision :puppet, :options =>...
You're effectively specifying module_path twice: Vagrant::Config.run do |config| config.vm.provision :puppet, :module_path => "my_modules" config.vm.provision :puppet, :options => ["--modulepath", "my_modules"] end I'm not sure which would wind up overriding the other, but you shouldn't be specifying the module pa...
Puppet
15,507,506
11
I'm trying to work out the best way to set some environment variables with puppet. I could use exec and just do export VAR=blah. However, that would only last for the current session. I also thought about just adding it onto the end of a file such as bashrc. However then I don't think there is a reliable method to che...
I would take a look at this related question. *.sh scripts in /etc/profile.d are read at user-login time (as the post says, at the same time /etc/profile is sourced) Variables export-ed in any script placed in /etc/profile.d will therefore be available to your users. You can then use a file resource to ensure this act...
Puppet
15,440,972
11
I would like to run a webservice and wait for a few seconds after to get the result. What is the best way to achieve a wait in puppet ?
You could use the linux sleep command with exec and stage it to run after the web-service. something like : exec { 'wait_for_my_web_service' : require => Service["my_web_service"], command => "sleep 10 && /run/my/command/to/get/results/from/the/web/service", path => "/usr/bin:/bin", }
Puppet
14,470,724
11
Directory and file layout as follows: app_test/ app_test/manifests app_test/manifests/init.pp app_test/manifests/test.pp Contents of init.pp: class app_test { include app_test::test } Contents of test.pp: class app_test::test { exec { 'hello world': command => "/bin/echo Hello World >> /tmp/are-you-th...
You are only defining classes, not declaring them. Create a file modules/[module_name]/tests/init.pp: Contents: include app_test Test your class then with: puppet apply tests/init.pp That should do the trick! Kind regards, Ger Apeldoorn
Puppet
13,143,929
11
I have a pip style requirements.txt file I use for keeping track of my python dependencies, I'm moving my dev environment over to vagrant + puppet. So far I've been using the pip provider built into puppet to install individual packages like this: package { ["django", "nose"]: ensure => present, provider...
Yes it is possible. Instead of defining a package resource, define a "exec" resource instead that will take the requirements.txt as variable and runs the pip install command. E.g. class pip_install( $path_requirements_file, ){ exec { "pip_requirements_install": command => "pip install -r ${path_requirements...
Puppet
21,420,205
10
I would like to know if there is any way of checking if a string exists inside another string (ie contains function). I have been taken a look to http://forge.puppetlabs.com/puppetlabs/stdlib but I haven't found this specific function. Maybe this is possible through a regexp, but I am not really sure how to do it. Can ...
There is an "in" operator in Puppet: # Right operand is a string: 'eat' in 'eaten' # resolves to true 'Eat' in 'eaten' # resolves to true # Right operand is an array: 'eat' in ['eat', 'ate', 'eating'] # resolves to true 'Eat' in ['eat', 'ate', 'eating'] # resolves to true # Right operand is a hash: 'eat' in { 'eat' =...
Puppet
19,283,190
10
I'm trying to get TeamCity to trigger a deployment with puppet via the commandline using puppet.bat on Windows. In Teamcity I'm calling this using a Command Line runner, with Command executable: C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat Command parameters: apply myexample.pp What I would like to do is al...
To pass a value through the command line it needs to be an environment variable, prefixed by FACTER_. So, FACTER_foo will turn into $::foo.
Puppet
15,901,850
10
From my current knowledge, there is no reason .terraform.lock.hcl should be included in the .gitignore. Nothing about this file is private, or is there?
Per the Terraform documentation on the Dependency Lock File: Terraform automatically creates or updates the dependency lock file each time you run the terraform init command. You should include this file in your version control repository so that you can discuss potential changes to your external dependencies via code...
Terraform
67,963,719
212
I have resources defined in .tf files that are generic to several applications. I populate many of the fields via a .tfvars file. I need to omit some of the resources entirely based on variables in the .tfvars. For example if I have a resource like: resource "cloudflare_record" "record" { zone_id = "${data.cloudflar...
Add a count parameter with a ternary conditional using the variable declared in .tfvars like this: resource "cloudflare_record" "record" { count = var.cloudflare ? 1 : 0 zone_id = "${data.cloudflare_zones.domain.zones[0].id}" name = "${var.subdomain}" value = "${var.origin_server}" type = "CNAME" tt...
Terraform
60,231,309
205
When I input any code in this function (e.g. console.log();) and click "Save", an error occurs: The provided execution role does not have permissions to call DescribeNetworkInterfaces on EC2 exports.handler = (event, context, callback) => { callback(null, 'Hello from Lambda'); console.log(); // here is my code ...
This error is common if you try to deploy a Lambda in a VPC without giving it the required network interface related permissions ec2:DescribeNetworkInterfaces, ec2:CreateNetworkInterface, and ec2:DeleteNetworkInterface (see AWS Forum). For example, this a policy that allows to deploy a Lambda into a VPC: { "Version":...
Terraform
41,177,965
194
I got the following error during a terraform plan which occured in my pipeline: Error: Error locking state: Error acquiring the state lock: ConditionalCheckFailedException: The conditional request failed Lock Info: ID: 9db590f1-b6fe-c5f2-2678-8804f089deba Path: ... Operation: OperationTypePlan Who: .....
Cause of Error This error usually appears when one process fails running terraform plan or terraform apply. For example if your network connection interrupts or the process is terminated before finishing. Then Terraform "thinks" that this process is still working on the infrastructure and blocks other processes from wo...
Terraform
62,189,825
194
It takes a long time to run terraform and wait. So I would like to run it to exclude rds that takes the longest time to excute or I would like to run only ec2 resource. Is there a way to do such things in terraform?
You can use -target=resource like this: terraform plan -target=module.mymodule.aws_instance.myinstance terraform apply -target=module.mymodule.aws_instance.myinstance or terraform plan -target=aws_instance.myinstance terraform apply -target=aws_instance.myinstance Disclaimer: Before downvoting the answer, please note...
Terraform
46,762,047
170
I need to deploy a list of GCP compute instances. How do I loop for_each through the "vms" in a list of objects like this: "gcp_zone": "us-central1-a", "image_name": "centos-cloud/centos-7", "vms": [ { "hostname": "test1-srfe", "cpu": 1, "ram": 4, "hdd": 15, "l...
I work a lot with iterators in Terraform, they always gave me bad headaches. Therefore I identified five of the most common iterator patterns (code examples are given below), which helped me construct a lot of nice modules (source). Using for_each on a list of strings Using for_each on a list of objects Using for_each...
Terraform
58,594,506
166
Use case I have installed Terraform v0.11.13 via homebrew and as recommended by terraform I want to ugprade to version v0.11.14 before doing the major upgrade to v0.12.0. The problem When I run brew upgrade terraform or download the Mac package from the terraform website it would immediately update my terraform version...
Especially when playing around with Terraform 0.12 betas, I learned to love tfenv. After installation (via brew install tfenv on MacOS), this allows you to easily discover, install and activate any Terraform version: $ tfenv list-remote 0.12.0 0.12.0-rc1 0.12.0-beta2 0.12.0-beta1 0.12.0 0.11.14 ... $ tfenv install 0.1...
Terraform
56,283,424
164
I want to attach one of the pre-existing AWS managed roles to a policy, here's my current code: resource "aws_iam_role_policy_attachment" "sto-readonly-role-policy-attach" { role = "${aws_iam_role.sto-test-role.name}" policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess" } Is there a better way to model the ...
The IAM Policy data source is great for this. A data resource is used to describe data or resources that are not actively managed by Terraform, but are referenced by Terraform. For your example, you would create a data resource for the managed policy as follows: data "aws_iam_policy" "ReadOnlyAccess" { arn = "arn:a...
Terraform
45,002,292
149
I need to spin up a bunch of EC2 boxes for different users. Each user should be sandboxed from all the others, so each EC2 box needs its own SSH key. What's the best way to accomplish this in Terraform? Almost all of the instructions I've found want me to manually create an SSH key and paste it into a terraform script....
Terraform can generate SSL/SSH private keys using the tls_private_key resource. So if you wanted to generate SSH keys on the fly you could do something like this: variable "key_name" {} resource "tls_private_key" "example" { algorithm = "RSA" rsa_bits = 4096 } resource "aws_key_pair" "generated_key" { key_name...
Terraform
49,743,220
143
I am a little bit puzzled on the question whether to commit .tfstate files to Git or not. The Terraform documentation states: Terraform also put some state into the terraform.tfstate file by default. This state file is extremely important; it maps various resource metadata to actual resource IDs so that Terraform know...
There are a few reasons not to store your .tfstate files in Git: You are likely to forget to commit and push your changes after running terraform apply, so your teammates will have out-of-date .tfstate files. Also, without any locking on these state files, if two team members run Terraform at the same time on the same...
Terraform
38,486,335
142
I must be being incredibly stupid but I can't figure out how to do simple string concatenation in Terraform. I have the following data null_data_source: data "null_data_source" "api_gw_url" { inputs = { main_api_gw = "app.api.${var.env_name == "prod" ? "" : var.env_name}mydomain.com" } } So when env_name...
I know this was already answered, but I wanted to share my favorite: format("%s/%s",var.string,"string2") Real world example: locals { documents_path = "${var.documents_path == "" ? format("%s/%s",path.module,"documents") : var.documents_path}" } More info: https://www.terraform.io/docs/configuration/functions/for...
Terraform
55,312,783
141
I'm in the process of swapping over our infrastructure into terraform. What's the best practice for actually managing the terraform files and state? I realize it's infrastructure as code, and i'll commit my .tf files into git, but do I commit tfstate as well? Should that reside somewhere like S3 ? I would like eventual...
I am also in a state of migrating existing AWS infrastructure to Terraform so shall aim to update the answer as I develop. I have been relying heavily on the official Terraform examples and multiple trial and error to flesh out areas that I have been uncertain in. .tfstate files Terraform config can be used to provisi...
Terraform
33,157,516
135
I would like to run an AWS lambda function every five minutes. In the AWS Management Console this is easy to set up, under the lambda function's "Event Sources" tab, but how do I set it up with Terraform? I tried to use an aws_lambda_event_source_mapping resource, but it turns out that the API it uses only supports eve...
You can use an aws_cloudwatch_event_target resource to tie the scheduled event source (event rule) to your lambda function. You need to grant it permission to invoke your lambda function; you can use an aws_lambda_permission resource for this. Example: resource "aws_lambda_function" "check_foo" { filename = "check_...
Terraform
35,895,315
133
The Terraform Data Sources documentation tells me what a data source is, but I do not quite understand it. Can somebody give me a use case of data source? What is the difference between it and configuring something using variables?
Data sources can be used for a number of reasons; but their goal is to do something and then give you data. Let's take the example from their documentation: # Find the latest available AMI that is tagged with Component = web data "aws_ami" "web" { filter { name = "state" values = ["available"] } filter...
Terraform
47,721,602
106
I am using terraform to manage IaC on AWS. There was a s3 bucket created by my terraform project and later I moved the s3 bucket terraform to a different project. So I deleted all s3 related code in my project. When I run terraform apply I get an error saying Error: error deleting S3 Bucket (xxxx): BucketNotEmpty: The ...
You can remove any resource added to your Terraform like this: List all state: terraform state list Remove desired resource from state: terraform state rm <name>
Terraform
61,297,480
101
I have a Terraform script using modules. I want to create multiple resources so I'm using the for_each method. Below is my variable configuration: variable bridge_domains { description = "Bridge Domain" type = map default = { bd1 = { name = "BD1", }, bd2 = { name = "BD2" } }...
The [*] and .* operators are intended for use with lists only. Because this resource uses for_each rather than count, its value in other expressions is a map, not a list. To make your configuration work you'll need to decide whether it's better to return a map of names where the keys are the var.bridge_domains keys, or...
Terraform
64,989,080
91
I have a GCP infrastructure deployed through Terraform: buckets, service accounts, Compute Engines, VPC, cloud SQL, BigTable, BigQuery, Composer, etc. Terraform v0.11.10 Provider "google" (2.15.0) Recently the client asked me to split our only one terraform file (e.g. main.tf) in several files. E.g: One files for Buck...
Terraform does not ascribe any special meaning to which filenames you use and how many files you have. Terraform instead reads all of the .tf files and considers their contents together. Therefore you can freely move the blocks from your main.tf file into as many separate .tf files in the same directory as you like, an...
Terraform
58,001,764
87
How am I able to execute the following command: terraform apply #=> . . . Do you want to perform these actions? Terraform will perform the actions described above. Only 'yes' will be accepted to approve. Enter a value: without the interactive prompt that follows?
terraform apply -auto-approve https://www.terraform.io/docs/commands/apply.html#auto-approve
Terraform
59,958,294
81
I'm getting confused when using Terraform to provision an auto-scaling group. Should I use launch configuration or launch template for EC2 properties, such as which AMI, instance types, ...? I don't know what the difference is between them, which we should use and why they exist?
Launch templates (LTs) are newer than launch configurations (LCs) and provide more options to work with. Thus, the AWS documentation recommends use of launch templates (LTs) over launch configuration (LCs): We recommend that you create Auto Scaling groups from launch templates to ensure that you're getting the latest ...
Terraform
61,981,663
74
I want to attach multiple IAM Policy ARNs to a single IAM Role. One method is to create a new policy with privileges of all the policies (multiple policies). But in AWS, we have some predefined IAM policies like AmazonEC2FullAccess, AmazomS3FullAccess, etc. I want to use a combination of these for my role. I could not ...
For Terraform versions >= 0.12 the cleanest way to add multiple policies is probably something like this: resource "aws_iam_role_policy_attachment" "role-policy-attachment" { for_each = toset([ "arn:aws:iam::aws:policy/AmazonEC2FullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess" ]) role = va...
Terraform
45,486,041
73
I want to create a Terraform configuration for DynamoDB table with multiple (> 10) attributes. And I have no need to add all attributes as an index to global_secondary_index or local_secondary_index. But when I run terraform plan command I have next error: All attributes must be indexed. Unused attributes: ... I foun...
You do not have to define every attribute you want to use up front when creating your table. attribute blocks inside aws_dynamodb_table resources are not defining which attributes you can use in your application. They are defining the key schema for the table and indexes. For example, the following Terraform defines a...
Terraform
50,006,885
69
I have a Terraform configuration targeting deployment on AWS. It applies beautifully when using an IAM user that has permission to do anything (i.e. {actions: ["*"], resources: ["*"]}. In pursuit of automating the application of this Terraform configuration, I want to determine the minimum set of permissions necessary...
Here is another approach, similar to what was said above, but without getting into CloudTrail - Give full permissions to your IAM user. Run TF_LOG=trace terraform apply --auto-approve &> log.log Run cat log.log | grep "DEBUG: Request" You will get a list of all AWS Actions used.
Terraform
51,273,227
69
First off - apologies - I’m extremely new (3 hours in!) to using terraform. I am looking to try and use the value of a variable inside the declaration of another variable. Below is my code - what am I doing wrong? variables.tf: variable "EnvironmentName" { type = "string" } variable "tags" { type = "map" de...
Terraform does not support variables inside a variable. If you want to generate a value based on two or more variables then you can try Terraform locals. You can define the locals like this: locals { tags = { Environment = "${var.EnvironmentName}" CostCentre = "C1234" Project = "TerraformTest" De...
Terraform
58,841,060
66
I was able to create a bucket in an AWS S3 using this link. I used the following code to create a bucket: resource "aws_s3_bucket" "b" { bucket = "my_tf_test_bucket" acl = "private" } Now I wanted to create folders inside the bucket, say Folder1. I found the link for creating an S3 object. But this has a ma...
For running Terraform on Mac or Linux, the following will do what you want: resource "aws_s3_bucket_object" "folder1" { bucket = "${aws_s3_bucket.b.id}" acl = "private" key = "Folder1/" source = "/dev/null" } If you're on Windows you can use an empty file. While folks will be pedantic about S3 no...
Terraform
37,491,893
62
I want access to my AWS Account ID in terraform. I am able to get at it with aws_caller_identity per the documentation. How do I then use the variable I created? In the below case I am trying to use it in an S3 bucket name: data "aws_caller_identity" "current" {} output "account_id" { value = data.aws_caller_identity...
If you have a data "aws_caller_identity" "current" {} then you need to define a local for that value: locals { account_id = data.aws_caller_identity.current.account_id } and then use it like output "account_id" { value = local.account_id } resource "aws_s3_bucket" "test-bucket" { bucket = "test-bucket-${loca...
Terraform
68,397,972
61
What is the least painful way to migrate state of resources from one project (i.e., move a module invocation) to another, particularly when using remote state storage? While refactoring is relatively straightforward within the same state file (i.e., take this resource and move it to a submodule or vice-versa), I don't ...
The least painful way I’ve found is to pull both remote states local, move the modules/resources between the two, then push back up. Also remember, if you’re moving a module, don’t move the individual resources; move the whole module. For example: cd dirA terraform state pull > ../dirA.tfstate cd ../dirB terraform st...
Terraform
50,400,007
60
I have the following condition: resource "aws_elastic_beanstalk_application" "service" { appversion_lifecycle { service_role = "service-role" delete_source_from_s3 = "${var.env == "production" ? false : true}" } } If var.env is set to production, I get the result I want. However if var.env is no...
Seems these days you can also use try to check if something is set. try(var.env, false) After that your code will work since var.env is now defined with the value false even if var.env was never defined somewhere. https://www.terraform.io/docs/configuration/functions/try.html
Terraform
53,200,585
59
I've been using Terraform to build my AWS stack and have been enjoying it. If it was to be used in a commercial setting the configuration would need to be reused for different environments (e.g. QA, STAGING, PROD). How would I be able to achieve this? Would I need to create a wrapper script that makes calls to terrafo...
I suggest you take a look at the hashicorp best-practices repo, which has quite a nice setup for dealing with different environments (similar to what James Woolfenden suggested). We're using a similar setup, and it works quite nicely. However, this best-practices repo assumes you're using Atlas, which we're not. We've...
Terraform
37,005,303
58
In AWS API Gateway, I have a endpoint defined as /users/{userId}/someAction, and I'm trying to recreate this with terraform I would start having some sort of linked gateway_resource chain like so... resource "aws_api_gateway_resource" "Users" { rest_api_id = "${var.rest_api_id}" parent_id = "${var.parent_id}" p...
You need to define a resource whose path_part is the parameter you want to use: // List resource "aws_api_gateway_resource" "accounts" { rest_api_id = var.gateway_id parent_id = aws_api_gateway_resource.finance.id path_part = "accounts" } // Unit resource "aws_api_gateway_resource" "account" { rest_a...
Terraform
39,040,739
58