import ( "github.com/hashicorp/terraform/configs" "github.com/hashicorp/terraform/terraform" ) func getCurrentConfig() (*configs.Config, error) { state := terraform.ReadStateFromFile("terraform.tfstate") root := state.RootModule() return root.Config(), nil }
for _, r := range root.Resources() { fmt.Printf("Resource: %s (%s)\n", r.Type(), r.Name()) }This code loops through all resources in the root module and prints their type and name. Overall, the github.com.hashicorp.terraform.terraform package library provides useful tools for working with Terraform in Go, including the State RootModule for managing Terraform configurations.