terraform only name in even numbers - terraform

I've been using terraform for a while but by no means am I experienced with code. I've been using the below block to generate descriptions for my hosts.
resource "vra_deployment" "test_instance" {
count = var.instance_count
catalog_item_name = var.catalog_item_name
description = "${var.hostname_prefix}${format("%02d", count.index+2)}-${replace(lower(var.region), "-","")}"
This will give me a host with a description like host02-region. At the moment I've only used this with the count variable set to 1.
I'd like to make it so that if I set the count variable to 2, it will build 2 hosts with the description only in even numbers, ie host02-region and host04-region.
Would anyone be able to show me how to do this please?

This is just a basic math question. I would change count.index+2 to (count.index + 1) * 2.
(0 + 1) * 2 = 2
(1 + 1) * 2 = 4
(2 + 1) * 2 = 6
(3 + 1) * 2 = 8

Related

Mathematics - Distribute a list of numbers over an interval

My problem is simple.
I am searching a mathematical function to distribute number over an interval.
For example I have this list :
[2; 4; 9; 14]
And in my case I wish
2 -> 1 = f(2)
14 -> 20 = f(14)
4 -> f(4) = ?
9 -> f(9) = ?
This is just an example I am searching for f(x).
Someone would have any idea ?
Thanks for advance ! :)
If you want a linear function, then:
f(x) = lowerFunc + (x - lowerX) * (upperFunc - lowerFunc) / (upperX - lowerX),
where:
lowerFunc: function value at the lower end
upperFunc: function value at the upper end
lowerX: x parameter at the lower end
upperX: x parameter at the upper end.
For your example:
f(x) = 1 + (x - 2) * (20 - 1) / (14 - 2)
= 1 + (x - 2) * 19/12
f(2) = 1
f(4) = 4.1666
f(9) = 12.08333
f(14) = 20

Errors in function, but the function works - why?

I have a function that generates a random filename in the format "greetingXX.gif" where "XX" is a number between 1 and 20. See code below:
1 function getGIF(callback) {
2 let randomGIF;
3 let gifName = "greeting";
4 const GIF_EXTENSION = ".gif";
5 const MAX_GREETING = 20;
6 randomGIF = Math.floor(Math.random() * MAX_GREETING) + 1;
7 if (randomGIF < 10) {
8 gifName += "0" + randomGIF;
9 } else {
10 gifName += randomGIF;
11 }
12 gifName += GIF_EXTENSION;
13 callback(gifName);
14 }
The function works, BUT in WebStorm I get the following warnings:
Unused Variable randomGIF (Line 2)
Unused constant MAX_GREETING (Line 5)
Element MAX_GREETING is not imported (Line 6)
Variable gifName might not have been initialised (Line 8 and Line 10)
Like I say, the function does exactly what it is supposed to do. But why am I getting these warnings? And more specifically, how do I change my code so I don't get them?
I was able to fix this by invalidating caches (File | Invalidate caches, Invalidate and restart). Thanks to lena for this!

Compile error of erfc function

I tried to use erfc but it says argument not optional.
An example is given below
For j = 0 To 150
f = 1
For m = 1 To j
f = f * m
Next
Application.WorksheetFunction.Erf = (Application.WorksheetFunction.Erf) + (-1) ^ j * b ^ (2 * j + 1) / ((2 * j + 1) * f)
Next
Application.WorksheetFunction.ErfC = 1 - 2 / Sqr(3.14) * Application.WorksheetFunction.Erf
MsgBox (Application.WorksheetFunction.ErfC)
xf1 = (wa + 2 * sp) * q / (4 * cl ^ 2 * 3.14 * hf)
xf2 = Exp(b ^ 2) * Application.WorksheetFunction.ErfC
xf3 = 2 * b / Sqr(3.14) - 1
xf = xf1 * (xf2 + xf3)
According to the MSDN documentation at least one parameter needs to be passed to the Erf method:
Name Required/Optional Data Type Description
Arg1 Required Variant Lower_limit - the lower bound for integrating ERF.
Arg2 Optional Variant Upper_limit - the upper bound for integrating ERF.
If omitted, ERF integrates between zero and
lower_limit.
Therefore, calling it with zero parameters (e.g. Application.WorksheetFunction.Erf) will give you an "argument not optional" error.
You also won't be able to set Erf to a value, i.e.
Application.WorksheetFunction.Erf = ...
is invalid.

