Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,97 @@ export class ListOfStringMap extends cdktn.TerraformResource {
"
`;

exports[`map of map of string attribute 1`] = `
"// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_map_of_string
// generated from terraform resource schema

import { Construct } from 'constructs';
import * as cdktn from 'cdktn';

// Configuration

export interface MapOfMapOfStringConfig extends cdktn.TerraformMetaArguments {
}

/**
* Represents a {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_map_of_string aws_map_of_map_of_string}
*/
export class MapOfMapOfString extends cdktn.TerraformResource {

// =================
// STATIC PROPERTIES
// =================
public static readonly tfResourceType = "aws_map_of_map_of_string";

// ==============
// STATIC Methods
// ==============
/**
* Generates CDKTN code for importing a MapOfMapOfString resource upon running "cdktn plan <stack-name>"
* @param scope The scope in which to define this construct
* @param importToId The construct id used in the generated config for the MapOfMapOfString to import
* @param importFromId The id of the existing MapOfMapOfString that should be imported. Refer to the {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_map_of_string#import import section} in the documentation of this resource for the id to use
* @param provider? Optional instance of the provider where the MapOfMapOfString to import is found
*/
public static generateConfigForImport(scope: Construct, importToId: string, importFromId: string, provider?: cdktn.TerraformProvider) {
return new cdktn.ImportableResource(scope, importToId, { terraformResourceType: "aws_map_of_map_of_string", importId: importFromId, provider });
}

// ===========
// INITIALIZER
// ===========

/**
* Create a new {@link https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_map_of_string aws_map_of_map_of_string} Resource
*
* @param scope The scope in which to define this construct
* @param id The scoped construct ID. Must be unique amongst siblings in the same scope
* @param options MapOfMapOfStringConfig = {}
*/
public constructor(scope: Construct, id: string, config: MapOfMapOfStringConfig = {}) {
super(scope, id, {
terraformResourceType: 'aws_map_of_map_of_string',
terraformGeneratorMetadata: {
providerName: 'aws'
},
provider: config.provider,
dependsOn: config.dependsOn,
count: config.count,
lifecycle: config.lifecycle,
provisioners: config.provisioners,
connection: config.connection,
forEach: config.forEach
});
}

// ==========
// ATTRIBUTES
// ==========

// labels - computed: true, optional: false, required: false
private _labels = new cdktn.StringMapMap(this, "labels");
public get labels() {
return this._labels;
}

// =========
// SYNTHESIS
// =========

protected synthesizeAttributes(): { [name: string]: any } {
return {
};
}

protected synthesizeHclAttributes(): { [name: string]: any } {
const attrs = {
};
return attrs;
}
}
"
`;

exports[`map of string list attribute 1`] = `
"// https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/map_of_string_list
// generated from terraform resource schema
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"provider_schemas": {
"registry.terraform.io/hashicorp/aws": {
"resource_schemas": {
"aws_map_of_map_of_string": {
"version": 1,
"block": {
"attributes": {
"labels": {
"type": [
"map",
[
"map",
"string"
]
],
"description": "Map of map of string.",
"computed": true
}
}
},
"block_types": {}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -571,3 +571,28 @@ test("list of list of strings", async () => {
);
expect(datasourceOutput).toMatchSnapshot();
});

test("map of map of string attribute", async () => {
const code = new CodeMaker();
const workdir = fs.mkdtempSync(
path.join(os.tmpdir(), "map-of-map-of-string.test"),
);
const spec = JSON.parse(
fs.readFileSync(
path.join(
__dirname,
"fixtures",
"map-of-map-of-string.test.fixture.json",
),
"utf-8",
),
);
new TerraformProviderGenerator(code, spec).generateAll();
await code.save(workdir);

const output = fs.readFileSync(
path.join(workdir, "providers/aws/map-of-map-of-string/index.ts"),
"utf-8",
);
expect(output).toMatchSnapshot();
});
26 changes: 26 additions & 0 deletions packages/cdktn/lib/complex-computed-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ export class AnyMap extends ComplexResolvable implements ITerraformAddressable {
}
}

// eslint-disable-next-line jsdoc/require-jsdoc
export class StringMapMap
extends ComplexResolvable
implements ITerraformAddressable
{
constructor(
protected terraformResource: IInterpolatingParent,
protected terraformAttribute: string,
) {
super(terraformResource, terraformAttribute);
}

public lookup(key: string): StringMap {
return new StringMap(
this.terraformResource,
`${this.terraformAttribute}["${key}"]`,
);
}

computeFqn(): string {
return Token.asString(
this.terraformResource.interpolationForAttribute(this.terraformAttribute),
);
}
}

/**
* @deprecated Going to be replaced by Array of ComplexListItem
* and will be removed in the future
Expand Down
64 changes: 64 additions & 0 deletions packages/cdktn/test/__snapshots__/data-source.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,67 @@ exports[`with string map 1`] = `
}
}"
`;

exports[`with string map map - lookup returns StringMap reference 1`] = `
"{
"data": {
"test_data_source": {
"test": {
"name": "foo"
}
}
},
"provider": {
"test": [
{
}
]
},
"resource": {
"test_resource": {
"test-resource": {
"name": "\${data.test_data_source.test.string_map_map[\\"outer_key\\"]}"
}
}
},
"terraform": {
"required_providers": {
"test": {
"version": "~> 2.0"
}
}
}
}"
`;

exports[`with string map map - nested lookup produces correct reference 1`] = `
"{
"data": {
"test_data_source": {
"test": {
"name": "foo"
}
}
},
"provider": {
"test": [
{
}
]
},
"resource": {
"test_resource": {
"test-resource": {
"name": "\${data.test_data_source.test.string_map_map[\\"outer_key\\"][\\"inner_key\\"]}"
}
}
},
"terraform": {
"required_providers": {
"test": {
"version": "~> 2.0"
}
}
}
}"
`;
30 changes: 30 additions & 0 deletions packages/cdktn/test/data-source.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,36 @@ test("with any map", () => {
).toMatchSnapshot();
});

test("with string map map - lookup returns StringMap reference", () => {
expect(
Testing.synthScope((stack) => {
new TestProvider(stack, "provider", {});

const dataSource = new TestDataSource(stack, "test", {
name: "foo",
});
new TestResource(stack, "test-resource", {
name: Token.asString(dataSource.stringMapMap.lookup("outer_key")),
});
}),
).toMatchSnapshot();
});

test("with string map map - nested lookup produces correct reference", () => {
expect(
Testing.synthScope((stack) => {
new TestProvider(stack, "provider", {});

const dataSource = new TestDataSource(stack, "test", {
name: "foo",
});
new TestResource(stack, "test-resource", {
name: dataSource.stringMapMap.lookup("outer_key").lookup("inner_key"),
});
}),
).toMatchSnapshot();
});

test("dependent data source", () => {
expect(
Testing.synthScope((stack) => {
Expand Down
5 changes: 5 additions & 0 deletions packages/cdktn/test/helper/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TerraformDataSource,
TerraformMetaArguments,
StringMap,
StringMapMap,
NumberMap,
BooleanMap,
AnyMap,
Expand Down Expand Up @@ -62,6 +63,10 @@ export class TestDataSource extends TerraformDataSource {
return new AnyMap(this, "any_map").lookup(key);
}

public get stringMapMap() {
return new StringMapMap(this, "string_map_map");
}

public get listValue() {
return this.getListAttribute("list_value");
}
Expand Down
Loading