{"action":"opened","issue":{"url":"https://api.github.com/repos/chef-cookbooks/windows/issues/296","labels_url":"https://api.github.com/repos/chef-cookbooks/windows/issues/296/labels{/name}","comments_url":"https://api.github.com/repos/chef-cookbooks/windows/issues/296/comments","events_url":"https://api.github.com/repos/chef-cookbooks/windows/issues/296/events","html_url":"https://github.com/chef-cookbooks/windows/issues/296","id":117185654,"number":296,"title":"windows_certificate create action does not appear to be idempotent","user":{"login":"chrisgit","id":3491138,"avatar_url":"https://avatars.githubusercontent.com/u/3491138?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisgit","html_url":"https://github.com/chrisgit","followers_url":"https://api.github.com/users/chrisgit/followers","following_url":"https://api.github.com/users/chrisgit/following{/other_user}","gists_url":"https://api.github.com/users/chrisgit/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisgit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisgit/subscriptions","organizations_url":"https://api.github.com/users/chrisgit/orgs","repos_url":"https://api.github.com/users/chrisgit/repos","events_url":"https://api.github.com/users/chrisgit/events{/privacy}","received_events_url":"https://api.github.com/users/chrisgit/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-16T18:13:03Z","updated_at":"2015-11-16T18:13:03Z","closed_at":null,"body":"Converging on a Windows 2012 RTM virtual box the windows_certificate resource always runs irrespective of whether the certificate is installed in the certificate store.\r\n\r\nExample usage of the windows_certificate resource\r\n```\r\n  windows_certificate \"C:/certs/my_cert_file\" do\r\n    pfx_password 'my_password'\r\n  end  \r\n```\r\nHaving looked at the code I think the powershell resource used in the create method needs changing to specify the guard interpreter \r\n```\r\n  powershell_script new_resource.name do\r\n    guard_interpreter :powershell_script\r\n    code code_script\r\n    not_if guard_script\r\n  end\r\n```\r\nAlternatively if a guard_interpreter is not specified the resource can be made idempotent by returning an exit code of 0 or 1 from the script by changing it to\r\n```\r\ndef cert_exists_script(hash)\r\n  <<-EOH\r\n$hash = #{hash}\r\nIf ((Test-Path \"Cert:\\\\#{@location}\\\\#{new_resource.store_name}\\\\$hash\") -eq $true) {exit 0} else {exit 1}\r\nEOH\r\nend\r\n```\r\n\r\nBoth solutions above tested with Chef 11.18.6 and 12.4.1."}}