terraform-forge 0.1.6

Terraform provider code generator from OpenAPI specs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
use std::collections::HashSet;
use std::fmt::Write as _;

use openapi_forge::Spec;

use crate::error::ForgeError;
use crate::resource_gen::render_read_mapping_code;
use crate::schema_gen::{TfAttribute, render_single_attribute};
use crate::spec::{DataSourceSpec, ProviderDefaults};
use crate::type_map::{
    go_to_tf_attr, openapi_to_go, tf_value_type, to_go_public_name, to_tf_name, to_type_name,
};

/// Generated Go source for a complete TF data source.
#[derive(Debug, Clone, PartialEq, Eq)]
#[must_use]
pub struct GeneratedDataSource {
    pub file_name: String,
    pub go_code: String,
    pub data_source_type_name: String,
}

/// Generate TF schema attributes for a data source.
///
/// All fields are either Optional or Computed (no Required), since a data
/// source is read-only.
///
/// # Errors
///
/// Returns an error if referenced schemas are missing.
pub fn generate_datasource_attributes(
    ds: &DataSourceSpec,
    api: &Spec,
    defaults: &ProviderDefaults,
) -> Result<Vec<TfAttribute>, ForgeError> {
    let read_fields = api.fields(&ds.read.schema)?;

    let skip_fields: HashSet<&str> = defaults.skip_fields.iter().map(String::as_str).collect();

    let mut attributes = Vec::new();

    for field in &read_fields {
        let tf_name = to_tf_name(&field.name);

        if skip_fields.contains(field.name.as_str()) {
            continue;
        }

        let override_cfg = ds.fields.get(&field.name);
        if override_cfg.is_some_and(|o| o.skip) {
            continue;
        }

        let computed = override_cfg.is_some_and(|o| o.computed);
        let sensitive = override_cfg.is_some_and(|o| o.sensitive);

        let type_override = override_cfg.and_then(|o| o.type_override.as_deref());
        let go_type = openapi_to_go(&field.type_info, type_override);
        let tf_type = go_to_tf_attr(&go_type);

        let description = override_cfg
            .and_then(|o| o.description.clone())
            .or_else(|| field.description.clone())
            .unwrap_or_default();

        let default_value = field.default.as_ref().map(|v| format!("{v}"));

        // Data source fields: if originally required, make them Optional (input params).
        // If computed, make them Computed-only (output from API).
        // Otherwise Optional.
        let (required, optional) = if computed {
            (false, false) // Computed-only
        } else {
            (false, true) // Optional input param
        };

        attributes.push(TfAttribute {
            tf_name,
            go_name: to_go_public_name(&field.name),
            description,
            required,
            optional,
            computed: computed || !field.required,
            sensitive,
            force_new: false,
            tf_type_expr: tf_type.to_string(),
            tf_value_type: tf_value_type(&go_type).to_string(),
            go_type: go_type.to_string(),
            default_value,
        });
    }

    Ok(attributes)
}

/// Generate a complete terraform-plugin-framework data source Go file.
///
/// # Errors
///
/// Returns an error if schema generation fails.
pub fn generate_datasource(
    ds: &DataSourceSpec,
    api: &Spec,
    defaults: &ProviderDefaults,
    sdk_import: &str,
) -> Result<GeneratedDataSource, ForgeError> {
    let attrs = generate_datasource_attributes(ds, api, defaults)?;

    let type_name = to_type_name(&ds.data_source.name);

    let file_name = format!("datasource_{}.go", to_tf_name(&ds.data_source.name));

    let mut code = String::new();

    code.push_str(&render_ds_imports(&type_name, sdk_import));
    code.push_str(&render_ds_type(&type_name));
    code.push_str(&render_ds_model(&type_name, &attrs));
    code.push('\n');
    code.push_str(&render_ds_metadata(&ds.data_source.name));
    code.push_str(&render_ds_schema(&attrs, &ds.data_source.description));
    code.push('\n');
    code.push_str(&render_ds_configure(&type_name));
    code.push_str(&render_ds_read(
        &type_name,
        &ds.read.endpoint,
        &attrs,
        &ds.read_mapping,
    ));

    Ok(GeneratedDataSource {
        file_name,
        go_code: code,
        data_source_type_name: type_name,
    })
}

