def test_update_override_value(): ts = Terrascript() ts2 = Terrascript() ts.add(variable('access_key')) ts.add(variable('secret_key')) var_region = ts.add(variable('region', default='us-east-1')) var_region2 = ts2.add(variable('region', default='ca-central-1')) assert var_region._kwargs['default'] != var_region2._kwargs['default'] # ts2 override variable "region" in ts ts.update(ts2) assert isinstance(ts, Terrascript) assert isinstance(ts2, Terrascript) ts_variables = ts.config.get('variable', {}) assert len(ts_variables.items()) == 3 # ensure that only three ts_var_region = ts_variables.get('region', {}) assert ts_var_region.get('default', '') == var_region2._kwargs.get('default') assert ts.validate(delete=False) is True
def test_issue35(): """Issue 35: missing some vSphere data sources and resources.""" ts = Terrascript() ts += r.vsphere_custom_attribute( "attribute", name="terraform-test-attribute", managed_object_type="VirtualMachine", ) ts += r.vsphere_datastore_cluster( "datastore_cluster", name="terraform-datastore-cluster-test", datacenter_id="ID", sdrs_enabled=True, ) ts += r.vsphere_storage_drs_vm_override( "drs_vm_override", datastore_cluster_id="ID1", virtual_machine_id="IS2", sdrs_enabled=False, ) ts += d.vsphere_custom_attribute("attribute", name="terraform-test-attribute") ts += d.vsphere_datastore_cluster("datastore_cluster", name="datastore-cluster1", datacenter_id="ID") assert ts.validate() is True
def test_issue33(): """Issue 33: Suggestion of syntax to terrascript""" ts = Terrascript() var_access_key = ts.add(variable('access_key')) assert isinstance(var_access_key, variable) var_secret_key = ts.add(variable('secret_key')) assert isinstance(var_secret_key, variable) var_region = ts.add(variable('region', default='us-east-1')) assert isinstance(var_region, variable) ts += provider('aws', access_key=var_access_key, secret_key=var_secret_key, region=var_region ) resource_aws_instance = ts.add(aws_instance('example', ami='ami-2757f631', instance_type='t2.micro')) assert isinstance(resource_aws_instance, aws_instance) ts += output('example_public_ip', value=resource_aws_instance.public_ip, description='Public IP of example') assert ts.validate() is True
def test_issue35(): """Issue 35: missing some vSphere data sources and resources.""" ts = Terrascript() ts += r.vsphere_custom_attribute('attribute', name='terraform-test-attribute', managed_object_type='VirtualMachine') ts += r.vsphere_datastore_cluster('datastore_cluster', name='terraform-datastore-cluster-test', datacenter_id='ID', sdrs_enabled=True) ts += r.vsphere_storage_drs_vm_override('drs_vm_override', datastore_cluster_id='ID1', virtual_machine_id='IS2', sdrs_enabled=False) ts += d.vsphere_custom_attribute('attribute', name='terraform-test-attribute') ts += d.vsphere_datastore_cluster('datastore_cluster', name='datastore-cluster1', datacenter_id='ID') assert ts.validate() is True
def test_issue32(): """Issue 32: provisioner return one line with provisioner.file instead a dictionary.""" ts = Terrascript() ts += provider('aws', region='ap-southeast-2') p = provisioner('local-exec', command='date > $(mktemp tmpXXXXXXX.terrascript)') ts += aws_instance('I1', ami='ami-60a26a02', instance_type='t2.nano', provisioner=p) j = ts.dump() assert 'mktemp' in j assert ts.validate() is True
def test_update_add_value(): ts = Terrascript() ts2 = Terrascript() var_access_key = ts.add(variable('access_key')) var_secret_key = ts.add(variable('secret_key')) var_region = ts.add(variable('region', default='us-east-1')) ts += provider('aws', access_key=var_access_key, secret_key=var_secret_key, region=var_region) resource_aws_instance = ts.add( aws_instance('example', ami='ami-2757f631', instance_type='t2.micro')) resource_aws_instance_2 = ts2.add( aws_instance('example_second', ami='ami-2757f631', instance_type='t2.micro')) assert isinstance(resource_aws_instance, aws_instance) assert isinstance(resource_aws_instance_2, aws_instance) # ts2 add resource "example_second" to ts ts.update(ts2) assert isinstance(ts, Terrascript) assert isinstance(ts2, Terrascript) ts_resources = ts.config.get('resource', {}) assert len(ts_resources.items()) == 1 ts_aws_instances = ts_resources.get('aws_instance') assert len(ts_aws_instances.items()) == 2 assert resource_aws_instance._name in ts_aws_instances.keys() assert resource_aws_instance_2._name in ts_aws_instances.keys() assert ts.validate(delete=False) is True