title: Puppet: How to require an additional resource in a custom type
body: <p>I am writing a custom type for Puppet and use the following code to copy a module file specified by a puppet url to the user's home directory:</p>
  
  <pre><code>def generate
    if self[:source]
      uri = URI.parse(self[:source])
      path = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
      file_opts = {}
      file_opts[:name] = File.join(Etc.getpwnam(self[:user])[:dir], File.basename(uri.path))
      file_opts[:ensure] = self[:ensure] == :absent ? :absent : :file
      file_opts[:source] = self[:source]
      file_opts[:owner] = self[:user]
      self[:source] = path
  
      Puppet::Type.type(:file).new(file_opts)
    end
  end
  </code></pre>
  
  <p>Things are working fine so far. The resource is added to the catalog and created on the agent side. But I have a problem...</p>
  
  <p>How can I specify that this additional file resource must be created before the actual type gets executed? Unfortunatley, I cannot find an example which shows how to specify a dependency on an optional resource that is defined in a <code>generate</code> method.</p>