RangeKey
I'm doing Pulumi IaC. I don't like
RangeKey = _rangeKey != null ? (Input<string>?)_rangeKey : null
. looks kinda ugly. Is there a better way?
public sealed class DynamoDbTableBuilder
{
private string? _name;
private string? _hashKey;
private string? _rangeKey;
private readonly List<TableAttributeArgs> _tableAttributes = new();
public DynamoDbTableBuilder WithName(string name)
{
_name = name;
return this;
}
public DynamoDbTableBuilder WithTableAttribute(string name, string type)
{
_tableAttributes.Add(new TableAttributeArgs
{
Name = name,
Type = type
});
return this;
}
public DynamoDbTableBuilder WithHashKey(string hashKey)
{
_hashKey = hashKey;
return this;
}
public DynamoDbTableBuilder WithRangeKey(string rangeKey)
{
_rangeKey = rangeKey;
return this;
}
public Table Build()
{
if (string.IsNullOrEmpty(_name))
{
throw new InvalidOperationException("Table name is not set");
}
if (string.IsNullOrEmpty(_hashKey))
{
throw new InvalidOperationException("Hash key is not set");
}
return new Table(_name, new TableArgs
{
Attributes = _tableAttributes,
BillingMode = "PAY_PER_REQUEST",
TableClass = "STANDARD",
StreamEnabled = false,
HashKey = _hashKey,
RangeKey = _rangeKey != null ? (Input<string>?)_rangeKey : null
});
}
}
public sealed class DynamoDbTableBuilder
{
private string? _name;
private string? _hashKey;
private string? _rangeKey;
private readonly List<TableAttributeArgs> _tableAttributes = new();
public DynamoDbTableBuilder WithName(string name)
{
_name = name;
return this;
}
public DynamoDbTableBuilder WithTableAttribute(string name, string type)
{
_tableAttributes.Add(new TableAttributeArgs
{
Name = name,
Type = type
});
return this;
}
public DynamoDbTableBuilder WithHashKey(string hashKey)
{
_hashKey = hashKey;
return this;
}
public DynamoDbTableBuilder WithRangeKey(string rangeKey)
{
_rangeKey = rangeKey;
return this;
}
public Table Build()
{
if (string.IsNullOrEmpty(_name))
{
throw new InvalidOperationException("Table name is not set");
}
if (string.IsNullOrEmpty(_hashKey))
{
throw new InvalidOperationException("Hash key is not set");
}
return new Table(_name, new TableArgs
{
Attributes = _tableAttributes,
BillingMode = "PAY_PER_REQUEST",
TableClass = "STANDARD",
StreamEnabled = false,
HashKey = _hashKey,
RangeKey = _rangeKey != null ? (Input<string>?)_rangeKey : null
});
}
}
2 Replies
_rangeKey as Input<string>?
?@Ero, thanks. I solved the problem. https://www.pulumi.com/docs/intro/concepts/inputs-outputs/