Dynamically Creating Resource Name from Values - aws-cloudformation

My end goal is to create a policy document from a cloudformation script. I want to have one script where the parameter is selected and that value is used to in the name of the resource.
"arn:aws:dynamodb:us-east-1:12345678:table/monit-${dev}/stream/*"
where ${dev} is a parameter value
Parameters:
Environment:
Default: dev
Description: Leveraged for environment tagging.
Type: String
AllowedValues:
- dev
- tst
- qa
- stg
- prd
I want to try something like the following but don't know how to add the Ref Environment from the parameter or is there some other method?
'Fn::Sub': 'arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}'
So I don't end up have to create a bunch of different scripts
PolicyDocument:
Statement:
- Effect: Allow
Action:
- dynamodb:DescribeStream
- dynamodb:GetRecords
- dynamodb:GetShardIterator
- dynamodb:ListStreams
- dynamodb:Scan
#This will need to changed for other tables
Resource:
- "arn:aws:dynamodb:us-east-1:12345678:table/monit-dev/stream/*"
- "arn:aws:dynamodb:us-east-1:12345678:table/monit-dev"

If i understood you correctly, You can use Fn::Join to add the "Environment" value. You dont use Ref of the value it self.
The intrinsic function Ref returns the value of the specified parameter or resource.
When you specify a parameter's logical name, it returns the value of the parameter.
When you specify a resource's logical name, it returns a value that you can typically use to refer to that resource, such as a physical ID.
json example:
"CustomInstanceProfileArn": {
"Fn::Join": [
"", ["arn:aws:iam::", {
"Ref": "AWS::AccountId"
},
":instance-profile/", {
"Ref": "InstanceProfile"
}
]
]
},
http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

Related

How to specify an unknown number of a parameter in the response Open API

I'm trying to model my API using swagger and the Open API 3.0 specification. I have made some schemas and now I'm modeling the response of my endpoints. The problem is that they return something like this:
[
{
"name": "this attribute is always here"
"type1": { "description": "this maybe appear or not" },
"type2": { "description": "this maybe appear or not" },
...
"typeN": { "description": "N is not a fixed number, it may range from 0 to another positive integer" },
}
]
I know how to model the array and the object (with the name property). The problem comes when I have to model the typeX properties, I do not know how to specify that they are optional and the number of ocurrences is variable. Any idea?
This object is basically a string-to-object dictionary/hashmap with an extra name property. Fixed properties are defined in properties, and the dictionary part can be defined using either patternProperties (in OpenAPI 3.1) or additionalProperties (in OpenAPI 3.0 and 2.0).
OpenAPI 3.1
In OAS 3.1 your object can be defined as follows. Since the optional property names all follow the typeX format, the schema uses patternProperties to define the regex for the property names.
MyObject:
type: object
required: [name]
properties:
name:
type: string
patternProperties: # <-- This part defines the "typeX" properties
^type\d+$: # <-- Property name regex
type: object # <-- Property value
properties:
description:
type: string
additionalProperties: false # No other properties other than "name" and "typeX"
OpenAPI 3.0 and 2.0
In earlier OAS versions, you use additionalProperties to define "may have extra properties with <such> values", but there's no way to define the format of those property names. You can however mention the property name format in the schema description and also add a schema example for documentation purposes.
MyObject:
type: object
description: >-
In addition to the `name` property, this object may have an arbitrary
number of properties named `typeX` where X is a positive integer.
required: [name]
properties:
name:
type: string
additionalProperties:
# This part defines the *value* of the typeX properties
type: object
properties:
description:
type: string
# Optional schema example
name: something
type1:
description: ....
type2:
description: ....

OpenAPI parameter description vs parameter schema description

In OpenAPI 3.0, I'm wondering what the difference is when describing parameters. For example, what is the difference between descriptions "Foo" and "Bar" below? Is the one for "Foo" more for the semantics of the parameter and the one for "Bar" more for the syntax, if that makes sense? Should just one be used generally (and which if so)?
{
"name": "someParameter",
"in": "query",
"description": "Foo",
"schema": {
"type": "string",
"description": "Bar"
}
}
The parameter description is specified by the description in the parameter itself.
It just so happens that parameters use a schema to define the data type, and schemas can have their own description. In the context of parameters, you can think of the schema-level description as the description of the parameter's data type.
The two descriptions are semantically separate. Schema-level decription is NOT a fallback for missing parameter description.
Here's another example:
paths:
/users/{id}:
delete:
summary: Delete a user
parameters:
- in: path
name: id
required: true
description: The ID of the user you want to delete.
schema:
type: string
format: uuid
description: >-
A unique identifier in the format "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".
In practice, parameters usually don't have a schema-level description specified because it's often redundant.

