func (w ConfigWriter) Write(cfg config.Config) error {
	var err error

	nodeName := cfg.Consul.Agent.NodeName

	if nodeName == "" {
		nodeName, err = nodeNameFor(cfg.Path.DataDir, cfg.Node)
		if err != nil {
			w.logger.Error("config-writer.write.determine-node-name.failed", err)
			return err
		}
	}

	w.logger.Info("config-writer.write.determine-node-name", lager.Data{
		"node-name": nodeName,
	})

	w.logger.Info("config-writer.write.generate-configuration")
	consulConfig := config.GenerateConfiguration(cfg, w.dir, nodeName)

	data, err := json.Marshal(&consulConfig)
	if err != nil {
		return err
	}

	w.logger.Info("config-writer.write.write-file", lager.Data{
		"config": consulConfig,
	})
	err = ioutil.WriteFile(filepath.Join(w.dir, "config.json"), data, os.ModePerm)
	if err != nil {
		w.logger.Error("config-writer.write.write-file.failed", errors.New(err.Error()))
		return err
	}

	w.logger.Info("config-writer.write.success")
	return nil
}
				"performance": map[string]int{
					"raft_multiplier": 1,
				},
			}
			body, err := json.Marshal(conf)
			Expect(err).To(BeNil())
			Expect(buf).To(MatchJSON(body))

			Expect(logger.Messages()).To(ContainSequence([]fakes.LoggerMessage{
				{
					Action: "config-writer.write.generate-configuration",
				},
				{
					Action: "config-writer.write.write-file",
					Data: []lager.Data{{
						"config": config.GenerateConfiguration(cfg, configDir, "node-0"),
					}},
				},
				{
					Action: "config-writer.write.success",
				},
			}))
		})

		Context("node name", func() {
			Context("when node-name.json does not exist", func() {
				It("uses the job name-index and writes node-name.json", func() {
					err := writer.Write(cfg)
					Expect(err).NotTo(HaveOccurred())

					buf, err := ioutil.ReadFile(filepath.Join(dataDir, "node-name.json"))
	"path/filepath"

	"github.com/cloudfoundry-incubator/consul-release/src/confab/config"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("ConsulConfigDefiner", func() {
	Describe("GenerateConfiguration", func() {
		var consulConfig config.ConsulConfig
		var configDir string

		BeforeEach(func() {
			configDir = "/var/vcap/jobs/consul_agent/config"
			consulConfig = config.GenerateConfiguration(config.Config{}, configDir, "")
		})

		Describe("datacenter", func() {
			It("defaults to empty string", func() {
				Expect(consulConfig.Datacenter).To(Equal(""))
			})

			Context("when the `consul.agent.datacenter` property is set", func() {
				It("uses that value", func() {
					consulConfig = config.GenerateConfiguration(config.Config{
						Consul: config.ConfigConsul{
							Agent: config.ConfigConsulAgent{
								Datacenter: "my-datacenter",
							},
						},