WorksheetFunction.Countifs 13 Type Mismatch

I am working on a complex Excel VBA application and trying to use Countifs function. The problem is it is giving me a Type mismatch error I am unable to point a finger to. It would be too complex to paste the entire code here but I am pasting what I think are the relevant lines of the code
Public NumSecTypes As Integer
Public NumSecurities As Integer
.
.
.
Dim i as Integer
Dim AvgPoSSizeCountif As Double
Dim SecType As String
.
.
.
Sheets("Output").Select
AvgPoSSizeCountif = WorksheetFunction.CountIfs(Range(Cells(i + 1, (17 + 2 * NumSecTypes)), Cells(i + 1, (16 + 2 * NumSecTypes + NumSecurities))), Range(Cells(6, (17 + 2 * NumSecTypes)), Cells(6, (16 + 2 * NumSecTypes + NumSecurities))), SecType, Range(Cells(i + 1, (21 + 2 * NumSecTypes + 2 * NumSecurities)), Cells(i + 1, (20 + 2 * NumSecTypes + 3 * NumSecurities))), ">0")
Can anyone tell me what is wrong with this? The error is in the "AvgPoSSizeCountif = ..." line
Many thanks in advance. Any help would be appreciated. Kindly let me know if you need any other information
The syntax for the CountIfs function should be
CountIfs( criteria_range1, criteria1, [criteria_range2, criteria2, ...])
It looks like you are missing the criteria that matches Parameter 1. This is what your function looks like below:
WorksheetFunction.CountIfs(
// Parameter 1
Range(Cells(i + 1, (17 + 2 * NumSecTypes)), Cells(i + 1, (16 + 2 * NumSecTypes + NumSecurities))),
// Parameter 2
Range(Cells(6, (17 + 2 * NumSecTypes)), Cells(6, (16 + 2 * NumSecTypes + NumSecurities))),
// Parameter 3
SecType,
// Parameter 4
Range(Cells(i + 1, (21 + 2 * NumSecTypes + 2 * NumSecurities)), Cells(i + 1, (20 + 2 * NumSecTypes + 3 * NumSecurities))),
// Parameter 5
">0"
)

Partition line into equal parts

This is a geometry question.
I have a line between two points A and B and want separate it into k equal parts. I need the coordinates of the points that partition the line between A and B.
Any help is highly appreciated.
Thanks a lot!
You just need a weighted average of A and B.
C(t) = A * (1-t) + B * t
or, in 2-D
Cx = Ax * (1-t) + Bx * t
Cy = Ay * (1-t) + By * t
When t=0, you get A.
When t=1, you get B.
When t=.25, you a point 25% of the way from A to B
etc
So, to divide the line into k equal parts, make a loop and find C, for t=0/k, t=1/k, t=2/k, ... , t=k/k
for(int i=0;i<38;i++)
{
Points[i].x = m_Pos.x * (1 - (i/38.0)) + m_To.x * (i / 38.0);
Points[i].y = m_Pos.y * (1 - (i/38.0)) + m_To.y * (i / 38.0);
if(i == 0 || i == 37 || i == 19) dbg_msg("CLight","(%d)\nPos(%f,%f)\nTo(%f,%f)\nPoint(%f,%f)",i,m_Pos.x,m_Pos.y,m_To.x,m_To.y,Points[i].x,Points[i].y);
}
prints:
[4c7cba40][CLight]: (0)
Pos(3376.000000,1808.000000)
To(3400.851563,1726.714111)
Point(3376.000000,1808.000000)
[4c7cba40][CLight]: (19)
Pos(3376.000000,1808.000000)
To(3400.851563,1726.714111)
Point(3388.425781,1767.357056)
[4c7cba40][CLight]: (37)
Pos(3376.000000,1808.000000)
To(3400.851563,1726.714111)
Point(3400.851563,1726.714111)
which looks fine but then my program doesn't work :D.
but your method works so thanks

Resources