Skip to content

Commit

Permalink
asset/cluster: Copy the terraform.tfvars
Browse files Browse the repository at this point in the history
Copy the terraform.tfvars to the working dir for the terraform.
  • Loading branch information
Yifan Gu authored and crawford committed Sep 23, 2018
1 parent f8bf4f2 commit 96adf3c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pkg/asset/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/terraform"
Expand Down Expand Up @@ -38,23 +39,26 @@ func (c *Cluster) Dependencies() []asset.Asset {

// Generate launches the cluster and generates the terraform state file on disk.
func (c *Cluster) Generate(parents map[asset.Asset]*asset.State) (*asset.State, error) {
dir, err := terraform.BaseLocation()
if err != nil {
return nil, err
}

state, ok := parents[c.tfvars]
if !ok {
return nil, fmt.Errorf("failed to get terraform.tfvar state in the parent asset states")
}

// Copy the terraform.tfvars to the working dir for the terraform.
if err := ioutil.WriteFile(filepath.Join(dir, state.Contents[0].Name), state.Contents[0].Data, 0600); err != nil {
return nil, fmt.Errorf("failed to write terraform.tfvars file: %v", err)
}

var tfvars config.Cluster
if err := json.Unmarshal(state.Contents[0].Data, &tfvars); err != nil {
return nil, fmt.Errorf("failed to unmarshal terraform tfvars file: %v", err)
}

dir, err := terraform.BaseLocation()
if err != nil {
return nil, err
}

var result asset.State

templateDir, err := terraform.FindStepTemplates(dir, terraform.InfraStep, tfvars.Platform)
if err != nil {
return nil, err
Expand All @@ -75,12 +79,13 @@ func (c *Cluster) Generate(parents map[asset.Asset]*asset.State) (*asset.State,
return nil, fmt.Errorf("failed to read tfstate file %q: %v", stateFile, err)
}

result.Contents = append(result.Contents, asset.Content{
Name: stateFileName,
Data: data,
})

// TODO(yifan): Use the kubeconfig to verify the cluster is up.

return &result, nil
return &asset.State{
Contents: []asset.Content{
{
Name: stateFileName,
Data: data,
},
},
}, nil
}

0 comments on commit 96adf3c

Please sign in to comment.