Пример #1
0
        public async Task <ResourceProvisioningResult> EnsureCreated(ResourceProvisioningParameters parameters, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"Creating Bastion for sandbox with Name: {parameters.SandboxName}! Resource Group: {parameters.ResourceGroupName}");

            if (!parameters.TryGetSharedVariable(AzureCrudSharedVariable.BASTION_SUBNET_ID, out string subnetId))
            {
                throw new ArgumentException("AzureBastionService: Missing Bastion subnet ID from input");
            }

            var bastionHost = await GetResourceInternalAsync(parameters.ResourceGroupName, parameters.Name, false);

            if (bastionHost == null)
            {
                bastionHost = await CreateInternal(GetRegionFromString(parameters.Region), parameters.ResourceGroupName, parameters.Name, subnetId, parameters.Tags, cancellationToken);

                _logger.LogInformation($"Done creating Bastion for sandbox with Id: {parameters.SandboxName}! Bastion Id: {bastionHost.Id}");
            }
            else
            {
                _logger.LogInformation($"Ensure bastion exist for Sandbox: {parameters.SandboxName}! Bastion allready existed. Bastion Id: {bastionHost.Id}");
            }

            var result = CreateResult(bastionHost);

            return(result);
        }
Пример #2
0
        public async Task <ResourceProvisioningResult> EnsureCreated(ResourceProvisioningParameters parameters, CancellationToken cancellationToken = default)
        {
            _logger.LogInformation($"Creating virtual network {parameters.Name} in resource Group: {parameters.ResourceGroupName}");

            var networkSettings = CloudResourceConfigStringSerializer.NetworkSettings(parameters.ConfigurationString);

            var virtualNetwork = await GetResourceInternalAsync(parameters.ResourceGroupName, parameters.Name, false);

            if (virtualNetwork == null)
            {
                virtualNetwork = await CreateInternalAsync(GetRegionFromString(parameters.Region), parameters.ResourceGroupName, parameters.Name, networkSettings.SandboxSubnetName, parameters.Tags, cancellationToken);
            }

            if (!parameters.TryGetSharedVariable(AzureCrudSharedVariable.NETWORK_SECURITY_GROUP_NAME, out string networkSecurityGroupName))
            {
                throw new ArgumentException("AzureVirtualNetworkService: Missing network security group name from input");
            }

            await EnsureNetworkSecurityGroupIsAddedToSubnet(virtualNetwork, networkSecurityGroupName, networkSettings.SandboxSubnetName);

            _logger.LogInformation($"Done creating virtual network {parameters.Name}");

            var crudResult = CreateResult(virtualNetwork);

            return(crudResult);
        }
Пример #3
0
        protected string GetSharedVariableThrowIfNotFoundOrEmpty(ResourceProvisioningParameters parameters, string variableName, string descriptionForErrorMessage)
        {
            if (!parameters.TryGetSharedVariable(variableName, out string sharedVariableValue))
            {
                throw new ArgumentException($"{this.GetType().Name}: Missing {descriptionForErrorMessage} from input");
            }
            else if (String.IsNullOrWhiteSpace(sharedVariableValue))
            {
                throw new ArgumentException($"{this.GetType().Name}: Empty {descriptionForErrorMessage} from input");
            }

            return(sharedVariableValue);
        }