Skip to content

Commit b94fce9

Browse files
authored
Merge pull request #74 from sullivtr/iss-70-opt-out-remote-state-verify
conditionalize remote-state verification logic, and add simple test
2 parents d23aff8 + 562f7ed commit b94fce9

15 files changed

+212
-120
lines changed

.github/workflows/acceptance.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2
@@ -27,12 +27,12 @@ jobs:
2727
terraform_wrapper: false
2828

2929
- name: Run test
30-
run: go test -v ./... | awk '!/\[no test files\]/ {print}'
30+
run: go test -v -coverprofile=cover.out ./... | awk '!/\[no test files\]/ {print}'
3131

3232
- name: Upload coverage to Codecov
3333
uses: codecov/codecov-action@v1
3434
with:
3535
token: ${{ secrets.CODECOV_TOKEN }}
36-
file: ./cp.out
36+
file: ./cover.out
3737
name: codecov-umbrella
3838
fail_ci_if_error: false

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
goreleaser:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2
@@ -29,7 +29,7 @@ jobs:
2929
- name: Build
3030
uses: goreleaser/goreleaser-action@v2
3131
with:
32-
version: latest
32+
version: 1.5.0
3333
args: release --snapshot --skip-validate --skip-publish
3434
env:
3535
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

.github/workflows/e2e.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88

99
jobs:
1010
test:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-20.04
1212
steps:
1313
- name: Checkout
1414
uses: actions/checkout@v2
@@ -29,8 +29,10 @@ jobs:
2929
- name: Build
3030
uses: goreleaser/goreleaser-action@v2
3131
with:
32-
version: latest
32+
version: 1.5.0
3333
args: release --snapshot --skip-validate --skip-publish --skip-sign -f .goreleaser-e2e-build.yml
3434

3535
- name: Run test
36-
run: make test
36+
run: |
37+
make copyplugins
38+
make test

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
jobs:
99
goreleaser:
10-
runs-on: ubuntu-latest
10+
runs-on: ubuntu-20.04
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v2
@@ -28,7 +28,7 @@ jobs:
2828
- name: Release
2929
uses: goreleaser/goreleaser-action@v2
3030
with:
31-
version: latest
31+
version: 1.5.0
3232
args: release --rm-dist
3333
env:
3434
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

GNUmakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ build: clean fetch ## publishes in dry run mode
2626
copyplugins: ## copy plugins to test folders
2727
$(eval COPY_FILES := $(filter %/, $(wildcard ./dist/terraform-provider-graphql*/)))
2828
$(eval OS_ARCH := $(patsubst ./dist/terraform-provider-graphql_%/, %, $(COPY_FILES)))
29-
$(eval TEST_FOLDERS := $(foreach p,$(OS_ARCH), $(patsubst %,%terraform.d/plugins/terraform.example.com/examplecorp/graphql/2.0.0/$p,$(TEST_DESTS))))
29+
$(eval TEST_FOLDERS := $(foreach p,$(OS_ARCH), $(patsubst %,%terraform.d/plugins/gqlprovidertf.com/examplecorp/graphql/2.0.0/$p,$(TEST_DESTS))))
3030
@sleep 1
3131
@mkdir -p $(TEST_FOLDERS);
3232
@for o in $(OS_ARCH); do \
3333
for f in $(TEST_DESTS); do \
34-
cp ./dist/terraform-provider-graphql_$$o/* $$f/terraform.d/plugins/terraform.example.com/examplecorp/graphql/2.0.0/$$o; \
34+
cp ./dist/terraform-provider-graphql_$$o/* $$f/terraform.d/plugins/gqlprovidertf.com/examplecorp/graphql/2.0.0/$$o; \
3535
done; \
3636
done
3737

38-
test: copyplugins ## test
38+
test: ## test
3939
@cd e2e && $(MAKE) test
4040

4141
fulltest: build test ## build and test

cp.out

Lines changed: 0 additions & 78 deletions
This file was deleted.

docs/resources/mutation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ resource "graphql_mutation" "basic_mutation" {
4848
* `compute_mutation_keys` - (Required) A map representing the hierarchy of your response object leading to the object properties that will be used during a terraform destroy & update operation.
4949
* `compute_from_create` - A bool to determine if computed keys should be computed based off of the response from the create request, or the read request. Default: false
5050
* `force_replace` - A bool to determine if the resource should always be replaced (deleted and recreated) during update lifecycle hooks. Default: false
51+
* `enable_remote_state_verification` - A pre v2.4.0 backward-compatibility flag. Set to `false` to disable resource remote state verification during reads.
5152

5253

5354
## Attribute Reference

e2e/basic_test.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,50 @@ func TestBasicCreateUpdateMutations(t *testing.T) {
6060
assert.NoFileExists(t, "./gql-server/test.json")
6161
}
6262

63+
func TestBasicCreateUpdateMutationsRemoteStateVerificationDisabled(t *testing.T) {
64+
65+
varFileCreate := []string{"./variable_initial_create_remote_state_verify_disabled.tfvars"}
66+
varFileUpdate := []string{"./variable_update.tfvars"}
67+
terraformOptionsCreate := &terraform.Options{
68+
// Set the path to the Terraform code that will be tested.
69+
TerraformDir: "./test_basic",
70+
VarFiles: varFileCreate,
71+
Logger: logger.Discard,
72+
}
73+
74+
terraformOptionsUpdate := &terraform.Options{
75+
TerraformDir: "./test_basic",
76+
VarFiles: varFileUpdate,
77+
Logger: logger.Discard,
78+
}
79+
80+
// Ensure workspace is clean
81+
assert.NoFileExists(t, "./gql-server/test.json")
82+
83+
terraform.InitAndApply(t, terraformOptionsCreate)
84+
85+
// Validate creation
86+
assert.FileExists(t, "./gql-server/test.json")
87+
88+
// Validate data source output
89+
dataSourceOutput, _ := terraform.OutputJsonE(t, terraformOptionsCreate, "query_output")
90+
assert.Contains(t, dataSourceOutput, initialTextOutput)
91+
92+
// Validate computed delete variables
93+
deleteVariableOutput, _ := terraform.OutputJsonE(t, terraformOptionsCreate, "computed_delete_variables")
94+
assert.Contains(t, deleteVariableOutput, idOutPut)
95+
assert.Contains(t, deleteVariableOutput, testVarComputed)
96+
97+
// Run update & validate changes
98+
terraform.InitAndApply(t, terraformOptionsUpdate)
99+
updatedOutput, _ := terraform.OutputJsonE(t, terraformOptionsUpdate, "query_output")
100+
assert.Contains(t, updatedOutput, updatedTextOutput)
101+
assert.NotContains(t, updatedOutput, initialTextOutput)
102+
103+
terraform.Destroy(t, terraformOptionsUpdate)
104+
assert.NoFileExists(t, "./gql-server/test.json")
105+
}
106+
63107
func TestBasicForceReplace(t *testing.T) {
64108

65109
varFileCreate := []string{"./variable_initial_create.tfvars"}

e2e/test_basic/test.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
terraform {
22
required_providers {
33
graphql = {
4-
source = "terraform.example.com/examplecorp/graphql"
4+
source = "gqlprovidertf.com/examplecorp/graphql"
55
version = "2.0.0"
66
}
77
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
todo_text = "Here is something todo"
2+
todo_user_id = "T5577006791947779410"
3+
4+
compute_mutation_keys = {
5+
"id" = "todo.id"
6+
}
7+
compute_from_create = false
8+
enable_remote_state_verification = false

0 commit comments

Comments
 (0)