I created an App Configuration using Pulumi:
_configurationStore = new ConfigurationStore(appConfigurationName, new ConfigurationStoreArgs
{
ResourceGroupName = _resourceGroup.Name,
Location = _resourceGroup.Location,
Sku = "standard"
});
Now I am stuck adding values to it. The docs don't mention any method to read or write settings into my ConfigurationStore (or I simply cannot find it).
How can I store simple key/value-Pairs?
How can I store "links" to values from an existing keyvault? Do I simply create the connectionstring manually?
Adding key-values was introduced by Azure Resource Manager (ARM) just recently in the 2020-07-01-preview version and there's no "stable" API version with them yet. So, you should use that version to define key-values
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValue("kv",
new Pulumi.AzureNextGen.AppConfiguration.V20200701Preview.KeyValueArgs
{
ResourceGroupName = _resourceGroup.Name,
ConfigStoreName = _configurationStore.Name,
KeyValueName = "key1",
Value = "value1",
});
You can read more in the docs: https://www.pulumi.com/docs/reference/pkg/azure-nextgen/appconfiguration/keyvalue/
Also, discussed in this issue: https://github.com/pulumi/pulumi-azure-nextgen/issues/62
Related
I am looking for the most appropriate way to store and/or use variables initialized during startup (Program.cs) throughout the application as needed, or an acceptable alternative process if there's a better way to accomplish this.
I.e., the following code snippet in Program.cs initializes the Azure Key Vault connectionString variable at runtime with a correct value retrieved from the designated Azure Key Vault:
var keyVaultUrl = builder.Configuration.GetValue<string>("KeyVault:KeyVaultUrl");
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
SecretClientOptions options = new SecretClientOptions()
{
Retry =
{
Delay= TimeSpan.FromSeconds(2),
MaxDelay = TimeSpan.FromSeconds(16),
MaxRetries = 5,
Mode = RetryMode.Exponential
}
};
var client = new SecretClient(new Uri(keyVaultUrl), new DefaultAzureCredential(), options);
KeyVaultSecret secretConnectionString = client.GetSecret("ConnectionString");
string connectionString = secretConnectionString.Value;
}
The objective is to use this variable or others on-demand without having to call the code another time. Any thoughts are appreciated.
Check the below steps to store the KeyVault Connection string in Azure Appsettings.
I do agree with #Dai, yes instead of getting the ConnectionString/Varaibles from KeyVault , we can store the values in Azure App Service => Configuration => Application Settings.
My appsettings.json
"ConnectionStrings": {
"MyVal": "DummyString"
}
Create a secret in KeyVault and copy the Secret Identifier.
Azure App Settings
Thanks to #Jayant Kulkarni - reference taken from c-sharpcorner.
I need to create subdomains in Azure DNS from ASP.NET Core dynamically so that the users who needs to create their own subdomains can do it as we see in most of the web apps out there like wix, etc..
Could anyone please detail the right steps well explained?
Thanks.
There is a management SDK for Azure, which you can use inside your ASP.NET Core application.
Create DNS zones and record sets using the .NET SDK - this is detailed full tutorial for this.
Code will be similar to this, though you will probably use CNAMEs instead of A records
// Create record set parameters
var recordSetParams = new RecordSet();
recordSetParams.TTL = 3600;
// Add records to the record set parameter object. In this case, we'll add a record of type 'A'
recordSetParams.ARecords = new List<ARecord>();
recordSetParams.ARecords.Add(new ARecord("1.2.3.4"));
// Add metadata to the record set. Similar to Azure Resource Manager tags, this is optional and you can add multiple metadata name/value pairs
recordSetParams.Metadata = new Dictionary<string, string>();
recordSetParams.Metadata.Add("user", "Mary");
// Create the actual record set in Azure DNS
// Note: no ETAG checks specified, will overwrite existing record set if one exists
var recordSet = await dnsClient.RecordSets.CreateOrUpdateAsync(resourceGroupName, zoneName, recordSetName, RecordType.A, recordSetParams);
I'm trying to create a new branch policy using Microsoft.TeamFoundation.Policy.WebApi Library.
my Code is:
variable info:
json - contains the setting in the policy configuration
connection - is the VSSConnection to our TFS server
TFSProject - is the project name in the TFS
the error i get the is not showing anything in my searches, i would appreciate some examples for how to create a new policy in TFS
code:
var json = "{\"statusName\": \"" + StatusNameForBlock + "\",\"statusGenre\": \"ci\",\"authorId\": null,\"invalidateOnSourceUpdate\": false,\"policyApplicability\": null,\"scope\": [{\"refName\": \"refs/heads/master\",\"matchKind\": \"Exact\"}]}";
JObject jToken = new JObject(JObject.Parse(json));
var newPolicy = new PolicyConfiguration();
var policyType = new PolicyTypeRef();
policyType.Id = Guid.NewGuid();
newPolicy.Type = policyType;
newPolicy.Settings = jToken;
var gitPolicyHttpClient = connection.GetClient<PolicyHttpClient>();
var policyCreated = gitPolicyHttpClient.CreatePolicyConfigurationAsync(newPolicy, TFSProject).Result;
exception: VssServiceException: Type with id '98813712-70a4-4937-b139-9a3654c9795f' does not exist
You could use Rest API to create a new branch policy.
POST https://{instance}/{collection}/{project}/_apis/policy/configurations/{configurationId}?api-version=5.0
Use these APIs to define policies for your projects. Configurations associate a type, such as "Required reviewers", with specific settings, such as "For pull requests with files named *.dll targeting the master branch in the xxx Git repository, add the Source-Controlled Binaries Team as a required reviewer".
Policy Examples for your reference.
For more details, you could also take a look at this blog-- Configuring standard policies for all repositories in Azure Repos
EDIT
Solved, the solution is in the comments.
I'm trying to create a record set in AWS Route53 that targets an alias CloudFront distribution.
At the moment, I'm creating a new hosted zone with the desired domain (works fine).
Afterward, I'm taking the HostedZoneId from the response and trying to create a recordset that points to a CloudFront Distribution that has this domain in his CNAMEs. (If I only create the hosted zone using the API and then trying to create the record set manually it works fine and I can see the CDN Alias on the list).
I'm following this example from AWS Documentation -
var response = client.ChangeResourceRecordSets(new ChangeResourceRecordSetsRequest
{
ChangeBatch = new ChangeBatch {
Changes = new List<change> {
new Change {
Action = "CREATE",
ResourceRecordSet = new ResourceRecordSet {
AliasTarget = new AliasTarget {
DNSName = "d123rk29d0stfj.cloudfront.net",
EvaluateTargetHealth = false,
HostedZoneId = "Z2FDTNDATAQYW2" // Different Hosted Zone?
},
Name = "example.com",
Type = "A"
}
}
},
Comment = "CloudFront distribution for example.com"
},
HostedZoneId = "Z3M3LMPEXAMPLE" // Different Hosted Zone?
});
Why is the Alias Target HostedZoneId property and the outer HostedZoneId aren't the same??? shouldn't they both be the Id of the hosted zone created for the desired domain?
The error I receive is -
Tried to create an alias that targets d123rk29d0stfj.cloudfront.net., type A in zone Z3BW3XHLEBEA2Z, but the alias target name does not lie within the target zone
Thanks for reading, cheers
So... of course that once Iv'e decided to post my question I found an answer lol.
According to the documentation, CloudFront HostedZoneId value MUST be Z2FDTNDATAQYW2.
Hope it might help anyone in the future, thanks.
I have localstack (https://github.com/localstack/localstack) running and am able to use the aws s3 cli to upload files to it.
What I want to be able to do is use the .NET AWS ADK with localstack. I'd like the following code to upload a file into localstack:
using (var tfu = new TransferUtility())
{
await tfu.UploadAsync(new TransferUtilityUploadRequest
{
Key = key,
BucketName = bucketName,
ContentType = document.ContentType,
Headers = { ["Content-Disposition"] = "attachment; filename=\"test.txt\"" },
InputStream = stream
});
}
My problem is I don't know how to set the endpoints so that localstack is used by the SDK rather than aws. Apparently you can set the AWSEndpointDefinition in appSettings.config as mentioned in the AWS SDK documentation, e.g:
<add key="AWSEndpointDefinition" value="C:\Dev\localstack\endpoints.json"/>
However I have no idea what this endpoints.json config should look like. I tried using this file:
https://raw.githubusercontent.com/aws/aws-sdk-net/master/sdk/src/Core/endpoints.json
When I do this, as soon as I new up a TransferUtility class I get a null reference exception - this is before I point anything to my localstack setup.
The version of AWS ASK is 3.3.0.
Another thing to note is that in some places in the documentation it is implied that the config should be an xml file rather than a json, however, when I try to use an xml file instead I get a different exception when newing up TransferUtility: 'Invalid character '<' in input string'
You can easily override it by creating an S3 client and passing it to TransferUtility constructor.
var config = new AmazonS3Config { ServiceURL = "http://localhost:4572" };
var s3client = new AmazonS3Client(config);
Do not forget to replace URL if your localstack is using different port for S3.
Hope this helps.