Skip to content

Commit

Permalink
Create subpaths for provisioning_datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrakel committed Jun 9, 2024
1 parent b6218f9 commit 447065a
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
45 changes: 45 additions & 0 deletions spec/acceptance/class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,51 @@ class { 'grafana':
apply_manifest(pp, catch_changes: true)
end
end

context 'with fancy dashboard config and custom target file and create_subdirs_provisioning' do
it 'works idempotently with no errors' do
pp = <<-EOS
class { 'grafana':
version => "#{grafana_version}",
create_subdirs_provisioning => true,
provisioning_datasources => {
apiVersion => 1,
datasources => [
{
name => 'Prometheus',
type => 'prometheus',
access => 'proxy',
url => 'http://localhost:9090/prometheus',
isDefault => false,
},
],
},
provisioning_dashboards => {
apiVersion => 1,
providers => [
{
name => 'default',
orgId => 1,
folder => '',
type => 'file',
disableDeletion => true,
options => {
path => '/var/lib/grafana/dashboards',
puppetsource => 'puppet:///modules/my_custom_module/dashboards',
},
},
],
},
provisioning_dashboards_file => '/etc/grafana/provisioning/dashboards/dashboard.yaml',
provisioning_datasources_file => '/etc/grafana/provisioning/datasources/datasources.yaml'
}
EOS

# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/classes/grafana_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,36 @@
end
end

context 'provisioning_datasources defined and create_subdirs_provisioning is true' do
let(:params) do
{
version: '11.0.0',
create_subdirs_provisioning: true,
provisioning_datasources: {
apiVersion: 1,
datasources: [
{
name: 'Prometheus',
type: 'prometheus',
access: 'proxy',
url: 'http://localhost:9090/',
isDefault: true,
}
]
}
}
end

it do
expect(subject).to contain_file('/etc/grafana/provisioning/datasources/puppetprovisioned.yaml').with(
ensure: 'file',
owner: 'grafana',
group: 'grafana',
mode: '0640'
)
end
end

context 'sysconfig environment variables' do
let(:params) do
{
Expand Down

0 comments on commit 447065a

Please sign in to comment.