I am trying to register an application in Azure AD using TF and i would like to define some redirect URIs using the arg as mentioned in the link --> https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application :
reply_urls = ["https://replyurl"]
But i have to put 3 URIs and the format of the URI is like this below :
https://(project code)-yellow-(resourcegroup).azurewebsites.net/oauth2-redirect.html
https://(project code)-blue-(resourcegroup).azurewebsites.net/oauth2-redirect.html
https://(project code)-green-(resourcegroup).azurewebsites.net/oauth2-redirect.html
So the second part is changing only and the other part is constant. We cannot hardcode URIs for best practices
Also, we need to use format function
So can anyone tell how to put the reply_urls using the format function so that only the middle part changes as described above
Also, can this be done in any way using concat for that matter
You can pass the project_id and resourcegroup as input parameters to your TF code:
variable "project_id" {}
variable "resource_group" {}
Then your reply_urls could be:
reply_urls = [
format("https://%s-yellow-%s.azurewebsites.net/oauth2-redirect.html", var.project_id, var.resource_group),
format("https://%s-blue-%s.azurewebsites.net/oauth2-redirect.html", var.project_id, var.resource_group),
format("https://%s-green-%s.azurewebsites.net/oauth2-redirect.html", var.project_id, var.resource_group)
]
Related
I have a shell script to download a http link using wget:
wget -qO - "${mojang_server_url}"
I want to enter this link in a tfvars file, and then reference this in the shell script using Terraform.
I found a good solution here using template_file data source (it works)
data "template_file" "setup_script" {
template = file("setup.sh")
vars = {
mojang_server_url = "${var.mojang_server_url}"
}
}
However, the official Terraform documentation for template_file tells me I should be using the templatefile function instead?
I can't seem to figure out the syntax for this function, here's what I've got:
templatefile("setup.sh",{"mojang_server_url"="${var.mojang_server_url}")
it highlights templatefile, saying:
Argument or block definition required: An argument or block definition
is required here. To set an argument, use the equals sign "=" to
introduce the argument value.
Is there a way to make it so this can reference the tfvars variable ina shell script?
thank you!
You just simply have to provide a map as an input for the second argument:
data "template_file" "setup_script" {
template = templatefile("setup.sh",
{
mojang_server_url = var.mojang_server_url
}
)
}
I'm trying to develop a maco in python. I need a method that changes the URI given in the input variables.
For instance, in www.(variable).com I need to change the URL www.1.com to www.2.com
You can use formatted strings like this:
variable = 1
url = f"www.{variable}.com"
You could store your list of names in a list and then interpolate the variable into the f-string like:
names = ['google', 'amazon', 'microsoft']
for name in names:
print(f"www.{name}.com")
OUTPUT
www.google.com
www.amazon.com
www.microsoft.com
I want to pass a value for parameter usertime, the value should be like 2020-07-23T13:19:31Z , which will be used in my source connection url.
For this i supplied utcnow() function in the value tab. But i realized utcnow() will return the value as "2018-04-15T13:00:00.0000000Z"
To remove the millisecond part i have used the expression substring(utcnow(),1,20).
and also used expression formatDateTime('utcnow()', 'yyyy-MM-ddTHH:mm:ss').
Both my trails are useless where my expression returning error ass invalid parameter.
Could you please help me how can i supply the value 2020-07-23T13:19:31Z in Azure data factory datasource parameters.
You don't want utcNow inside quotes, here is an example from one of my pipelines using your format:
#formatDateTime(utcnow(), 'yyyy-MM-ddTHH:mm:ss')
which gives this result, setting a variable named x:
{
"name": "x",
"value": "2020-07-24T13:44:42Z"
}
Build it in 'Add dynamic content' as you can pick the functions and it will format properly if you aren't familiar.
Your substring won't work because it requires a string for the first parameter and utcnow is a timestamp.
The custom V93K test methods we use have parameter names that have characters that are forbidden in Ruby. For example:
testmethodparameters
tm_1:
"ComponentRule.ComponentRuleNameVariable" = "ComponentRuleMinConfig";
"ComponentRule.ExecuteRules" = "true";
"ComponentRule.RuleGroupNameVariable" = "ComponentRuleGroupName";
"ComponentRule.ScriptNameVariable" = "ComponentRuleScriptName";
"Softset.NumberOfPatternInfo" = "1";
"Softset.PatternInfo0.EdgesPerVector" = "2";
When looking at the Origen V93k docs, I see that Origen will convert a Ruby styled variable to the camel case required by the V93k, but would it handle a variable with an actual period in it? I am storing them using the Origen::Parameters::Set class like so, but to retrieve the correct parameter name, I would have to write some 'parameter name flattener' method.
params.bist.Softset.PatternInfo0.EdgesPerVector = "2"
params.bist.Softset.PatternInfo0.FuseProgramming = "false"
Before I write said method, does Origen already have a way to handle this case already that is not part of the docs? If not, would a PR be well received?
thx
It would handle a period in the C++ parameter name, the example here contains a parameter called 'An.UnusualName'.
When you supply the parameter name via a string like this then it is rendered verbatim into the test flow:
tm_1:
"An.UnusualName" = "blah"
To assign a value to this in an interface though then you need to convert the period to an underscore, Origen will create both the fully lower-cased and underscored accessor and also one with only the periods converted to underscores:
t = test_methods.my_lib.my_test
t.an_unusual_name = "blah"
t.An_UnusualName # => "blah"
It would add significant complication to generate filler objects on the fly to support t.An.UnusualName = "blah" and I don't think it is worth it - the existing API is fine for humans.
I can see that supporting the name with the period might be preferable for scripting though.
An easier approach that would provide what is needed would be to add a set_param method or similar to this class:
t.set_param("An.UnusualName", "blah")
I am having trouble in variable interpolation in terraform. Here is what my terraform configuration looks like. i.e variable inside builtin function
variable "key" {}
ssh_keys {
path = "/home/${var.provider["user"]}/.ssh/authorized_keys"
key_data = "${file(${var.key})}"
}
Command: terraform apply -var 'key=~/.ssh/id_rsa.pub'
It's not reading the value of "key" from command line argument or from env variable. However when i hardcore the value in .tf file, it works. Like below.
key_data = "${file("~/.ssh/id_rsa.pub")}"
The ${ ... } syntax is only used when embedding an expression into a quoted string. In this case, where your var.key variable is just being passed as an argument to a function already within a ${ ... } sequence, you can just reference the variable name directly like this:
key_data = "${file(var.key)}"
Nested ${ ... } sequences are sometimes used to pass an interpolated string to a function. In that case there would first be a nested set of quotes to return to string context. For example:
key_data = "${file("${path.module}/${var.key_filename}")}"
In this more complicated case, the innermost string expression is first evaluated to join together the two variables with a /, then that whole string is passed to the file function, with the result finally returned as the value of key_data.
It doesn't work because you were using the wrong flag for the scenario you described above.
If you want to specify a path to a file use the "-var-file" flag as follow:
terraform apply -var-file=~/.ssh/id_rsa.pub
If you must use the "-var" flag then you must specify the content of the file as follow:
terraform apply -var 'key=contenctOFPublicKey'
ssh_keys - (Optional) Specifies a collection of path and key_data to be placed on the virtual machine.
Note: Please note that the only allowed path is /home/<username>/.ssh/authorized_keys due to a limitation of Azure.
refer: AZURERM_VIRTUAL_MACHINE