Skip to content

Instantly share code, notes, and snippets.

@odenkun
Last active December 1, 2018 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odenkun/8158eb21c029f6d9d2d7ef38caa12573 to your computer and use it in GitHub Desktop.
Save odenkun/8158eb21c029f6d9d2d7ef38caa12573 to your computer and use it in GitHub Desktop.
AWSTemplateFormatVersion: 2010-09-09
Parameters:
VPCname:
MinLength: 2
MaxLength: 12
AllowedPattern: "[0-9a-zA-Z]+"
Type: String
Resources:
testVPC:
Type: 'AWS::EC2::VPC'
Properties:
CidrBlock: 172.16.0.0/16
Tags:
- Key: Name
Value: !Ref VPCname
- hosts: localhost
vars:
token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
app_code: "XXXXXXXXXXX"
base_url: "https://XXXXXXXXXXXXXXX.cybozu.com/k/v1/"
mono_url: "{{ base_url }}record.json?app={{app_code}}"
multi_url: "{{ base_url }}records.json?app={{app_code}}"
not_created: 'isCreated in ("未")'
tasks:
- name: get records
uri:
url: "{{ multi_url }}&query={{ not_created | urlencode }}"
method: GET
return_content: yes
headers:
X-Cybozu-API-Token: "{{token}}"
register: candidates_in_json
- name: create a cloudformation stack
cloudformation:
stack_name: "stackFor{{ item.vpcName.value }}"
state: "present"
region: "ap-northeast-1"
template: "./cfn.tmpl"
template_format: "yaml"
template_parameters:
VPCname: "vpcFor{{ item.vpcName.value }}"
with_items: "{{candidates_in_json.json.records}}"
register: create_stack_result
- name: update records
uri:
url: "{{ mono_url }}"
method: PUT
return_content: yes
headers:
X-Cybozu-API-Token: "{{ token }}"
body_format: json
body: {
"app": "{{app_code}}",
"id": "{{ item.item['$id'].value }}",
"record": {
"isCreated": {
"value": "OK"
}
}
}
with_items: "{{ create_stack_result.results }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment