简体   繁体   中英

How to provide encoded json data to resources in cdktf for grafana

I appear to be an early adopter of cdktf for grafana using python. The following config is successfully transmitted and accepted by grafana

    DataSource(self, "xxx",
    uid = "datasource_influxdb",
    type = "influxdb",
    name = "...",
    url  = "...",
    json_data= [DataSourceJsonData(
        default_bucket    = "xxx",
        http_method       = "POST",
        organization      = "xxx",
        version           = "Flux",
        tls_skip_verify   = "true"
    )]
    )

The documentation is unclear on how to provide json_data_encoded and secure_json_data_encoded .

I have a working terraform config: ( terraform grafana_provider datasource_influx2 encode not working? / How to provide an influx2 token? )

The solution is simple python json encoding using json.dumps(dict())

    DataSource(self, "xxx",
    uid = "datasource_influxdb",
    type = "influxdb",
    name = "xxx",
    url  = "xxx
    json_data_encoded = json.dumps(
        dict(defaultBucket    = "xxx",
        httpMode       = "POST",
        organization      = "xxx",
        version           = "Flux",
        tlsSkipVerify     = True)
    ),
    secure_json_data_encoded = json.dumps(
        dict(token = "xxx")
    )
    )

Beware to use the actual keys required by grafana and ignore the mappings of cdktf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM