Skip to content

Instantly share code, notes, and snippets.

@DavidS
Created January 20, 2017 16:32
Show Gist options
  • Save DavidS/3f9fe51ea79c219dc12176d96927bb8d to your computer and use it in GitHub Desktop.
Save DavidS/3f9fe51ea79c219dc12176d96927bb8d to your computer and use it in GitHub Desktop.
The simplest possible resource type implementation: talking to a external API
Puppet::SimpleResource.define(
name: 'iis_application_pool',
docs: 'Manage an IIS application pool through a powershell proxy.',
attributes: {
ensure: {
type: 'Enum[present, absent]',
docs: 'Whether this ApplicationPool should be present or absent on the target system.'
},
name: {
type: 'String',
docs: 'The name of the ApplicationPool.',
namevar: true,
},
state: {
type: 'Enum[running, stopped]',
docs: 'The state of the ApplicationPool.',
default: 'running',
},
managedpipelinemode: {
type: 'String',
docs: 'The managedPipelineMode of the ApplicationPool.',
},
managedruntimeversion: {
type: 'String',
docs: 'The managedRuntimeVersion of the ApplicationPool.',
},
}
) do
require 'puppet/provider/iis_powershell'
include Puppet::Provider::IIS_PowerShell
def get
result = run('fetch_application_pools.ps1', logger) # call out to powershell to talk to the API
# returns an array of hashes with data according to the schema above
JSON.parse(result)
end
def set(goals, noop = false)
result = run('enforce_application_pools.ps1', goals, logger, noop) # call out to powershell to talk to the API
# returns an array of hashes with status data from the changes
JSON.parse(result)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment