def test(): """Provisioner (005)""" config = terrascript.Terrascript() config += terrascript.provider.aws(version="~> 2.0", region="us-east-1") # Copies the myapp.conf file to /etc/myapp.conf provisioner1 = terrascript.Provisioner("file", source="conf/myapp.conf", destination="/etc/myapp.conf") # Copies the string in content into /tmp/file.log provisioner2 = terrascript.Provisioner("file", source="ami used: ${self.ami}", destination="/tmp/file.log") # Copies the configs.d folder to /etc/configs.d provisioner3 = terrascript.Provisioner("file", source="conf/configs.d", destination="/etc") # Copies all files and folders in apps/app1 to D:/IIS/webapp1 provisioner4 = terrascript.Provisioner("file", source="apps/app1/", destination="D:/IIS/webapp1") config += terrascript.resource.aws_instance( "web", ami="AMI", instance_type="t2.micro", provisioner=[provisioner1, provisioner2, provisioner3, provisioner4], ) assert_equals_json(config, "test_005.tf.json")
def test_multiple_provisioners(self): create = terrascript.Provisioner("local-exec", command="echo 'Create'") destroy = terrascript.Provisioner( "local-exec", when="destroy", command="echo 'Destroy'" ) self.cfg += terrascript.resource.aws_instance( "instance1", instance_type="t2.micro", provisioner=[create, destroy] ) assert ( len(self.cfg["resource"]["aws_instance"]["instance1"]["provisioner"]) == 2 ) assert ( self.cfg["resource"]["aws_instance"]["instance1"]["provisioner"][0][ "local-exec" ]["command"] == "echo 'Create'" ) assert ( self.cfg["resource"]["aws_instance"]["instance1"]["provisioner"][1][ "local-exec" ]["command"] == "echo 'Destroy'" )
def test(): """Provisioner (005)""" config = terrascript.Terrascript() config += terrascript.provider.aws(version='~> 2.0', region='us-east-1') # Copies the myapp.conf file to /etc/myapp.conf provisioner1 = terrascript.Provisioner('file', source='conf/myapp.conf', destination='/etc/myapp.conf') # Copies the string in content into /tmp/file.log provisioner2 = terrascript.Provisioner('file', source='ami used: ${self.ami}', destination='/tmp/file.log') # Copies the configs.d folder to /etc/configs.d provisioner3 = terrascript.Provisioner('file', source='conf/configs.d', destination='/etc') # Copies all files and folders in apps/app1 to D:/IIS/webapp1 provisioner4 = terrascript.Provisioner('file', source='apps/app1/', destination='D:/IIS/webapp1') config += terrascript.resource.aws_instance( 'web', ami="AMI", instance_type="t2.micro", provisioner=[provisioner1, provisioner2, provisioner3, provisioner4]) assert_equals_json(config, 'test_005.tf.json')
def test_multiple_provisioners(self): create = terrascript.Provisioner("local-exec", command="echo 'Create'") destroy = terrascript.Provisioner("local-exec", when="destroy", command="echo 'Destroy'") self.cfg += terrascript.resource.aws_instance( 'instance1', instance_type="t2.micro", provisioner=[create, destroy]) assert len(self.cfg['resource']['aws_instance']['instance1'] ['provisioner']) == 2 assert self.cfg['resource']['aws_instance']['instance1'][ 'provisioner'][0]['local-exec']['command'] == "echo 'Create'" assert self.cfg['resource']['aws_instance']['instance1'][ 'provisioner'][1]['local-exec']['command'] == "echo 'Destroy'"
def test_one_provisioner(self): p = terrascript.Provisioner("local-exec", when="destroy", command="echo 'Destroy-time provisioner'") assert p['local-exec']['when'] == 'destroy' self.cfg += terrascript.resource.aws_instance('instance1', instance_type="t2.micro", provisioner=p) assert len(self.cfg['resource']['aws_instance']['instance1'] ['provisioner']) == 1 assert self.cfg['resource']['aws_instance']['instance1'][ 'provisioner']['local-exec']['when'] == 'destroy'
def test_one_provisioner(self): p = terrascript.Provisioner( "local-exec", when="destroy", command="echo 'Destroy-time provisioner'" ) assert p["local-exec"]["when"] == "destroy" self.cfg += terrascript.resource.aws_instance( "instance1", instance_type="t2.micro", provisioner=p ) assert ( len(self.cfg["resource"]["aws_instance"]["instance1"]["provisioner"]) == 1 ) assert ( self.cfg["resource"]["aws_instance"]["instance1"]["provisioner"][ "local-exec" ]["when"] == "destroy" )
# https://www.terraform.io/docs/provisioners/file.html import terrascript import terrascript.provider import terrascript.resource config = terrascript.Terrascript() config += terrascript.provider.aws(version="~> 2.0", region="us-east-1") # Copies the myapp.conf file to /etc/myapp.conf provisioner1 = terrascript.Provisioner("file", source="conf/myapp.conf", destination="/etc/myapp.conf") # Copies the string in content into /tmp/file.log provisioner2 = terrascript.Provisioner("file", source="ami used: ${self.ami}", destination="/tmp/file.log") # Copies the configs.d folder to /etc/configs.d provisioner3 = terrascript.Provisioner("file", source="conf/configs.d", destination="/etc") # Copies all files and folders in apps/app1 to D:/IIS/webapp1 provisioner4 = terrascript.Provisioner("file", source="apps/app1/", destination="D:/IIS/webapp1") config += terrascript.resource.aws_instance(
import terrascript import terrascript.provider import terrascript.resource config = terrascript.Terrascript() # AWS provider config += terrascript.provider.aws(region="us-east-1") # Provisioners create = terrascript.Provisioner("local-exec", command="echo 'Create'") destroy = terrascript.Provisioner("local-exec", when="destroy", command="echo 'Destroy'") # Resource with two provisioners config += terrascript.resource.aws_instance('instance1', instance_type="t2.micro", ami='ami-4bf3d731', provisioner=[create, destroy])