Skip to content

Commit

Permalink
Merge pull request #1309 from mdb/mdb/parse-plan-json
Browse files Browse the repository at this point in the history
publicly expose terraform.ParsePlanJSON function
  • Loading branch information
denis256 committed Jul 10, 2023
2 parents d58da78 + 7f28553 commit c6a3be9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/terraform/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func InitAndPlanAndShowWithStructE(t testing.TestingT, options *Options) (*PlanS
if err != nil {
return nil, err
}
return parsePlanJson(jsonOut)
return ParsePlanJSON(jsonOut)
}

// InitAndPlanWithExitCode runs terraform init and plan with the given options and returns exitcode for the plan command.
Expand Down
4 changes: 2 additions & 2 deletions modules/terraform/plan_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type PlanStruct struct {
ResourceChangesMap map[string]*tfjson.ResourceChange
}

// parsePlanJson takes in the json string representation of the terraform plan and returns a go struct representation
// ParsePlanJSON takes in the json string representation of the terraform plan and returns a go struct representation
// for easy introspection.
func parsePlanJson(jsonStr string) (*PlanStruct, error) {
func ParsePlanJSON(jsonStr string) (*PlanStruct, error) {
plan := &PlanStruct{}

if err := json.Unmarshal([]byte(jsonStr), &plan.RawPlan); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions modules/terraform/plan_struct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestPlannedValuesMapWithBasicJson(t *testing.T) {

// Retrieve test data from the terraform-json project.
_, jsonData := http_helper.HttpGet(t, basicJsonUrl, nil)
plan, err := parsePlanJson(jsonData)
plan, err := ParsePlanJSON(jsonData)
require.NoError(t, err)

query := []string{
Expand All @@ -48,7 +48,7 @@ func TestPlannedValuesMapWithDeepModuleJson(t *testing.T) {

// Retrieve test data from the terraform-json project.
_, jsonData := http_helper.HttpGet(t, deepModuleJsonUrl, nil)
plan, err := parsePlanJson(jsonData)
plan, err := ParsePlanJSON(jsonData)
require.NoError(t, err)

query := []string{
Expand All @@ -64,7 +64,7 @@ func TestResourceChangesJson(t *testing.T) {

// Retrieve test data from the terraform-json project.
_, jsonData := http_helper.HttpGet(t, changesJsonUrl, nil)
plan, err := parsePlanJson(jsonData)
plan, err := ParsePlanJSON(jsonData)
require.NoError(t, err)

// Spot check a few changes to make sure the right address was registered
Expand Down
2 changes: 1 addition & 1 deletion modules/terraform/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func ShowWithStructE(t testing.TestingT, options *Options) (*PlanStruct, error)
if err != nil {
return nil, err
}
planStruct, err := parsePlanJson(json)
planStruct, err := ParsePlanJSON(json)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit c6a3be9

Please sign in to comment.