fn render_ds_imports(type_name: &str, sdk_import: &str) -> String {
    format!(
        r#"// Code generated by terraform-forge. DO NOT EDIT.

package resources

import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-log/tflog"

	akeyless_api "{sdk_import}"
)

var (
	_ datasource.DataSource              = &{type_name}DataSource{{}}
	_ datasource.DataSourceWithConfigure = &{type_name}DataSource{{}}
)

"#
    )
}

fn render_ds_type(type_name: &str) -> String {
    format!(
        r"type {type_name}DataSource struct {{
	client *AkeylessClient
}}

func New{type_name}DataSource() datasource.DataSource {{
	return &{type_name}DataSource{{}}
}}

"
    )
}

fn render_ds_model(type_name: &str, attrs: &[TfAttribute]) -> String {
    let struct_name = format!("{type_name}DataSourceModel");
    let mut out = String::new();
    let _ = writeln!(out, "type {struct_name} struct {{");
    let fields: String = attrs
        .iter()
        .map(|a| format!("\t{} {} `tfsdk:\"{}\"`\n", a.go_name, a.tf_value_type, a.tf_name))
        .collect();
    out.push_str(&fields);
    out.push_str("}\n");
    out
}

fn render_ds_metadata(ds_name: &str) -> String {
    let suffix = ds_name.strip_prefix("akeyless_").unwrap_or(ds_name);
    let type_name = to_type_name(ds_name);
    format!(
        r#"func (d *{type_name}DataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {{
	resp.TypeName = req.ProviderTypeName + "_{suffix}"
}}

"#,
    )
}

fn render_ds_schema(attrs: &[TfAttribute], description: &str) -> String {
    let mut out = String::new();
    out.push_str("func (d *Resource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {\n");
    out.push_str("\tresp.Schema = schema.Schema{\n");
    let desc = description.replace('"', "\\\"");
    let _ = writeln!(out, "\t\tDescription: \"{desc}\",");
    out.push_str("\t\tAttributes: map[string]schema.Attribute{\n");

    let attr_code: String = attrs.iter().map(render_single_attribute).collect();
    out.push_str(&attr_code);

    out.push_str("\t\t},\n");
    out.push_str("\t}\n");
    out.push_str("}\n");
    out
}

fn render_ds_configure(type_name: &str) -> String {
    format!(
        r#"func (d *{type_name}DataSource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {{
	if req.ProviderData == nil {{
		return
	}}

	client, ok := req.ProviderData.(*AkeylessClient)
	if !ok {{
		resp.Diagnostics.AddError(
			"Unexpected DataSource Configure Type",
			fmt.Sprintf("Expected *AkeylessClient, got: %T", req.ProviderData),
		)
		return
	}}

	d.client = client
}}

"#
    )
}

fn render_ds_read(
    type_name: &str,
    endpoint: &str,
    attrs: &[TfAttribute],
    read_mapping: &std::collections::BTreeMap<String, String>,
) -> String {
    let field_reads = render_read_mapping_code(attrs, read_mapping);

    // Find a suitable id field: prefer "name", otherwise first Optional string field
    let id_field = attrs.iter().find(|a| a.tf_name == "name").or_else(|| {
        attrs
            .iter()
            .find(|a| a.optional && a.tf_value_type == "types.String")
    });

    let id_setup = if let Some(id_attr) = id_field {
        let go_name = &id_attr.go_name;
        format!(
            r#"	body := akeyless_api.NewReadBody("{endpoint}")
	id := state.{go_name}.ValueString()
	body.Set{go_name}(&id)
"#
        )
    } else {
        format!("\tbody := akeyless_api.NewReadBody(\"{endpoint}\")\n")
    };

    format!(
        r#"func (d *{type_name}DataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {{
	var state {type_name}DataSourceModel
	diags := req.Config.Get(ctx, &state)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {{
		return
	}}

{id_setup}
	tflog.Debug(ctx, "Reading {type_name} data source")

	result, err := d.client.Call(ctx, body)
	if err != nil {{
		resp.Diagnostics.AddError("Error reading {type_name}", err.Error())
		return
	}}

{field_reads}
	diags = resp.State.Set(ctx, &state)
	resp.Diagnostics.Append(diags...)
}}
"#
    )
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::spec::DataSourceSpec;

    fn make_ds_test_data() -> (DataSourceSpec, Spec, ProviderDefaults) {
        let toml_str = r#"
[data_source]
name = "akeyless_auth_method"
description = "Read an auth method"

[read]
endpoint = "/get-auth-method"
schema = "GetAuthMethod"

[fields]
token = { skip = true }

[read_mapping]
"auth_method_access_id" = "access_id"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");

        let api_str = r#"
openapi: "3.0.0"
info: { title: Test, version: "1.0" }
paths:
  /get-auth-method:
    post:
      operationId: getAuthMethod
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetAuthMethod'
      responses:
        "200": { description: ok }
components:
  schemas:
    GetAuthMethod:
      type: object
      required: [name]
      properties:
        name: { type: string, description: "Auth method name" }
        access_id: { type: string, description: "Access ID" }
        token: { type: string }
"#;
        let api = Spec::parse(api_str).expect("parse");
        (ds, api, ProviderDefaults::default())
    }

    #[test]
    fn generate_datasource_attributes_test() {
        let (ds, api, defaults) = make_ds_test_data();
        let attrs = generate_datasource_attributes(&ds, &api, &defaults).expect("gen");

        // token should be skipped
        assert!(attrs.iter().all(|a| a.tf_name != "token"));

        // name should be Optional (data sources don't have Required)
        let name_attr = attrs.iter().find(|a| a.tf_name == "name").expect("name");
        assert!(!name_attr.required);
        assert!(name_attr.optional);

        // access_id should exist
        let access = attrs
            .iter()
            .find(|a| a.tf_name == "access_id")
            .expect("access_id");
        assert!(access.computed);
    }

    #[test]
    fn generate_full_datasource() {
        let (ds, api, defaults) = make_ds_test_data();
        let result = generate_datasource(
            &ds,
            &api,
            &defaults,
            "github.com/akeylesslabs/akeyless-go/v5",
        )
        .expect("gen");

        assert_eq!(result.file_name, "datasource_akeyless_auth_method.go");
        assert!(result.go_code.contains("AuthMethodDataSource"));
        assert!(
            result
                .go_code
                .contains("func (d *AuthMethodDataSource) Read")
        );
        assert!(
            result
                .go_code
                .contains("func (d *AuthMethodDataSource) Configure")
        );
        assert!(result.go_code.contains("AuthMethodDataSourceModel"));
    }

    #[test]
    fn datasource_read_mapping_generates_code() {
        let (ds, api, defaults) = make_ds_test_data();
        let result = generate_datasource(
            &ds,
            &api,
            &defaults,
            "github.com/akeylesslabs/akeyless-go/v5",
        )
        .expect("gen");

        // Should have GetNestedString call for the mapped field
        assert!(
            result
                .go_code
                .contains("GetNestedString(result, \"auth_method_access_id\")")
        );
        assert!(
            result
                .go_code
                .contains("state.AccessId = types.StringValue(v)")
        );
    }

    // --- Computed-only field (not Optional) ---

    #[test]
    fn datasource_computed_only_field_not_optional() {
        let toml_str = r#"
[data_source]
name = "akeyless_ds"
description = "DS"

[read]
endpoint = "/get"
schema = "GetDS"

[fields]
auto_field = { computed = true }
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths:
  /get:
    post:
      operationId: get
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetDS'
      responses:
        "200": { description: ok }
components:
  schemas:
    GetDS:
      type: object
      required: [name, auto_field]
      properties:
        name: { type: string }
        auto_field: { type: string }
"#;
        let api = Spec::parse(api_str).expect("parse");
        let attrs =
            generate_datasource_attributes(&ds, &api, &ProviderDefaults::default()).expect("gen");

        let auto = attrs
            .iter()
            .find(|a| a.tf_name == "auto_field")
            .expect("auto_field");
        assert!(!auto.required, "computed ds field should not be required");
        assert!(!auto.optional, "computed-only ds field should not be optional");
        assert!(auto.computed, "computed field should be computed");
    }

    // --- Sensitive data source field ---

    #[test]
    fn datasource_sensitive_field() {
        let toml_str = r#"
[data_source]
name = "akeyless_ds"
description = "DS"

[read]
endpoint = "/get"
schema = "GetDS"

[fields]
secret = { sensitive = true }
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths:
  /get:
    post:
      operationId: get
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetDS'
      responses:
        "200": { description: ok }
components:
  schemas:
    GetDS:
      type: object
      properties:
        secret: { type: string }
"#;
        let api = Spec::parse(api_str).expect("parse");
        let attrs =
            generate_datasource_attributes(&ds, &api, &ProviderDefaults::default()).expect("gen");
        let secret = attrs
            .iter()
            .find(|a| a.tf_name == "secret")
            .expect("secret");
        assert!(secret.sensitive);
    }

    // --- Data source schema rendering ---

    #[test]
    fn datasource_schema_includes_description() {
        let (ds, api, defaults) = make_ds_test_data();
        let result = generate_datasource(
            &ds,
            &api,
            &defaults,
            "github.com/test/sdk",
        )
        .expect("gen");
        assert!(result.go_code.contains("Description: \"Read an auth method\""));
    }

    // --- Data source without name field: no id setup ---

    #[test]
    fn datasource_no_name_field_still_generates() {
        let toml_str = r#"
[data_source]
name = "akeyless_no_name"
description = "No name field"

[read]
endpoint = "/get-thing"
schema = "GetThing"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths:
  /get-thing:
    post:
      operationId: getThing
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetThing'
      responses:
        "200": { description: ok }
components:
  schemas:
    GetThing:
      type: object
      properties:
        count: { type: integer }
        enabled: { type: boolean }
"#;
        let api = Spec::parse(api_str).expect("parse");
        let result = generate_datasource(
            &ds,
            &api,
            &ProviderDefaults::default(),
            "github.com/test/sdk",
        )
        .expect("gen");
        assert!(result.go_code.contains("NoNameDataSource"));
        assert!(!result.go_code.contains("body.SetName"), "No name field means no id setup");
    }

    // --- Data source without akeyless_ prefix ---

    #[test]
    fn datasource_no_prefix() {
        let toml_str = r#"
[data_source]
name = "custom_data"
description = "Custom"

[read]
endpoint = "/get-auth-method"
schema = "GetAuthMethod"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let (_, api, defaults) = make_ds_test_data();
        let result = generate_datasource(&ds, &api, &defaults, "github.com/test/sdk")
            .expect("gen");
        assert!(result.go_code.contains("CustomDataDataSource"));
        assert_eq!(result.file_name, "datasource_custom_data.go");
    }

    // --- Global skip in data source ---

    #[test]
    fn datasource_global_skip_fields() {
        let (ds, api, _) = make_ds_test_data();
        let defaults = ProviderDefaults {
            skip_fields: vec!["access_id".to_string()],
        };
        let attrs = generate_datasource_attributes(&ds, &api, &defaults).expect("gen");
        assert!(
            attrs.iter().all(|a| a.tf_name != "access_id"),
            "access_id should be skipped via global defaults"
        );
    }

    // --- Data source schema attribute rendering: sensitive ---

    #[test]
    fn datasource_schema_sensitive_attribute() {
        let toml_str = r#"
[data_source]
name = "akeyless_sens"
description = "Sensitive test"

[read]
endpoint = "/get-auth-method"
schema = "GetAuthMethod"

[fields]
access_id = { sensitive = true }
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let (_, api, defaults) = make_ds_test_data();
        let result = generate_datasource(&ds, &api, &defaults, "github.com/test/sdk")
            .expect("gen");
        assert!(result.go_code.contains("Sensitive: true"));
    }

    // --- Data source type_override ---

    #[test]
    fn datasource_type_override() {
        let toml_str = r#"
[data_source]
name = "akeyless_override"
description = "Override"

[read]
endpoint = "/get-auth-method"
schema = "GetAuthMethod"

[fields]
access_id = { type_override = "bool" }
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let (_, api, defaults) = make_ds_test_data();
        let attrs = generate_datasource_attributes(&ds, &api, &defaults).expect("gen");
        let access = attrs
            .iter()
            .find(|a| a.tf_name == "access_id")
            .expect("access_id");
        assert_eq!(access.go_type, "bool");
    }

    // --- Data source Read with first optional string field as ID ---

    #[test]
    fn datasource_read_uses_first_optional_string_when_no_name() {
        let toml_str = r#"
[data_source]
name = "akeyless_alt_id"
description = "Alt ID"

[read]
endpoint = "/get-alt"
schema = "GetAlt"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths:
  /get-alt:
    post:
      operationId: getAlt
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GetAlt'
      responses:
        "200": { description: ok }
components:
  schemas:
    GetAlt:
      type: object
      properties:
        path: { type: string, description: "Path" }
        count: { type: integer }
"#;
        let api = Spec::parse(api_str).expect("parse");
        let result = generate_datasource(
            &ds,
            &api,
            &ProviderDefaults::default(),
            "github.com/test/sdk",
        )
        .expect("gen");
        assert!(
            result.go_code.contains("body.SetPath"),
            "Should use first optional string field 'path' as id"
        );
    }

    // --- Error paths ---

    #[test]
    fn generate_datasource_attributes_missing_schema_errors() {
        let toml_str = r#"
[data_source]
name = "test_ds"
description = "Test"

[read]
endpoint = "/get"
schema = "NonExistentSchema"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths: {}
components:
  schemas: {}
"#;
        let api = Spec::parse(api_str).expect("parse");
        let result = generate_datasource_attributes(&ds, &api, &ProviderDefaults::default());
        assert!(result.is_err(), "Missing schema should error");
    }

    #[test]
    fn generate_datasource_missing_schema_errors() {
        let toml_str = r#"
[data_source]
name = "test_ds"
description = "Test"

[read]
endpoint = "/get"
schema = "NonExistentSchema"
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let api_str = r#"
openapi: "3.0.0"
info: { title: T, version: "1" }
paths: {}
components:
  schemas: {}
"#;
        let api = Spec::parse(api_str).expect("parse");
        let result = generate_datasource(&ds, &api, &ProviderDefaults::default(), "sdk");
        assert!(result.is_err(), "Missing schema should error");
    }

    // --- Data source description override ---

    #[test]
    fn datasource_field_description_override() {
        let toml_str = r#"
[data_source]
name = "akeyless_ds"
description = "DS"

[read]
endpoint = "/get-auth-method"
schema = "GetAuthMethod"

[fields]
name = { description = "Custom name desc" }
"#;
        let ds: DataSourceSpec = toml::from_str(toml_str).expect("parse");
        let (_, api, defaults) = make_ds_test_data();
        let attrs = generate_datasource_attributes(&ds, &api, &defaults).expect("gen");
        let name_attr = attrs.iter().find(|a| a.tf_name == "name").expect("name");
        assert_eq!(name_attr.description, "Custom name desc");
    }
}