Skip to content

Commit

Permalink
Merge pull request #1471 from jsteinich/number_array_token
Browse files Browse the repository at this point in the history
feat(lib): number[] Tokens
  • Loading branch information
DanielMSchmidt committed Jan 13, 2022
2 parents 4f2f6c1 + e3e76d2 commit 1d8ae19
Show file tree
Hide file tree
Showing 32 changed files with 3,851 additions and 3,068 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,19 @@
## Unreleased

**Breaking Changes**

### Number[] Tokens [#1471](https://github.com/hashicorp/terraform-cdk/pull/1471)

As part of an effort to use more native types, there are now tokens for `number[]`.
This is mostly an internal change, but there is now `Token.asNumberList()` which can be used to convert other values into `number[]`.

As a result of some standardization, there is a minor breaking change:

- Boolean[] attributes have gone from `boolean[]` to `Array<boolean | IResolvable> | IResolvable`.
- This is done because neither `boolean` or `boolean[]` is representable by a token.
- This should make it easier to pass around `boolean[]` between resources and fuctions.
- For jsii languages (especially Java and C#), these types will end up as `List<Object>`.

## 0.8.6

### fix
Expand Down
Expand Up @@ -1215,6 +1215,18 @@ export interface OptionalAttributeResourceConfig extends cdktf.TerraformMetaArgu
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_attribute_resource#bool OptionalAttributeResource#bool}
*/
readonly bool?: boolean | cdktf.IResolvable;
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_attribute_resource#strList OptionalAttributeResource#strList}
*/
readonly strList?: string[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_attribute_resource#numList OptionalAttributeResource#numList}
*/
readonly numList?: number[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_attribute_resource#boolList OptionalAttributeResource#boolList}
*/
readonly boolList?: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
}
/**
Expand Down Expand Up @@ -1252,6 +1264,9 @@ export class OptionalAttributeResource extends cdktf.TerraformResource {
this._str = config.str;
this._num = config.num;
this._bool = config.bool;
this._strList = config.strList;
this._numList = config.numList;
this._boolList = config.boolList;
}
// ==========
Expand Down Expand Up @@ -1306,6 +1321,54 @@ export class OptionalAttributeResource extends cdktf.TerraformResource {
return this._bool;
}
// strList - computed: false, optional: true, required: false
private _strList?: string[];
public get strList() {
return this.getListAttribute('strList');
}
public set strList(value: string[]) {
this._strList = value;
}
public resetStrList() {
this._strList = undefined;
}
// Temporarily expose input value. Use with caution.
public get strListInput() {
return this._strList;
}
// numList - computed: false, optional: true, required: false
private _numList?: number[];
public get numList() {
return this.getNumberListAttribute('numList');
}
public set numList(value: number[]) {
this._numList = value;
}
public resetNumList() {
this._numList = undefined;
}
// Temporarily expose input value. Use with caution.
public get numListInput() {
return this._numList;
}
// boolList - computed: false, optional: true, required: false
private _boolList?: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
public get boolList() {
return this.getBooleanAttribute('boolList') as any;
}
public set boolList(value: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable) {
this._boolList = value;
}
public resetBoolList() {
this._boolList = undefined;
}
// Temporarily expose input value. Use with caution.
public get boolListInput() {
return this._boolList;
}
// =========
// SYNTHESIS
// =========
Expand All @@ -1315,6 +1378,9 @@ export class OptionalAttributeResource extends cdktf.TerraformResource {
str: cdktf.stringToTerraform(this._str),
num: cdktf.numberToTerraform(this._num),
bool: cdktf.booleanToTerraform(this._bool),
strList: cdktf.listMapper(cdktf.stringToTerraform)(this._strList),
numList: cdktf.listMapper(cdktf.numberToTerraform)(this._numList),
boolList: cdktf.listMapper(cdktf.booleanToTerraform)(this._boolList),
};
}
}
Expand Down Expand Up @@ -1343,6 +1409,18 @@ export interface OptionalComputedAttributeResourceConfig extends cdktf.Terraform
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_computed_attribute_resource#bool OptionalComputedAttributeResource#bool}
*/
readonly bool?: boolean | cdktf.IResolvable;
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_computed_attribute_resource#strList OptionalComputedAttributeResource#strList}
*/
readonly strList?: string[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_computed_attribute_resource#numList OptionalComputedAttributeResource#numList}
*/
readonly numList?: number[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/optional_computed_attribute_resource#boolList OptionalComputedAttributeResource#boolList}
*/
readonly boolList?: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
}
/**
Expand Down Expand Up @@ -1380,6 +1458,9 @@ export class OptionalComputedAttributeResource extends cdktf.TerraformResource {
this._str = config.str;
this._num = config.num;
this._bool = config.bool;
this._strList = config.strList;
this._numList = config.numList;
this._boolList = config.boolList;
}
// ==========
Expand Down Expand Up @@ -1434,6 +1515,54 @@ export class OptionalComputedAttributeResource extends cdktf.TerraformResource {
return this._bool;
}
// strList - computed: true, optional: true, required: false
private _strList?: string[];
public get strList() {
return this.getListAttribute('strList');
}
public set strList(value: string[]) {
this._strList = value;
}
public resetStrList() {
this._strList = undefined;
}
// Temporarily expose input value. Use with caution.
public get strListInput() {
return this._strList;
}
// numList - computed: true, optional: true, required: false
private _numList?: number[];
public get numList() {
return this.getNumberListAttribute('numList');
}
public set numList(value: number[]) {
this._numList = value;
}
public resetNumList() {
this._numList = undefined;
}
// Temporarily expose input value. Use with caution.
public get numListInput() {
return this._numList;
}
// boolList - computed: true, optional: true, required: false
private _boolList?: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
public get boolList() {
return this.getBooleanAttribute('boolList') as any;
}
public set boolList(value: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable) {
this._boolList = value;
}
public resetBoolList() {
this._boolList = undefined;
}
// Temporarily expose input value. Use with caution.
public get boolListInput() {
return this._boolList;
}
// =========
// SYNTHESIS
// =========
Expand All @@ -1443,6 +1572,9 @@ export class OptionalComputedAttributeResource extends cdktf.TerraformResource {
str: cdktf.stringToTerraform(this._str),
num: cdktf.numberToTerraform(this._num),
bool: cdktf.booleanToTerraform(this._bool),
strList: cdktf.listMapper(cdktf.stringToTerraform)(this._strList),
numList: cdktf.listMapper(cdktf.numberToTerraform)(this._numList),
boolList: cdktf.listMapper(cdktf.booleanToTerraform)(this._boolList),
};
}
}
Expand Down Expand Up @@ -1471,6 +1603,18 @@ export interface RequiredAttributeResourceConfig extends cdktf.TerraformMetaArgu
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/required_attribute_resource#bool RequiredAttributeResource#bool}
*/
readonly bool: boolean | cdktf.IResolvable;
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/required_attribute_resource#strList RequiredAttributeResource#strList}
*/
readonly strList: string[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/required_attribute_resource#numList RequiredAttributeResource#numList}
*/
readonly numList: number[];
/**
* Docs at Terraform Registry: {@link https://www.terraform.io/docs/providers/edge/r/required_attribute_resource#boolList RequiredAttributeResource#boolList}
*/
readonly boolList: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
}
/**
Expand Down Expand Up @@ -1508,6 +1652,9 @@ export class RequiredAttributeResource extends cdktf.TerraformResource {
this._str = config.str;
this._num = config.num;
this._bool = config.bool;
this._strList = config.strList;
this._numList = config.numList;
this._boolList = config.boolList;
}
// ==========
Expand Down Expand Up @@ -1553,6 +1700,45 @@ export class RequiredAttributeResource extends cdktf.TerraformResource {
return this._bool;
}
// strList - computed: false, optional: false, required: true
private _strList?: string[];
public get strList() {
return this.getListAttribute('strList');
}
public set strList(value: string[]) {
this._strList = value;
}
// Temporarily expose input value. Use with caution.
public get strListInput() {
return this._strList;
}
// numList - computed: false, optional: false, required: true
private _numList?: number[];
public get numList() {
return this.getNumberListAttribute('numList');
}
public set numList(value: number[]) {
this._numList = value;
}
// Temporarily expose input value. Use with caution.
public get numListInput() {
return this._numList;
}
// boolList - computed: false, optional: false, required: true
private _boolList?: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable;
public get boolList() {
return this.getBooleanAttribute('boolList') as any;
}
public set boolList(value: Array<boolean | cdktf.IResolvable> | cdktf.IResolvable) {
this._boolList = value;
}
// Temporarily expose input value. Use with caution.
public get boolListInput() {
return this._boolList;
}
// =========
// SYNTHESIS
// =========
Expand All @@ -1562,6 +1748,9 @@ export class RequiredAttributeResource extends cdktf.TerraformResource {
str: cdktf.stringToTerraform(this._str),
num: cdktf.numberToTerraform(this._num),
bool: cdktf.booleanToTerraform(this._bool),
strList: cdktf.listMapper(cdktf.stringToTerraform)(this._strList),
numList: cdktf.listMapper(cdktf.numberToTerraform)(this._numList),
boolList: cdktf.listMapper(cdktf.booleanToTerraform)(this._boolList),
};
}
}
Expand Down
Expand Up @@ -149,4 +149,35 @@ export class SchemaBuilder {
});
return this;
}

public addAllPrimitiveListTypes({
required,
computed,
prefix = "",
}: {
required: boolean;
computed: boolean;
prefix?: string;
}): SchemaBuilder {
this.attribute({
name: prefix + "strList",
type: ["list", "string"],
required,
computed,
})
.attribute({
name: prefix + "numList",
type: ["list", "number"],
required,
computed,
})
.attribute({
name: prefix + "boolList",
type: ["list", "bool"],
required,
computed,
});

return this;
}
}
Expand Up @@ -3,14 +3,17 @@ import { schema, SchemaBuilder as S } from "./builder";

const required_attribute_resource = new S()
.addAllPrimitiveTypes({ required: true, computed: false })
.addAllPrimitiveListTypes({ required: true, computed: false })
.build();

const optional_attribute_resource = new S()
.addAllPrimitiveTypes({ required: false, computed: false })
.addAllPrimitiveListTypes({ required: false, computed: false })
.build();

const optional_computed_attribute_resource = new S()
.addAllPrimitiveTypes({ required: false, computed: true })
.addAllPrimitiveListTypes({ required: false, computed: true })
.build();

const list_block_resource = new S()
Expand Down

0 comments on commit 1d8ae19

Please sign in to comment.