Terraform,字符串计数时出现错误

时间:2019-01-09 03:41:54

标签: terraform

我正在尝试制作Terraform剧本,以通过循环创建Azure路由。

最终目标是用户将用逗号分隔的列表输入目的地。例如:

import tkinter as tk

mylist = ['apple', 'pear', 'kiwi', 'banana', 'strawberry', 'pineapple']

root = tk.Tk()
root.geometry('400x100')

frame = tk.Frame(root)
frame.pack(fill=tk.BOTH, expand=True)

checked_list = []
check_buttons = []  # Added.
fruit_vars = []

def cb_pressed():
    """ Checkbutton callback. """

    # (Re)create [the entire] list of checked fruits.
    checked_list.clear()
    for i, int_var in enumerate(fruit_vars):
       if int_var.get():  # Not zero -> checked.
            checked_list.append(mylist[i])


# Create scrollable Checkbuttons of fruit options.
text = tk.Text(root, cursor="arrow", width=5, height=5)
vsb = tk.Scrollbar(root, command=text.yview)
text.configure(yscrollcommand=vsb.set)
vsb.pack(side=tk.RIGHT, fill=tk.Y)
text.pack(side=tk.LEFT, fill=tk.BOTH, expand=tk.YES)

# Create IntVars and check_buttons list.
for fruit in mylist:
    fruit_vars.append(tk.IntVar())
    cb = tk.Checkbutton(text, text=fruit, variable=fruit_vars[-1],
                        onvalue=1, offvalue=0, command=cb_pressed)
    check_buttons.append(cb)
    text.window_create(tk.END, window=cb)
    text.insert(tk.END, "\n")


def label_fruits():
    """ Display the fruits user has checked. """

    global list_frame

    print(checked_list)

    try:
        list_frame.destroy()
    except NameError:  # Nonexistent.
        pass
    list_frame = tk.Frame(root)  # (Re)create Label container.
    list_frame.pack()
    for fruit in checked_list:
        tk.Label(list_frame, text=fruit).pack()

    # Clear out GUI by unchecking all the Checkbuttons.
    for cb in check_buttons:
        cb.deselect()


tk.Button(root, text='Show Chosen Fruits', command=label_fruits).pack()

root.mainloop()

通过此变量,azurerm_route将运行此函数并创建路由。

#include <conio.h>
#include <iostream>
#include <vector>

using namespace std;
class Something{
    int id;
};

int main() {
    int num;
    cin >> num;
    vector<Something> something;
    //Something *somethings = new Something[num];
    for (;;) {
        if (_kbhit()) {
            if (_getch() == 27) {
                break;
            }
        }
    }
    return 0;
}

但是,我在计数前缀列表时遇到问题,并且收到以下错误:

Enter route destinations: 0.0.0.0/0,192.168.0.0/16

1 个答案:

答案 0 :(得分:1)

弄清楚了。您必须使用元素插值。

resource "azurerm_route" "route" {
  name                    = "route-${count.index}"
  resource_group_name     = "resourcegroup"
  route_table_name        = "table"
  address_prefix          = "${element(split(",",var.destinations),count.index)}"
  next_hop_type           = "Internet"
  count                   = "${length(split(",",var.destinations))}"
}