services | platforms | author |
---|---|---|
network | Go | marstr |
This sample assumes that you have an Azure subscription to target. If you do not already have one, you can get started for free at azure.microsoft.com.
You should also have a machine with Go 1.9 or higher installed.
You will need to have the following environment variables set when executing this sample:
- AZURE_SUBSCRIPTION_ID
- AZURE_TENANT_ID
- AZURE_CLIENT_ID
- AZURE_CLIENT_SECRET
There's a lot of great documentation that can be found on populating those variables, getting starting with Service Principals, and accessing your subscription programaticly. Here are some of the sites that will be best at helping you get started:
There are a couple of options for acquiring and running this sample.
-
Using
go get...
:This is fastest and easiest, but will clutter your PATH. Simply run the following command:
go get -u github.com/Azure-Samples/network-go-manage-network-security-group
Once
go get
has finished running, you should be able to execute the command:network-go-manage-network-security-group
If you make tweaks to the source code for the sample, you will need to re-build and optionally re-install the sample.
-
Clone & Build:
Using this option will require using glide, but doesn't add anything into your Go bin directory. For this option, take the following steps:
- Install glide if it's not already present on your machine.
git clone git@github.com:Azure-Samples/network-go-manage-network-security-group.git
cd network-go-manage-network-security-group
glide install
- `go run ./sample.go
Using either of the above options, your subscription may have restrictions on which Locations are eligible for the operations taken by this sample. If you run into trouble, you can change the region which is targeted by the global variable sampleLocation
. At the time of this writing, the definition is on line 47.
For convenience of the ability to test the network security groups that were craeted by this sample, there are a couple of ways to delay cleanup.
-pause
waits for human acknowledgement before deleting the resource group that was created.-delay {uint}
waits a specified number of seconds before deleting the resource group that was created. If you don't care to see the output messages, you can pass the flag-quiet
.
- Create a Resource Group to encapsulate everything created by this sample.
- Create a Virtual Network that will host the subjects of this sample.
- Create two Security Groups that initially have no rules to enforce.
- Create two Subnets, and associate them with the previously created Security Groups.
- Create a set of SecurityRules for each Subnet that hypothetically would give appropriate access.
- Clean up. Delete all of the items that were created above.