how to add arrays as azure devops variable groups variable value?

I have used azure devops variable group variables to define my appsettings properties. However, I could not use an array as a value for one of my appsettings properties.
Here is a screenshot of what i am trying to do:
But it appears on the appsettings.json as follows which results in a 500 internal server error Value cannot be null. Parameter name: collection
"AzureAd": {
"Instance": "https://login.microsoftonline.com",
"ClientId": "",
"TenantId": "",
"Audience": "[ https://api.doesnotexist.com ]"
}
The code in Startup.cs that is failing is as follows:
services.AddAuthentication(o =>
{
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(o =>
{
o.Authority = $"{azureADSettings.Instance}/{azureADSettings.TenantId}/";
o.TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
ValidAudiences = new List<string>(azureADSettings.Audience),
};
});
Please Refer to this doc:
All variables are stored as strings and are mutable. The value of a variable can change from run to run or job to job of your pipeline.
In Azure Devops, Variables are String type by default. And we couldn'change it.
So when you define an array in variable, it will pass the array as a string to your appsettings.json file.
To solve this issue, you need to change to use Parameters. The parameter supports the value of the input array type.
Here is an example:
parameters:
- name: 'param'
type: object
default: [123,234,456]
steps:
- ${{ each p in parameters.param }}:
- script: echo ${{ p }}
Note: Parameters can only be used in YAML pipeline.
You can also set collection using the variables as explained in the microsoft documentation
By adding the index of the element in the variable name
example

add a pipeline variable of array type In ADO pipeline

Is it possible to add a pipeline variable of array type in ADO pipeline? I’m trying to add a pipeline variable of array type with these values:
[
{ name: abc, id: 123 },
{ name: def, id: 456 }
]
Pipeline variable doesnot support complex type, all variables are stored as strings. You can try below workarounds depending on how you use the variable in your pipeline.
1, If you want to reference the variable in other task. You can define the variable as runtime parameters instead of pipeline variables. You can define the parameter like below:
parameters:
- name: Ids
type: object
default:
- name: abc
value: 123
- name: efg
value: 456
Then you can refer to the parameter using syntax like this :${{parameters.Ids[0].name}}
steps:
- powershell: |
echo "${{parameters.Ids[0].name}}"
echo "${{parameters.Ids[0].value}}"
2, If you use the variable in a script task. You can save the value to json string. And convert to json object in the script. See below example:
First, Save the value to json string('[{"name":"abc", "value":111},{"name":"efg", value:222}]') to the pipeline variable:
Then, Convert to json object in the script task. See below example in powershell task:
steps:
- powershell: |
$ids = $(ids) | convertfrom-json
echo $ids[0].name
No pipeline variables are strings. There is no way at the moment to have variable of complex type. Plese check this topic on developer community - Variables in YAML pipeline are not allowing to define array
Yaml variables have always been string: string mappings. Instead of using variable, you may consider Parameters.
parameters:
- name: abc
type: string
default: 123
- name: def
type: string
default: 456
……

How do define custom displayNameGetter in PowerBI?

I'm developing a new visual in PowerBI and first defining visual capabilities.
Even, the samples show me that, for example, gauge.capabilities.ts file like this.
export var gaugeCapabilities: VisualCapabilities = {
dataRoles: [
{
name: gaugeRoleNames.y,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_Value'),
}, {
name: gaugeRoleNames.minValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_MinValue'),
}, {
name: gaugeRoleNames.maxValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_MaxValue'),
}, {
name: gaugeRoleNames.targetValue,
kind: VisualDataRoleKind.Measure,
displayName: data.createDisplayNameGetter('Role_DisplayName_TargetValue'),
}
],
I want to define custom display names like "From", "To". And when I trying to input it as "raw" in the dataRoles like:
dataRoles: [
{
name: gaugeRoleNames.y,
kind: VisualDataRoleKind.Measure,
displayName: 'From',
}, { ...
And it works.
But I think this is out of coding requirements. Is there any way to define custom display name getter like:
displayName: data.createDisplayNameGetter('Role_DisplayName_From')
I tried. But it doesn't work.
Does anyone have same issue and solve this problem?
Defining a function for displayName allows a visual to fetch a localized string.
The data.createDisplayNameGetter function returns a lambda that does a resource string lookup in our PowerBI.resx resources.
The custom visuals don’t currently have a way to do extend our PowerBI.resx. So you can either hard-code (as you’ve done), or you can define your own function that does your own resource lookup.