Skip to content

Aliases for attributes #280

Open
Open
@michaeltlombardi

Description

@michaeltlombardi

Use Case

Sometimes, for backwards compatibility prior to deprecation, it would be useful to change an attribute's name but retain an alias to the old/alternate name. Similarly, sometimes the parameters for the underlying object being managed itself have aliases which should be usable at the Puppet resource level.

Describe the Solution You Would Like

A new optional key for attributes called aliases which takes one ore more symbols as alternate names. For example:

Puppet::ResourceApi.register_type(
  name: 'testy_resource',
  docs: 'test resource',
  attributes: {
    ensure: {
      type:    'Enum[present, absent]',
      desc:    'Whether this resource should be present or absent on the target system.',
      default: 'present',
    },
    name: {
      type:      'String',
      desc:      'Description of the purpose for this resource declaration.',
      behaviour: :namevar,
    },
    foo: {
      type:      'String',
      desc:      'Description of the purpose for this resource declaration.',
      aliases: [:bar, :baz],
    },
)

Which would then have the following equivalent manifest declarations:

testy_resource { 'some title':
  foo => 'bing!',
}
testy_resource { 'some title':
  bar => 'bing!',
}
testy_resource { 'some title':
  baz => 'bing!',
}

But would fail if you tried to specify either the same attribute, regardless of name/alias, twice in the same resource:

testy_resource { 'some title':
  foo => 'boop!',
  bar => 'woop!',
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions