Ask Your Question

Multiple links between custom types

asked 2016-02-07 08:01:18 -0500

Jan Fabry gravatar image

I'm looking for the "best" (most elegant/feasible) way to model custom types with links between each other, so this question is one about the usability for the users of these types and the possibility of actually coding it.

I am trying to model New Relic alert policies and channels in custom types. There is no logical order, either you create your policies first and then attach your channels, or you create your channels first and then attach your policies. Or you already created your channels and policies (outside of Puppet), but want to create new links.

I was thinking of allowing all three ways, by collecting all data and then doing all synchronisation in a final flush. Does this make sense? From a user perspective, but also from a code perspective?

So there would be a newrelic_alert_channel, newrelic_alert_policy, and a newrelic_alert_policy_channel to link them. But both the channel and the policy would have a policies or channels property that could be used to link them directly (and a purge_policies and purge_channels if you want to clear those not defined anywhere in Puppet).

# Define without links to policies
newrelic_alert_channel { 'Mail ops':
  ensure        => 'present',
  configuration => {'address' => '' },
  type          => 'slack',

# Define without link to channels
newrelic_alert_policy { ' production':
  ensure          => 'present',
  rollup_strategy => 'PER_CONDITION_AND_TARGET',

# Link production policy to mail channel
newrelic_alert_policy_channel { 'Mail production':
  policy  => ' production',
  channel => 'Mail ops',

# Create channel with link to policy
newrelic_alert_channel { 'Slack':
  ensure        => 'present',
  configuration => {'channel' => 'newrelic'},
  type          => 'slack',
  policies      => [' production']

# Create policy with link to channel
newrelic_alert_policy { ' development':
  ensure          => 'present',
  rollup_strategy => 'PER_CONDITION_AND_TARGET',
  channels        => ['Slack']

Code-wise, I think I should collect all data and links, and then in the flush phase synchronise everything. So this would mean that the flush methods of the three providers would call the same backend synchronisation method, which will keep track whether it has already been called. Or something like that, this is my first custom Puppet type and resource, so I hope I get the concepts right.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-08 04:59:31 -0500

liamjbennett gravatar image

updated 2016-02-08 04:59:57 -0500

This is one of those interesting problems when writing providers over APIs like this. I would try and keep them as separate as possible, especially if they have separate API calls.

Having said that if you dowant to do something like that, you can get access to the resources of the catalog in prefetch as described here:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-07 08:01:18 -0500

Seen: 56 times

Last updated: Feb 08 '16