


How to create a custom terraform data source provider schema for a map of map values?
php editor Banana today will introduce you how to create a custom terraform data source provider architecture for a map of map values. When using Terraform for infrastructure orchestration, we often need to obtain data from external systems or services for dynamic configuration. And a custom data source provider can help us achieve this goal. By creating a custom data source provider schema, we can easily get the data we need from the map of map values and apply it in our Terraform configuration. Next, let’s learn how to achieve it!
Question content
I have a golang function that returns a role of type map[string]map[string]string
map[foo:map[name:abc env:dev id:465 project:e-1] boo:map[name:def env:prd id:82 project:e-1] :doo[name:ght env:stg id:353 project:e-3]]
func datasourceaccounthelper() *schema.resource { return &schema.resource{ read: accounthelperread, schema: map[string]*schema.schema{ "roles": { type: schema.typemap, elem: &schema.schema{ type: schema.typemap, computed: true, elem: &schema.schema{ type: schema.typestring, }, }, computed: true, }, "id": &schema.schema{ computed: true, type: schema.typestring, }, }, } }
func rolesread(d *schema.resourcedata, m interface{}) error { filteredroles := filteraccounts("john") // returns `map[string]map[string]string` if err := d.set("account_map", filteredroles); err != nil { return err } //accountmaps := make(map[string]interface{}) d.setid("-") return nil }
outputs: output = { "roles" = tomap(null) /* of map of string */ "id" = tostring(null) }
Outputs: output = { "roles" = { foo = {name = "abc" env = "dev" id= 465 project = "e-1"} boo = {name = "efg" env = "prd" id= 82 project = "e-2"} }, "id" = "-" }
typestring,
typeint,
typebool.
migrate to the new framework , which is built for the type system of modern terraform, rather than (as is the case with sdkv2) that of classic terraform v0.11 and earlier Type system.
In the terraform plugin framework, the equivalent structure to what you are trying to describe here ismapnestedattribute, and the following describes the schema structure you show in your question:
schema.mapnestedattribute{ nestedobject: schema.nestedattributeobject{ attributes: map[string]schema.attribute{ "name": schema.stringattribute{ // ... }, "env": schema.stringattribute{ // ... }, "id": schema.numberattribute{ // ... }, "project": schema.stringattribute{ // ... }, }, }, }
The type constraint syntax of the terraform language :
map( object({ name = string env = string id = number project = string }) )
The above is the detailed content of How to create a custom terraform data source provider schema for a map of map values?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Go language performs well in building efficient and scalable systems. Its advantages include: 1. High performance: compiled into machine code, fast running speed; 2. Concurrent programming: simplify multitasking through goroutines and channels; 3. Simplicity: concise syntax, reducing learning and maintenance costs; 4. Cross-platform: supports cross-platform compilation, easy deployment.

Golang is better than C in concurrency, while C is better than Golang in raw speed. 1) Golang achieves efficient concurrency through goroutine and channel, which is suitable for handling a large number of concurrent tasks. 2)C Through compiler optimization and standard library, it provides high performance close to hardware, suitable for applications that require extreme optimization.

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Golang and C each have their own advantages in performance competitions: 1) Golang is suitable for high concurrency and rapid development, and 2) C provides higher performance and fine-grained control. The selection should be based on project requirements and team technology stack.

Goimpactsdevelopmentpositivelythroughspeed,efficiency,andsimplicity.1)Speed:Gocompilesquicklyandrunsefficiently,idealforlargeprojects.2)Efficiency:Itscomprehensivestandardlibraryreducesexternaldependencies,enhancingdevelopmentefficiency.3)Simplicity:

C is more suitable for scenarios where direct control of hardware resources and high performance optimization is required, while Golang is more suitable for scenarios where rapid development and high concurrency processing are required. 1.C's advantage lies in its close to hardware characteristics and high optimization capabilities, which are suitable for high-performance needs such as game development. 2.Golang's advantage lies in its concise syntax and natural concurrency support, which is suitable for high concurrency service development.

The performance differences between Golang and C are mainly reflected in memory management, compilation optimization and runtime efficiency. 1) Golang's garbage collection mechanism is convenient but may affect performance, 2) C's manual memory management and compiler optimization are more efficient in recursive computing.
