コード例 #1
0
    def test_provisioner_with_variable_and_connection(self):
        plan = pytfe.Plan()
        variable = plan.add(pytfe.variable('user_name', type='string'))
        provisioner = pytfe.provisioner(
            'file',
            source=Quote("conf/myapp.conf"),
            destination=Quote("/etc/myapp.conf"),
            connection=pytfe.Connection(
                type=Quote("ssh"),
                user=Quote("root"),
                password=variable.user_name,
                host="var.host"
            )
        )
        plan += provisioner

        expected = pytfe.TFBlock("""
        provisioner "file" {
          source = "conf/myapp.conf"
          destination = "/etc/myapp.conf"
          connection {
            type = "ssh"
            user = "******"
            password = var.user_name
            host = var.host
          }
        }""")
        self.assertEqual(plan.format(), expected)
コード例 #2
0
 def test_simple_resource(self):
     variable = pytfe.Variable(
         'redis_image', type=Quote("string"), default=Quote('v1.2')
     )
     expected = pytfe.TFBlock("""
     variable "redis_image" {
       type = "string"
       default = "v1.2"
     }""")
     self.assertEqual(variable.format(), expected)
コード例 #3
0
 def test_simple_resource(self):
     function = pytfe.Resource(
         'docker_container', "redis", image=Quote('redis'), name=Quote('foo')
     )
     expected = pytfe.TFBlock("""
     resource "docker_container" "redis" {
       image = "redis"
       name = "foo"
     }""")
     self.assertEqual(function.format(), expected)
コード例 #4
0
 def test_simple(self):
     obj = pytfe.Connection(
         type=Quote("winrm"),
         user=Quote("Administrator"),
     )
     expected = pytfe.TFBlock("""
     connection {
       type = "winrm"
       user = "******"
     }""")
     self.assertEqual(obj.format(), expected)
コード例 #5
0
 def test_simple(self):
     module = pytfe.Module(
         'consul',
         source=Quote("hashicorp/consul/aws"),
         version=Quote("0.0.5"),
         servers=3
     )
     expected = pytfe.TFBlock("""
     module "consul" {
       source = "hashicorp/consul/aws"
       version = "0.0.5"
       servers = 3
     }""")
     self.assertEqual(module.format(), expected)
コード例 #6
0
    def test_format_locals(self):

        local = pytfe.Locals(service_name=Quote('forum'))
        expected = pytfe.TFBlock("""
        locals {
          service_name = "forum"
        }""")
        self.assertEqual(local.format(), expected)
コード例 #7
0
    def test_format_locals_with_map(self):

        local = pytfe.Locals(local_map={'hello': Quote('world')})
        expected = pytfe.TFBlock("""
        locals {
          local_map = {
            hello = "world"
          }
        }""")
        self.assertEqual(local.format(), expected)
コード例 #8
0
    def test_format_locals_with_list(self):

        local = pytfe.Locals(local_list=[Quote('string'), '"string2"'])
        expected = pytfe.TFBlock("""
        locals {
          local_list = [
            "string",
            "string2"
          ]
        }""")
        self.assertEqual(local.format(), expected)
コード例 #9
0
 def test_provisioner_with_connection(self):
     obj = pytfe.Provisioner(
         'local-exec',
         command=Quote("echo The server's IP address is ${self.private_ip}"),
         on_failure=Raw("continue"),
         connection=pytfe.Connection(
             type=Quote("winrm"),
             user=Quote("Administrator"),
         )
     )
     expected = pytfe.TFBlock("""
     provisioner "local-exec" {
       command = "echo The server's IP address is ${self.private_ip}"
       on_failure = continue
       connection {
         type = "winrm"
         user = "******"
       }
     }""")
     self.assertEqual(obj.format(), expected)
コード例 #10
0
 def test_simple(self):
     obj = pytfe.Provisioner(
         'local-exec',
         command=Quote("echo The server's IP address is ${self.private_ip}"),
         on_failure="continue"
     )
     expected = pytfe.TFBlock("""
     provisioner "local-exec" {
       command = "echo The server's IP address is ${self.private_ip}"
       on_failure = continue
     }""")
     self.assertEqual(obj.format(), expected)
コード例 #11
0
 def test_simple(self):
     module = pytfe.terraform(
         pytfe.backend(
             'consul',
             address='"demo.consul.io"',
             scheme='"https"',
             path='"example_app/terraform_state"'
         ),
         source=Quote("hashicorp/consul/aws"),
         version=Quote("0.0.5")
     )
     expected = pytfe.TFBlock("""
     terraform {
       backend "consul" {
         address = "demo.consul.io"
         scheme = "https"
         path = "example_app/terraform_state"
       }
       source = "hashicorp/consul/aws"
       version = "0.0.5"
     }""")
     self.assertEqual(module.format(), expected)
コード例 #12
0
    def test_complex_variable(self):
        """
        source: https://www.terraform.io/docs/language/values/variables.html#declaring-an-input-variable
        """
        variable = pytfe.variable(
            'docker_ports',
            type=pytfe.function(
                'list',
                pytfe.function(
                    'object',
                    internal='number',
                    external='number',
                    protocol='string'
                )
            ),
            default=[
                dict(
                    internal=8300,
                    external=8300,
                    protocol=Quote("tcp")
                )
            ]
        )

        expected = pytfe.TFBlock("""
        variable "docker_ports" {
          type = list(object({
            internal = number
            external = number
            protocol = string
          }))
          default = [
            {
              internal = 8300
              external = 8300
              protocol = "tcp"
            }
          ]
        }""")
        self.assertEqual(variable.format(), expected)