Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/divineomega/php-hcl-parser
⚒🔀🐘 Parses HCL configuration files into PHP objects.
https://github.com/divineomega/php-hcl-parser
configuration hcl parser php-library php-object terraform
Last synced: 11 days ago
JSON representation
⚒🔀🐘 Parses HCL configuration files into PHP objects.
- Host: GitHub
- URL: https://github.com/divineomega/php-hcl-parser
- Owner: DivineOmega
- License: gpl-3.0
- Created: 2018-04-10T15:04:40.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-23T09:13:31.000Z (over 4 years ago)
- Last Synced: 2024-10-15T02:37:30.820Z (23 days ago)
- Topics: configuration, hcl, parser, php-library, php-object, terraform
- Language: PHP
- Homepage:
- Size: 30.3 KB
- Stars: 14
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ⚒🔀🐘 PHP HCL Parser
[![Build Status](https://travis-ci.org/DivineOmega/php-hcl-parser.svg?branch=master)](https://travis-ci.org/DivineOmega/php-hcl-parser)
[![Coverage Status](https://coveralls.io/repos/github/DivineOmega/php-hcl-parser/badge.svg?branch=master)](https://coveralls.io/github/DivineOmega/php-hcl-parser?branch=master)
[![StyleCI](https://styleci.io/repos/128951643/shield?branch=master)](https://styleci.io/repos/128951643)HCL is a configuration language make by HashiCorp. HCL files are used by several HashiCorp products,
including Terraform.This library parses HCL configuration files into PHP objects.
## Installation
You can install the PHP HCL Parser library using Composer. Just run the following command
from the root of your project.```
composer require divineomega/php-hcl-parser
```## Usage
To parse HCL into a PHP object, create a new `HCLParser` object, passing it the HCL (as a string), then call the `parse` method. See the example below.
```php
$hcl = file_get_contents('example.tf');
$configObject = (new HCLParser($hcl))->parse();
```The resulting object will look similar to the following.
```php
object(stdClass)#5 (2) {
["provider"]=>
array(1) {
[0]=>
object(stdClass)#4 (1) {
["aws"]=>
array(1) {
[0]=>
object(stdClass)#2 (3) {
["access_key"]=>
string(17) "${var.access_key}"
["region"]=>
string(13) "${var.region}"
["secret_key"]=>
string(17) "${var.secret_key}"
}
}
}
}
["resource"]=>
array(1) {
[0]=>
object(stdClass)#8 (1) {
["aws_instance"]=>
array(1) {
[0]=>
object(stdClass)#7 (1) {
["example"]=>
array(1) {
[0]=>
object(stdClass)#6 (2) {
["ami"]=>
string(12) "ami-2757f631"
["instance_type"]=>
string(8) "t2.micro"
}
}
}
}
}
}
}
```