scottwinkler / terraform-provider-shell

Terraform provider for executing shell commands and saving output to state file
Mozilla Public License 2.0
279 stars 60 forks source link

complex JSON fix #33

Closed scottwinkler closed 4 years ago

scottwinkler commented 4 years ago

Fixes tickets #31 and #32.

This fixes the way JSON is parsed from the output to allow support for more complex JSON strings. Previously only JSON that matched exactly a map[string]string could be returned from a shell_script resource. Now any JSON can be returned It will still be converted to a map[string]string and any complex values will be flattened. For example, the following JSON would return the following output:

{
  "last_state_loss_time": 0,
  "spark_version": "5.3.x-scala2.11",
  "azure_attributes": {},
  "state": "PENDING",
  "enable_elastic_disk": true,
  "init_scripts_safe_mode": false,
  "num_workers": 1,
  "driver_node_type_id": "Standard_D3_v2",
  "default_tags": {
    "Creator": "lagripp@microsoft.com",
    "ClusterName": "my-cluster",
    "ClusterId": "0327-174802-howdy690",
    "Vendor": "Databricks"
  },
  "creator_user_name": "lagripp@microsoft.com",
  "cluster_id": "0327-174802-howdy690",
  "cluster_name": "my-cluster",
  "node_type_id": "Standard_D3_v2",
  "state_message": "Finding instances for new nodes, acquiring more instances if necessary",
  "enable_local_disk_encryption": false,
  "autotermination_minutes": 0,
  "cluster_source": "API",
  "start_time": 1585331282783,
  "spark_conf": {
    "spark.speculation": "true"
  }
            "output": {
              "autotermination_minutes": "0",
              "azure_attributes": "{}",
              "cluster_id": "0327-174802-howdy690",
              "cluster_name": "my-cluster",
              "cluster_source": "API",
              "creator_user_name": "lagripp@microsoft.com",
              "default_tags": "{    \"Creator\": \"lagripp@microsoft.com\",    \"ClusterName\": \"my-cluster\",    \"ClusterId\": \"0327-174802-howdy690\",    \"Vendor\": \"Databricks\"  }",
              "driver_node_type_id": "Standard_D3_v2",
              "enable_elastic_disk": "true",
              "enable_local_disk_encryption": "false",
              "init_scripts_safe_mode": "false",
              "last_state_loss_time": "0",
              "node_type_id": "Standard_D3_v2",
              "num_workers": "1",
              "spark_conf": "{    \"spark.speculation\": \"true\"  }",
              "spark_version": "5.3.x-scala2.11",
              "start_time": "1585331282783",
              "state": "PENDING",
              "state_message": "Finding instances for new nodes, acquiring more instances if necessary"
            },