func deployConsul(deploymentPrefix string, count int, client bosh.Client, config Config, releaseVersion string, manifestGenerator ManifestGenerator) (manifest consul.ManifestV2, kv consulclient.HTTPKV, err error) {
	guid, err := NewGUID()
	if err != nil {
		return
	}

	info, err := client.Info()
	if err != nil {
		return
	}

	manifestConfig := consul.ConfigV2{
		DirectorUUID:   info.UUID,
		Name:           fmt.Sprintf("consul-%s-%s", deploymentPrefix, guid),
		TurbulenceHost: config.TurbulenceHost,
		WindowsClients: config.WindowsClients,
	}

	var iaasConfig iaas.Config
	switch info.CPI {
	case "aws_cpi":
		manifestConfig.PersistentDiskType = config.BOSH.Errand.DefaultPersistentDiskType
		manifestConfig.VMType = config.BOSH.Errand.DefaultVMType

		awsConfig := buildAWSConfig(config)
		if len(config.AWS.Subnets) > 0 {
			subnet := config.AWS.Subnets[0]

			var cidrBlock string
			cidrPool := NewCIDRPool(subnet.Range, 24, 27)
			cidrBlock, err = cidrPool.Get(ginkgoConfig.GinkgoConfig.ParallelNode)
			if err != nil {
				return
			}

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: cidrBlock, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.AZs = append(manifestConfig.AZs, consul.ConfigAZ{IPRange: cidrBlock, Nodes: count, Name: "z1"})
		} else {
			err = errors.New("AWSSubnet is required for AWS IAAS deployment")
			return
		}

		iaasConfig = awsConfig
	case "warden_cpi":
		iaasConfig = iaas.NewWardenConfig()

		var cidrBlock string
		cidrPool := NewCIDRPool("10.244.4.0", 24, 27)
		cidrBlock, err = cidrPool.Get(ginkgoConfig.GinkgoConfig.ParallelNode)
		if err != nil {
			return
		}

		manifestConfig.AZs = []consul.ConfigAZ{
			{
				IPRange: cidrBlock,
				Nodes:   count,
				Name:    "z1",
			},
		}
	default:
		err = errors.New("unknown infrastructure type")
		return
	}

	manifest, err = manifestGenerator(manifestConfig, iaasConfig)
	if err != nil {
		return
	}

	for i := range manifest.Releases {
		if manifest.Releases[i].Name == "consul" {
			manifest.Releases[i].Version = releaseVersion
		}
	}

	yaml, err := manifest.ToYAML()
	if err != nil {
		return
	}

	yaml, err = client.ResolveManifestVersions(yaml)
	if err != nil {
		return
	}

	err = consul.FromYAML(yaml, &manifest)
	if err != nil {
		return
	}

	_, err = client.Deploy(yaml)
	if err != nil {
		return
	}

	err = VerifyDeploymentRelease(client, manifestConfig.Name, releaseVersion)
	if err != nil {
		return
	}

	kv = consulclient.NewHTTPKV(fmt.Sprintf("http://%s:6769", manifest.InstanceGroups[1].Networks[0].StaticIPs[0]))
	return
}
				Expect(members).To(Equal([]consul.ConsulMember{
					{
						Address: "10.244.5.2",
					},
				}))
			})
		})
	})

	Describe("FromYAML", func() {
		It("returns a Manifest matching the given YAML", func() {
			consulManifest, err := ioutil.ReadFile("fixtures/consul_manifest.yml")
			Expect(err).NotTo(HaveOccurred())

			var manifest consul.Manifest
			err = consul.FromYAML(consulManifest, &manifest)
			Expect(err).NotTo(HaveOccurred())

			Expect(manifest.DirectorUUID).To(Equal("some-director-uuid"))
			Expect(manifest.Name).To(Equal("consul"))
			Expect(manifest.Releases).To(HaveLen(1))
			Expect(manifest.Releases).To(ContainElement(core.Release{
				Name:    "consul",
				Version: "latest",
			}))
			Expect(manifest.Compilation).To(Equal(core.Compilation{
				Network:             "consul1",
				ReuseCompilationVMs: true,
				Workers:             3,
			}))
			Expect(manifest.Update).To(Equal(core.Update{
func DeployMultiAZConsul(deploymentPrefix string, client bosh.Client, config Config) (manifest consul.Manifest, err error) {
	guid, err := NewGUID()
	if err != nil {
		return
	}

	info, err := client.Info()
	if err != nil {
		return
	}

	manifestConfig := consul.Config{
		DirectorUUID: info.UUID,
		Name:         fmt.Sprintf("consul-%s-%s", deploymentPrefix, guid),
	}

	var iaasConfig iaas.Config
	switch info.CPI {
	case "aws_cpi":
		awsConfig := buildAWSConfig(config)
		if len(config.AWS.Subnets) >= 2 {
			subnet := config.AWS.CloudConfigSubnets[0]

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: subnet.Range, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.Networks = append(manifestConfig.Networks, consul.ConfigNetwork{IPRange: subnet.Range, Nodes: 2})

			subnet = config.AWS.CloudConfigSubnets[1]

			awsConfig.Subnets = append(awsConfig.Subnets, iaas.AWSConfigSubnet{ID: subnet.ID, Range: subnet.Range, AZ: subnet.AZ, SecurityGroup: subnet.SecurityGroup})
			manifestConfig.Networks = append(manifestConfig.Networks, consul.ConfigNetwork{IPRange: subnet.Range, Nodes: 1})
		} else {
			err = errors.New("AWSSubnet is required for AWS IAAS deployment")
			return
		}

		iaasConfig = awsConfig
	case "warden_cpi":
		iaasConfig = iaas.NewWardenConfig()

		manifestConfig.Networks = []consul.ConfigNetwork{
			{IPRange: "10.244.4.0/24", Nodes: 2},
			{IPRange: "10.244.5.0/24", Nodes: 1},
		}
	default:
		err = errors.New("unknown infrastructure type")
		return
	}

	manifest, err = consul.NewManifest(manifestConfig, iaasConfig)
	if err != nil {
		return
	}

	for i := range manifest.Releases {
		if manifest.Releases[i].Name == "consul" {
			manifest.Releases[i].Version = ConsulReleaseVersion()
		}
	}

	yaml, err := manifest.ToYAML()
	if err != nil {
		return
	}

	yaml, err = client.ResolveManifestVersions(yaml)
	if err != nil {
		return
	}

	err = consul.FromYAML(yaml, &manifest)
	if err != nil {
		return
	}

	_, err = client.Deploy(yaml)
	if err != nil {
		return
	}

	err = VerifyDeploymentRelease(client, manifestConfig.Name, ConsulReleaseVersion())
	if err != nil {
		return
	}

	return
}