public async Task TestUpdateOlderResourceVersion() { using var terraform = await _host.CreateTerraformTestInstanceAsync(ProviderName); var resourcePath = Path.Combine(terraform.WorkDir, "file.tf"); await File.WriteAllTextAsync(resourcePath, $@" resource ""{ProviderName}_sampleresource"" ""item1"" {{ data = ""some value"" }} "); var tfstate = Assembly.GetExecutingAssembly().GetManifestResourceStream("SchemaUpgrade.Test.terraform.tfstate"); using (var tfStateFile = File.Create(Path.Combine(terraform.WorkDir, "terraform.tfstate"))) { await tfstate.CopyToAsync(tfStateFile); } var plan = await terraform.PlanWithOutputAsync(); // State should be upgraded, but there are no changes to apply. var resourceChange = plan.ResourceChanges.Single().Change; Assert.That(resourceChange.Actions.Single(), Is.EqualTo("no-op")); Assert.That(resourceChange.After.GetProperty("data").GetString(), Is.EqualTo(resourceChange.Before.GetProperty("data").GetString())); }
public async Task TestCreateFile() { using var terraform = await _host.CreateTerraformTestInstanceAsync(ProviderName); var resourcePath = Path.Combine(terraform.WorkDir, "file.tf"); var testFilePath = Path.Combine(terraform.WorkDir, "test.txt"); var fileContent = "this is a test"; await File.WriteAllTextAsync(resourcePath, $@" resource ""{ProviderName}_file"" ""demo_file"" {{ path = ""{testFilePath.Replace("\\", "\\\\")}"" content = ""{fileContent}"" }} "); await terraform.PlanAsync(); await terraform.ApplyAsync(); Assert.That(File.Exists(testFilePath)); Assert.That(await File.ReadAllTextAsync(testFilePath), Is.EqualTo(fileContent)); }
public async Task TestPlanCreateAllFields() { using var terraform = await _host.CreateTerraformTestInstanceAsync(ProviderName); var resourcePath = Path.Combine(terraform.WorkDir, "file.tf"); await File.WriteAllTextAsync(resourcePath, @" resource ""test_resource"" ""test"" { required_string = ""value"" required_int = 1 int_attribute = 1 boolean_attribute = true float_attribute = 1.0 double_attribute = 1.0 string_list_attribute = [""one"", ""two"", ""three""] int_list_attribute = [1, 2, 3] string_map_attribute = { a = ""one"", b = ""two"", c = ""three"" } int_map_attribute = { a = 1, b = 2, c = 3 } } "); var plan = await terraform.PlanWithOutputAsync(); Assert.That(plan.ResourceChanges, Has.Count.EqualTo(1)); Assert.That(plan.ResourceChanges.Single().Change.Actions.Single(), Is.EqualTo("create")); Assert.That(plan.ResourceChanges.Single().Change.Before.ValueKind, Is.EqualTo(JsonValueKind.Null)); var after = JsonSerializer.Serialize(plan.ResourceChanges.Single().Change.After, new JsonSerializerOptions() { WriteIndented = true }); var expected = @" { ""boolean_attribute"": true, ""double_attribute"": 1, ""float_attribute"": 1, ""int_attribute"": 1, ""int_list_attribute"": [ 1, 2, 3 ], ""int_map_attribute"": { ""a"": 1, ""b"": 2, ""c"": 3 }, ""required_int"": 1, ""required_string"": ""value"", ""string_list_attribute"": [ ""one"", ""two"", ""three"" ], ""string_map_attribute"": { ""a"": ""one"", ""b"": ""two"", ""c"": ""three"" } }".Trim(); Assert.That(after, Is.EqualTo(expected)); }