markdown route_53_resolver.md

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown route_53_resolver.md相关的知识,希望对你有一定的参考价值。

This shows a config file which can be parsed with Python's configparser. Rules.py will read this config file and construct a JSON object with IP addresses dynamically.

## rules.conf
```
[domain1-rule]
Name = domain1-rule
RuleType = Forward
DomainName = domain1
Ips = 10.10.10.10, 10.10.10.11, 10.10.10.12
Port = 53

[domain2-rule]
Name = domain2-rule
RuleType = Forward
DomainName = domain2
Ips = 10.10.10.10, 10.10.10.11
Port = 53

[domain3-rile]
Name = domain3-rule
RuleType = Forward
DomainName = domain3
Ips = 10.10.10.13, 10.10.10.14, 10.10.10.15
Port = 8500
```

## Rules.py

```python
import boto3
import configparser

def test_function(config):
    print(config)

rules_config = configparser.ConfigParser()
rules_config.read('rules.conf')

domains = rules_config.sections()

for domain in domains:
    name = rules_config.get(domain, 'Name')
    rule_type = rules_config.get(domain, 'RuleType')
    rule_domain = rules_config.get(domain, 'DomainName')
    ips = rules_config.get(domain, 'Ips')
    port = rules_config.get(domain, 'Port')

    print("Adding rule: {} - {} - {}".format(name, rule_type, rule_domain))

    test_function(
        config={
            'TargetIps': [{'Ip': ip, 'Port': port} for ip in ips.split(", ")]
        }
    )
```

## Output
Below is what you should get when you run the above Python script:
```
Adding rule: domain1-rule - Forward - domain1
{'TargetIps': [{'Ip': '10.10.10.10', 'Port': '53'}, {'Ip': '10.10.10.11', 'Port': '53'}, {'Ip': '10.10.10.12', 'Port': '53'}]}
Adding rule: domain2-rule - Forward - domain2
{'TargetIps': [{'Ip': '10.10.10.10', 'Port': '53'}, {'Ip': '10.10.10.11', 'Port': '53'}]}
Adding rule: domain3-rule - Forward - domain3
{'TargetIps': [{'Ip': '10.10.10.13', 'Port': '8500'}, {'Ip': '10.10.10.14', 'Port': '8500'}, {'Ip': '10.10.10.15', 'Port': '8500'}]}
```

以上是关于markdown route_53_resolver.md的主要内容,如果未能解决你的问题,请参考以下文章

在 aws_route53_record terraform 资源中使用“计数”

如何使用 Terraform 将现有的“aws_route53_record”CNAME 更新/修改为 ALIAS

尝试创建 aws_route53_record 以指向负载均衡器,但使用 terraform 不断出现错误

Terraform 设置 Route53 NS 记录永远不会完成

如何使用Boto 3获取域的托管区域?

Amazon Web服务Route 53忽略域名