Skip to content

Commit

Permalink
Branch 241111 example e2e test pipeline (#665)
Browse files Browse the repository at this point in the history
* add e2e test case for examples

* update make terrafmt command to format examples

* update nightly test pipeline

* fix the test
  • Loading branch information
ms-henglu authored Nov 12, 2024
1 parent 53a8509 commit f3127cd
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 111 deletions.
2 changes: 2 additions & 0 deletions .azdo/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ jobs:
ARM_TEST_LOCATION: $(ARM_TEST_LOCATION)
ARM_TEST_LOCATION_ALT: $(ARM_TEST_LOCATION_ALT)
ARM_TEST_LOCATION_ALT2: $(ARM_TEST_LOCATION_ALT2)
ARM_TEST_EXAMPLES: $(ARM_TEST_EXAMPLES)
TESTARGS: $(TESTARGS)
2 changes: 2 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ fmtcheck:
@sh "$(CURDIR)/scripts/check-test-package.sh"

terrafmt:
@echo "==> Fixing examples with terrafmt"
@find examples | egrep .tf | sort | while read f; do terraform fmt $$f || echo "error in $$f"; done
@echo "==> Fixing acceptance test terraform blocks code with terrafmt..."
@find internal | egrep "_test.go" | sort | while read f; do terrafmt fmt -f $$f; done
@echo "==> Fixing website terraform blocks code with terrafmt..."
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/2.0-upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,4 @@ When you run `terraform plan`, you will see the following error message:
How to fix:
1. Run `terraform refresh` to update the state file.
2. Specify the `disable_default_output = true` in the provider block to disable the default output.
2. Specify the `disable_default_output = true` in the provider block to disable the default output.
6 changes: 3 additions & 3 deletions docs/resources/data_plane_resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ e.g. to replace a resource when either the SKU or os_type attributes change:

```hcl
resource "azapi_data_plane_resource" "example" {
name = var.name
type = "Microsoft.AppConfiguration/configurationStores/[email protected]"
body = {
name = var.name
type = "Microsoft.AppConfiguration/configurationStores/[email protected]"
body = {
properties = {
sku = var.sku
zones = var.zones
Expand Down
2 changes: 1 addition & 1 deletion docs/resources/resource.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ resource "azapi_resource" "example" {
name = var.name
type = "Microsoft.Network/publicIPAddresses@2023-11-01"
parent_id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example"
body = {
body = {
properties = {
sku = var.sku
zones = var.zones
Expand Down

This file was deleted.

6 changes: 3 additions & 3 deletions internal/services/azapi_data_plane_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ func (r *DataPlaneResource) Schema(ctx context.Context, request resource.SchemaR
"\n" +
"```hcl\n" +
"resource \"azapi_data_plane_resource\" \"example\" {\n" +
" name = var.name\n" +
" type = \"Microsoft.AppConfiguration/configurationStores/[email protected]\"\n" +
" body = {\n" +
" name = var.name\n" +
" type = \"Microsoft.AppConfiguration/configurationStores/[email protected]\"\n" +
" body = {\n" +
" properties = {\n" +
" sku = var.sku\n" +
" zones = var.zones\n" +
Expand Down
2 changes: 1 addition & 1 deletion internal/services/azapi_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (r *AzapiResource) Schema(ctx context.Context, _ resource.SchemaRequest, re
" name = var.name\n" +
" type = \"Microsoft.Network/publicIPAddresses@2023-11-01\"\n" +
" parent_id = \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example\"\n" +
" body = {\n" +
" body = {\n" +
" properties = {\n" +
" sku = var.sku\n" +
" zones = var.zones\n" +
Expand Down
50 changes: 50 additions & 0 deletions internal/services/azapi_resource_example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package services_test

import (
"fmt"
"os"
"path"
"strings"
"testing"

"github.com/Azure/terraform-provider-azapi/internal/acceptance"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccExamples(t *testing.T) {
cases := strings.Split(os.Getenv("ARM_TEST_EXAMPLES"), ",")

for _, c := range cases {
if strings.Trim(c, " ") == "" {
continue
}
t.Run(c, func(t *testing.T) {
workingDir := path.Join("..", "..", "examples", c)
t.Logf("Running example %s", workingDir)

content, err := os.ReadFile(path.Join(workingDir, "main.tf"))
if err != nil {
t.Errorf("Error reading main.tf: %v", err)
return
}

data := acceptance.BuildTestData(t, "azapi_resource", "test")
config := string(content)
config = strings.ReplaceAll(config, `terraform {
required_providers {
azapi = {
source = "Azure/azapi"
}
}
}`, "")
config = strings.ReplaceAll(config, `default = "acctest0001"`, fmt.Sprintf(`default = "acctest%s"`, data.RandomString))

r := GenericResource{}
data.ResourceTest(t, r, []resource.TestStep{
{
Config: config,
},
})
})
}
}
2 changes: 1 addition & 1 deletion templates/guides/2.0-upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,4 @@ When you run `terraform plan`, you will see the following error message:
How to fix:
1. Run `terraform refresh` to update the state file.
2. Specify the `disable_default_output = true` in the provider block to disable the default output.
2. Specify the `disable_default_output = true` in the provider block to disable the default output.

0 comments on commit f3127cd

Please sign in to comment.