Skip to content

Instantly share code, notes, and snippets.

@writeameer
Last active November 27, 2016 11:45
Show Gist options
  • Save writeameer/5bb0f0b9494c8caac6c4412054616673 to your computer and use it in GitHub Desktop.
Save writeameer/5bb0f0b9494c8caac6c4412054616673 to your computer and use it in GitHub Desktop.
public void AppGateway() {
var resourceGroup = "blah";
var location = "Australia East";
var netClient = new NetworkManagementClient(credential) { SubscriptionId = Lookup.subscriptionId };
// Create IP for gateway
var ipParams = new PublicIPAddress{Location = location ,PublicIPAllocationMethod = "Dynamic" };
var newIp = netClient.PublicIPAddresses.CreateOrUpdate(resourceGroup, "appGatewayFrontendIP", ipParams);
Console.WriteLine(newIp.IpAddress);
// Get subnet Id
var devNet = netClient.VirtualNetworks.List("blah")
.Where(x => x.Name.Equals("development")).FirstOrDefault();
var tier1Subnet = devNet.Subnets.Where(sn => sn.Name.Equals("Tier1")).FirstOrDefault();
// FrontEnd IP Config
var frontEndIpConfig = new ApplicationGatewayFrontendIPConfiguration
{
PublicIPAddress = new SubResource { Id = newIp.Id },
//Subnet = new SubResource { Id = tier1Subnet.Id },
Name = "appGatewayFrontendIP"
};
var frontEndPort = new ApplicationGatewayFrontendPort { Name = "appGatewayFrontendPort", Port = 80 };
var frontendIPConfigurations = new List<ApplicationGatewayFrontendIPConfiguration>() { frontEndIpConfig };
var backEndAddressPool = new ApplicationGatewayBackendAddressPool {
Name = "appGatewayBackendPool" ,
BackendAddresses = new List<ApplicationGatewayBackendAddress> { new ApplicationGatewayBackendAddress { IpAddress = "1.1.1.1" } }
};
var backendHttpSetting = new ApplicationGatewayBackendHttpSettings { Name= "appGatewayBackendHttpSettings", Protocol = "http", Port = 80 };
var gatewayIpConfig = new ApplicationGatewayIPConfiguration { Name = "appGatewayIpConfig", Subnet = tier1Subnet };
var httpListener = new ApplicationGatewayHttpListener
{
Name = "appGatewayHttpListener",
FrontendIPConfiguration = frontEndIpConfig,
FrontendPort = frontEndPort
};
var requestRoutingRule = new ApplicationGatewayRequestRoutingRule
{
Name = "rule1",
RuleType = "Basic",
HttpListener = httpListener,
BackendAddressPool = backEndAddressPool,
BackendHttpSettings = backendHttpSetting
};
// Create Gateway
var parameters = new ApplicationGateway()
{
Location = location,
Sku = new ApplicationGatewaySku { Name = ApplicationGatewaySkuName.StandardSmall, Capacity = 1, Tier = "Standard" },
FrontendPorts = new List<ApplicationGatewayFrontendPort> { frontEndPort },
FrontendIPConfigurations = frontendIPConfigurations,
GatewayIPConfigurations = new List<ApplicationGatewayIPConfiguration> { gatewayIpConfig },
BackendAddressPools = new List<ApplicationGatewayBackendAddressPool>() { backEndAddressPool },
BackendHttpSettingsCollection = new List<ApplicationGatewayBackendHttpSettings>() { backendHttpSetting },
HttpListeners = new List<ApplicationGatewayHttpListener> { httpListener },
RequestRoutingRules = new List<ApplicationGatewayRequestRoutingRule> { requestRoutingRule}
};
netClient.ApplicationGateways.CreateOrUpdate(resourceGroup, "test111", parameters);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment