Skip to content

Instantly share code, notes, and snippets.

@skierkowski
Last active October 16, 2017 18:54
Show Gist options
  • Save skierkowski/d80c8e8932285c3dc99b22c59d1e7195 to your computer and use it in GitHub Desktop.
Save skierkowski/d80c8e8932285c3dc99b22c59d1e7195 to your computer and use it in GitHub Desktop.
$LOAD_PATH.unshift(File.expand_path("./lib"))
require 'terraform_enterprise_api'
require 'awesome_print'
require 'securerandom'
@client = TerraformEnterprise::Client.new(api_key: ENV['TERRAFORM_ENTERPRISE_TOKEN'])
def test_policy_crud(organization:'000-test-suite',policy_name:"policy-#{SecureRandom.hex(3)}")
policy_content = 'main = rule { true }'
policy = @client.policies.create(organization:organization,name:policy_name, enforce:[{path:"#{policy_name}.sentinel",mode:'hard-mandatory'}])
@client.policies.upload(policy: policy['id'], content:policy_content)
downloaded_policy = @client.policies.download(policy: policy['id'])
raise "uploaded policy (#{policy_content}) does not match downloaded policy (downloaded_policy)" unless policy_content == downloaded_policy
@client.policies.delete(policy: policy['id'])
end
test_policy_crud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment