Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into fix-handle_drift_withIsDeleted-#225
  • Loading branch information
samuel-br committed Mar 2, 2022
2 parents 357054e + 1aa9e32 commit 85267ae
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 118 deletions.
19 changes: 0 additions & 19 deletions .github/release-drafter.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.16 # please change also in `release.yml` and `go.mod`
go-version: ${{ secrets.GO_VERSION }}
- name: Checkout code
uses: actions/checkout@v2
- name: Go fmt
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/release-drafter.yml

This file was deleted.

10 changes: 3 additions & 7 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name: release
on:
push:
tags:
- 'v*'
- 'v*.*.*'
jobs:
goreleaser:
runs-on: ubuntu-latest
Expand All @@ -28,15 +28,12 @@ jobs:
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16 # please change also in `ci.yml` and `go.mod`
go-version: ${{ secrets.GO_VERSION }}
-
name: Import GPG key
uses: hashicorp/ghaction-import-gpg@v2.1.0
id: import_gpg
# TODO: move this to HashiCorp namespace or find alternative that is just simple gpg commands
# see https://github.com/hashicorp/terraform-provider-scaffolding/issues/22
uses: paultyng/ghaction-import-gpg@v2.1.0
env:
# These secrets will need to be configured for the repository:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
PASSPHRASE: ${{ secrets.PASSPHRASE }}
-
Expand All @@ -47,5 +44,4 @@ jobs:
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
# GitHub sets this automatically
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/update-generated-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Update generated docs

on:
push:

jobs:
Update-generated-docs:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ secrets.GO_VERSION }}
-
name: Update generated docs
run: ./generate-docs.sh
-
name: Commit changes
uses: EndBug/add-and-commit@v8
with:
author_name: update generated docs action
author_email: mail@example.com
message: 'Update docs'
add: 'docs/*'

15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Each test perform the following steps:
The harness has two modes to help while developing: If an environment variable `DESTROY_MODE` exists and it's value is `NO_DESTROY`, the harness will avoid calling `terraform destroy`, allowing the developer to inspect the resources created, through the dashboard, for example.
Afterwards, when cleanup is required, just set `DESTROY_MODE` to `DESTROY_ONLY` and _only_ `terraform destroy` will run.

#### Integration Test Prerequisites
- An env0 organization
- An API Key
- A Github.com integrated template name `Github Integrated Template` for https://github.com/env0/templates
- A Gitlab.com integrated template name `Gitlab Integrated Template` for https://gitlab.com/env0/gitlab-vcs-integration-tests

### Unit Testing
#### How to run tests
Run from root directory:
Expand Down Expand Up @@ -144,9 +150,6 @@ go generate ./...

## Release
To release a version to the [Terraform Public Registry](https://registry.terraform.io/providers/env0/env0/latest?pollNotifications=true) -
1. Docs must be generated manually and committed to the repo before release. (`./generate-docs.sh`)
2. Create and push a tag locally, in semver format - `git tag v0.0.9 && git push origin --tags`
3. Goto [Github Releases](https://github.com/env0/terraform-provider-env0/releases) and edit the draft created by Release Drafter Bot - it should contain the change log for the release. Make sure it's pointing at the tag you created in the previous step and publish the release.
4. Binaries will be automatically generated by the Github action defined in `.github/workflows/release.yml`
5. The Registry will automatically pick up on the new version. If the registry says the release doesn't have any binaries, check the result of the `release` Github action. You might need to [Resync](https://registry.terraform.io/providers/env0/env0/latest/settings?pollNotifications=true) the registry after the action finishes.

1. Create and push a tag **locally**, in semver format - `git tag v0.0.9 && git push origin --tags`
2. New release with binaries **will be automatically generated** by the GitHub action defined in `.github/workflows/release.yml`.
3. The Registry will automatically pick up on the new version.
1 change: 1 addition & 0 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ data "env0_template" "example" {
- **github_installation_id** (Number) The env0 application installation id on the relevant github repository
- **gitlab_project_id** (Number) The project id of the relevant repository
- **id** (String) id of the template
- **is_gitlab_enterprise** (Boolean) Does this template use gitlab enterprise repository?
- **name** (String) the name of the template
- **token_id** (String) The token id used for private git repos or for integration with GitLab

Expand Down
7 changes: 5 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ provider "env0" {
<!-- schema generated by tfplugindocs -->
## Schema

### Optional
### Required

- **api_endpoint** (String) override api endpoint (used for testing)
- **api_key** (String, Sensitive) env0 api key (https://developer.env0.com/docs/api/YXBpOjY4Njc2-env0-api#creating-an-api-key)
- **api_secret** (String, Sensitive) env0 api key secret

### Optional

- **api_endpoint** (String) override api endpoint (used for testing)
1 change: 0 additions & 1 deletion env0/resource_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ func resourceTemplate() *schema.Resource {
Type: schema.TypeString,
Description: "The token id used for private git repos or for integration with GitLab, you can get this value by using a data resource of an existing Gitlab template or contact our support team",
Optional: true,
RequiredWith: []string{"gitlab_project_id"},
ConflictsWith: []string{"github_installation_id"},
},
"gitlab_project_id": {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/env0/terraform-provider-env0

go 1.16 // please change also in `ci.yml` and `release.yml`
go 1.16 // please change also in repo secrets

require (
github.com/adhocore/gronx v0.2.6
Expand Down
2 changes: 1 addition & 1 deletion tests/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func terraformCommand(testName string, arg ...string) ([]byte, error) {
if err != nil {
log.Println("error running terraform ", arg, " in ", testName, " error: ", err, " output: ", output)
} else {
log.Println("Completed successfully terraform ", arg, " in ", testName)
log.Println("Completed successfully terraform", arg, "in", testName)
}
return outputBytes, err
}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/002_project/expected_outputs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"default_project_name": "Default Organization Project",
"default_description": "Test Description after update"
"test_project_name": "Test-Project",
"test_project_description": "Test Description after update"
}
20 changes: 7 additions & 13 deletions tests/integration/002_project/main.tf
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
data "env0_project" "default" {
name = "Default Organization Project"
}

resource "env0_project" "test_project" {
name = "Test-Project"
description = "Test Description ${var.second_run ? "after update" : ""}"
}

data "env0_project" "default2" {
depends_on = [data.env0_project.default]
id = data.env0_project.default.id
data "env0_project" "data_by_name" {
name = env0_project.test_project.name
}

output "default_project_id" {
value = data.env0_project.default.id
data "env0_project" "data_by_id" {
id = env0_project.test_project.id
}

output "default_project_name" {
value = data.env0_project.default2.name
output "test_project_name" {
value = env0_project.test_project.name
}

output "default_description" {
output "test_project_description" {
value = env0_project.test_project.description
}
24 changes: 10 additions & 14 deletions tests/integration/003_configuration_variable/main.tf
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
data "env0_configuration_variable" "region" {
name = "AWS_DEFAULT_REGION"
resource "env0_project" "test_project" {
name = "Project-for-003-configuration-variable"
}
output "region_value" {
value = data.env0_configuration_variable.region.value
sensitive = true
}
output "region_id" {
value = data.env0_configuration_variable.region.id
}


data "env0_project" "default" {
name = "Default Organization Project"
resource "env0_configuration_variable" "region_in_project_resource" {
name = "AWS_DEFAULT_REGION"
project_id = env0_project.test_project.id
value = "il-tnuvot-1"
}

data "env0_configuration_variable" "region_in_project" {
name = "AWS_DEFAULT_REGION"
project_id = data.env0_project.default.id
project_id = env0_project.test_project.id
depends_on = [env0_configuration_variable.region_in_project_resource]
}
output "region_in_project_value" {
value = data.env0_configuration_variable.region_in_project.value
Expand Down Expand Up @@ -61,4 +57,4 @@ output "tested3_enum_1" {
output "tested3_enum_2" {
value = data.env0_configuration_variable.tested3.enum[1]
sensitive = true
}
}
4 changes: 2 additions & 2 deletions tests/integration/004_template/expected_outputs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"tested2_template_type": "terraform",
"tested2_template_name": "tested1",
"tested2_template_repository": "https://github.com/env0/templates",
"tested1_template_repository": "https://gitlab.com/eran.elbaz/templates.git",
"tested1_template_repository": "https://gitlab.com/env0/gitlab-vcs-integration-tests.git",
"tested2_template_path": "second"
}
}
23 changes: 16 additions & 7 deletions tests/integration/004_template/main.tf
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
data "env0_project" "default_project" {
name = "Default Organization Project"
# Github Integration must be done manually - so we expect an existing Github Template with this name -
# It must be for https://github.com/env0/templates - We validate that in the outputs
data "env0_template" "github_template" {
name = "Github Integrated Template"
}

# Gitlab Integration must be done manually - so we expect an existing Gitlab Template with this name
# It must be for https://gitlab.com/env0/gitlab-vcs-integration-tests - the gitlab_project_id is still static
data "env0_template" "gitlab_template" {
name = "Gitlab Integrated Template"
}

resource "env0_template" "tested1" {
name = "tested1"
description = "Tested 1 description"
type = "terraform"
repository = "https://github.com/env0/templates"
github_installation_id = 11551359
repository = data.env0_template.github_template.repository
github_installation_id = data.env0_template.github_template.github_installation_id
path = var.second_run ? "second" : "misc/null-resource"
retries_on_deploy = 3
retry_on_deploy_only_when_matches_regex = "abc"
Expand All @@ -19,9 +27,9 @@ resource "env0_template" "tested2" {
name = "GitLab Test"
description = "Tested 2 description - Gitlab"
type = "terraform"
repository = "https://gitlab.com/eran.elbaz/templates.git"
token_id = "6be35256-b685-4e92-8f6b-a332f5832c06"
gitlab_project_id = 28713760
repository = data.env0_template.gitlab_template.repository
token_id = data.env0_template.gitlab_template.token_id
gitlab_project_id = 32315446
path = var.second_run ? "second" : "misc/null-resource"
retries_on_deploy = 3
retry_on_deploy_only_when_matches_regex = "abc"
Expand Down Expand Up @@ -74,3 +82,4 @@ output "tested2_template_path" {
data "env0_template" "tested3" {
id = env0_template.tested1.id
}

11 changes: 1 addition & 10 deletions tests/integration/010_team_project_assignment/main.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
data "env0_project" "default" {
name = "Default Organization Project"
}

resource "env0_project" "test_project" {
name = "Test-Project"
description = "Test Description ${var.second_run ? "after update" : ""}"
}

data "env0_project" "default2" {
depends_on = [data.env0_project.default]
id = data.env0_project.default.id
}

resource "env0_team" "team_resource" {
name = "Test-Team"
description = var.second_run ? "second description" : "first description"
Expand All @@ -22,4 +13,4 @@ resource "env0_team_project_assignment" "assignment" {
project_id = env0_project.test_project.id
team_id = env0_team.team_resource.id
role = "Admin"
}
}
9 changes: 4 additions & 5 deletions tests/integration/011_policy/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
data "env0_project" "default" {
name = "Default Organization Project"
resource "env0_project" "test_project" {
name = "Test-Project-For_policy"
}

resource "env0_project_policy" "test_policy" {
project_id = data.env0_project.default.id
project_id = env0_project.test_project.id
number_of_environments = 1
number_of_environments_total = 1
requires_approval_default = true
Expand All @@ -14,7 +13,7 @@ resource "env0_project_policy" "test_policy" {
}

resource "env0_project_policy" "test_policy_2" {
project_id = data.env0_project.default.id
project_id = env0_project.test_project.id
number_of_environments = 1
number_of_environments_total = 1
requires_approval_default = true
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/012_environment/main.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "env0_project" "default" {
name = "Default Organization Project"
resource "env0_project" "test_project" {
name = "Test-Project-for-environment"
}

resource "env0_template" "template" {
Expand All @@ -13,7 +13,7 @@ resource "env0_template" "template" {
resource "env0_environment" "example" {
force_destroy = true
name = "environment"
project_id = data.env0_project.default.id
project_id = env0_project.test_project.id
template_id = env0_template.template.id
configuration {
name = "environment configuration variable"
Expand Down
Loading

0 comments on commit 85267ae

Please sign in to comment.