public async Task <AttachInternetGatewayResponse> AttachInternetGatewayAsync(string internetGatewayId, string vpcId)
        {
            var request = new AttachInternetGatewayRequest
            {
                InternetGatewayId = internetGatewayId,
                VpcId             = vpcId
            };

            var response = await _cloudComputeClient.AttachInternetGatewayAsync(request);

            return(response);
        }
示例#2
0
        public bool load_internet_gateway_id()
        {
            write_log(region + " のインターネットゲートウェイを確認しています。");
            try
            {
                var client    = get_client();
                var query_req = new DescribeInternetGatewaysRequest();
                query_req.Filters.Add(new Filter()
                {
                    Name = "tag-value", Values = new List <string>()
                    {
                        Helper.build_name(setting_, "igw")
                    }
                });
                var query_res = client.DescribeInternetGateways(query_req);
                if (query_res.InternetGateways.Count != 0)
                {
                    foreach (var row in query_res.InternetGateways[0].Attachments)
                    {
                        if (row.VpcId.Equals(vpc_id))
                        {
                            internet_gateway_id = query_res.InternetGateways[0].InternetGatewayId;
                            write_log(vpc_id + " のインターネットゲートウェイは " + internet_gateway_id + " です");
                            return(true);
                        }
                    }
                }

                write_log(region + " にインターネットゲートウェイを作成しています。");
                var create_req = new CreateInternetGatewayRequest();
                var create_res = client.CreateInternetGateway(create_req);

                set_name_tag(client, create_res.InternetGateway.InternetGatewayId, Helper.build_name(setting_, "igw"));
                internet_gateway_id = create_res.InternetGateway.InternetGatewayId;
                write_log("インターネットゲートウェイ " + internet_gateway_id + " を作成しました。");


                write_log("VPC " + vpc_id + " に " + internet_gateway_id + " を関連付けます。");
                var attach_req = new AttachInternetGatewayRequest();
                attach_req.InternetGatewayId = internet_gateway_id;
                attach_req.VpcId             = vpc_id;
                client.AttachInternetGateway(attach_req);
            }
            catch (Exception ex)
            {
                write_log("ERROR: " + ex.ToString());
                return(false);
            }
            return(true);
        }