Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF-9605] Add Private Registry Module Testing #1096

Merged
merged 1 commit into from
Nov 16, 2023
Merged

Conversation

hashimoon
Copy link
Contributor

@hashimoon hashimoon commented Oct 9, 2023

Description

Add the following attributes to RegistryModule to support testing

  • publishing_mechanism
  • vcs_repo.branch
  • vcs_repo.tags
  • test_config.tests_enabled

Remember to:

Testing plan

  1. Create a RegistryModule
  2. Confirm the publishing_mechanism is git_tag
  3. Set vcs_repo.branch to a branch on the git repository
  4. Set vcs_repo.tags to false
  5. Set test_config.tests_enabled to true
  6. Perform changes
  7. Confirm the publishing_mechanism is branch
  8. Enjoy your registry module with tests enabled

External links

Include any links here that might be helpful for people reviewing your PR. If there are none, feel free to delete this section.

Output from acceptance tests

Please run applicable acceptance tests locally and include the output here. See testing.md to learn how to run acceptance tests.

If you are an external contributor, your contribution(s) will first be reviewed before running them against the project's CI pipeline.

$ TESTARGS="-run TestAccTFERegistryModuleImport" make testacc

?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/client	0.137s [no tests to run]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/logging	0.181s [no tests to run]
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
=== RUN   TestAccTFERegistryModule_vcs
--- PASS: TestAccTFERegistryModule_vcs (7.89s)
=== RUN   TestAccTFERegistryModule_GitHubApp
    provider_test.go:230: Please set GITHUB_APP_INSTALLATION_ID to run this test
--- SKIP: TestAccTFERegistryModule_GitHubApp (0.00s)
=== RUN   TestAccTFERegistryModule_emptyVCSRepo
--- PASS: TestAccTFERegistryModule_emptyVCSRepo (0.13s)
=== RUN   TestAccTFERegistryModule_nonVCSPrivateRegistryModuleWithoutRegistryName
--- PASS: TestAccTFERegistryModule_nonVCSPrivateRegistryModuleWithoutRegistryName (4.48s)
=== RUN   TestAccTFERegistryModule_nonVCSPrivateRegistryModuleWithRegistryName
--- PASS: TestAccTFERegistryModule_nonVCSPrivateRegistryModuleWithRegistryName (4.35s)
=== RUN   TestAccTFERegistryModule_publicRegistryModule
--- PASS: TestAccTFERegistryModule_publicRegistryModule (4.92s)
=== RUN   TestAccTFERegistryModule_noCodeModule
--- PASS: TestAccTFERegistryModule_noCodeModule (4.95s)
=== RUN   TestAccTFERegistryModuleImport_vcsPrivateRMDeprecatedFormat
--- PASS: TestAccTFERegistryModuleImport_vcsPrivateRMDeprecatedFormat (8.42s)
=== RUN   TestAccTFERegistryModuleImport_vcsPrivateRMRecommendedFormat
--- PASS: TestAccTFERegistryModuleImport_vcsPrivateRMRecommendedFormat (8.14s)
=== RUN   TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranch
--- PASS: TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranch (19.21s)
=== RUN   TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranchWithTests
--- PASS: TestAccTFERegistryModuleImport_vcsPublishingMechanismBranchToTagsToBranchWithTests (9.25s)
=== RUN   TestAccTFERegistryModuleImport_vcsPublishingMechanismTagsToBranchToTags
--- PASS: TestAccTFERegistryModuleImport_vcsPublishingMechanismTagsToBranchToTags (14.34s)
=== RUN   TestAccTFERegistryModuleImport_nonVCSPrivateRM
--- PASS: TestAccTFERegistryModuleImport_nonVCSPrivateRM (4.95s)
=== RUN   TestAccTFERegistryModuleImport_publicRM
--- PASS: TestAccTFERegistryModuleImport_publicRM (4.49s)
=== RUN   TestAccTFERegistryModule_invalidWithBothVCSRepoAndModuleProvider
--- PASS: TestAccTFERegistryModule_invalidWithBothVCSRepoAndModuleProvider (0.14s)
=== RUN   TestAccTFERegistryModule_invalidRegistryName
--- PASS: TestAccTFERegistryModule_invalidRegistryName (0.27s)
=== RUN   TestAccTFERegistryModule_invalidWithModuleProviderAndNoName
--- PASS: TestAccTFERegistryModule_invalidWithModuleProviderAndNoName (0.11s)
=== RUN   TestAccTFERegistryModule_invalidWithModuleProviderAndNoOrganization
--- PASS: TestAccTFERegistryModule_invalidWithModuleProviderAndNoOrganization (0.11s)
=== RUN   TestAccTFERegistryModule_invalidWithNamespaceAndNoRegistryName
--- PASS: TestAccTFERegistryModule_invalidWithNamespaceAndNoRegistryName (0.11s)
=== RUN   TestAccTFERegistryModule_invalidWithRegistryNameAndNoModuleProvider
--- PASS: TestAccTFERegistryModule_invalidWithRegistryNameAndNoModuleProvider (0.11s)
PASS
ok  	github.com/hashicorp/terraform-provider-tfe/internal/provider	96.758s

...

@hashimoon hashimoon changed the title WIP Add Private Registry Module Testing Oct 9, 2023
@hashimoon hashimoon force-pushed the hashimoon/pmr-testing branch 6 times, most recently from e31531e to 8ab253d Compare October 13, 2023 15:27
@hashimoon hashimoon changed the title Add Private Registry Module Testing [TF-9605] Add Private Registry Module Testing Oct 13, 2023
@hashimoon hashimoon marked this pull request as ready for review October 13, 2023 15:52
@hashimoon hashimoon requested a review from a team as a code owner October 13, 2023 15:52
@hashimoon hashimoon force-pushed the hashimoon/pmr-testing branch 6 times, most recently from 8a3824c to d9da171 Compare October 13, 2023 17:44
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No smoke test yet. Just some initial quick observations and questions so far.

CHANGELOG.md Outdated
## UNRELEASED

Features
* `d/tfe_registry_module`: Add `test_config` and `vcs_repo.tags` attributes, by @hashimoon [1096](https://github.com/hashicorp/terraform-provider-tfe/pull/1096)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, publishing_mechanism and vcs_repo.branch -- It might be worth quickly explaining that these are related in the sense that they allow module developers more release flexibility but I don't have the words

Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke test feedback:

  • creating RM with tags set to true creates RM with tag => false, config used:
resource "tfe_registry_module" "test-with-tags-only-true" {
vcs_repo {
 display_identifier = ""
   identifier         = ""
   oauth_token_id     = "id"
  tags             = true
}
}

Should be able to create tags with true value

  • creating RM with test_config.tests_enabled set to true creates RM with tests_enabled => false, config used:
resource "tfe_registry_module" "test-with-test-config-set-to-true" {
test_config {
  tests_enabled = true
}
vcs_repo {
 display_identifier = ""
   identifier         = ""
   oauth_token_id     = "id"
  tags             = true
}
}

Should be able to create tests_enabled with true value

  • creating a RM without adding the test_config block is successful. Attempting a new apply without any config changes, tries to unsets the test_config block:
 # tfe_registry_module.test-with-branch-only will be updated in-place
 ~ resource "tfe_registry_module" "test-with-branch-only" {
       id                   = "mod-1"
       name                 = "tfe-module"
       # (6 unchanged attributes hidden)

     - test_config {
         - tests_enabled = false -> null
       }

       # (1 unchanged block hidden)
   }

@hashimoon hashimoon force-pushed the hashimoon/pmr-testing branch 2 times, most recently from 13f2812 to 8c76c27 Compare October 23, 2023 23:56
@hashimoon
Copy link
Contributor Author

@Uk1288

  • creating RM with tags set to true creates RM with tag => false, config used:

Do you have any more context on this? Can you see share what value is return for the publishingMechanism ? Creating a VCS-based Registry Module defaults to tag based publishing currently. With this PR, we are returning the tags attribute back to the client.

Should be able to create tags with true value

- creating RM with test_config.tests_enabled set to true creates RM with tests_enabled => false, config used:

This is expected behavior. Tests are only supported for modules with branch-based publishing.

Should be able to create tests_enabled with true value

- creating a RM without adding the test_config block is successful. Attempting a new apply without any config changes, tries to unsets the test_config block:

This is expected behavior. Tests are only supported for Registry Modules with branch-based publishing at the moment.

@hashimoon hashimoon force-pushed the hashimoon/pmr-testing branch 2 times, most recently from e7f9532 to 00b2886 Compare October 24, 2023 00:17
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good progress, see our slack chat for other comments with usecase examples.

@@ -125,6 +155,9 @@ The following arguments are supported:
* `namespace` - (Optional) The namespace of a public registry module. It can be used if `module_provider` is set and `registry_name` is public.
* `registry_name` - (Optional) Whether the registry module is private or public. It can be used if `module_provider` is set.

The `test_config` block supports
* `tests_enabled` - (Required) Specifies whether tests run for the registry module. Tests are only supported for branch-based publishing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation sets both test_config and tests_enabled as optional attributes, but here it is state as required...update to reflect same requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

website/docs/r/registry_module.html.markdown Outdated Show resolved Hide resolved
@hashimoon hashimoon requested a review from Uk1288 November 8, 2023 03:06
@hashimoon hashimoon force-pushed the hashimoon/pmr-testing branch 2 times, most recently from 1ce75a4 to 1585890 Compare November 8, 2023 18:23
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Smoke testing feedback:
Most of the config is working as expected 🎉

Found 2 config with issues below
1.
Actual: successful apply..s of the config below always ends up in a state with changes to update. A second apply seems to get stuck in an infinite state trying to modify. I ctrl c to stop the process.
Expected: after an apply the resource state should reflect created resource

Config:

resource "tfe_registry_module" "test-with-branch-tags-and-test-config" {
 test_config {
   tests_enabled = true
 }
 vcs_repo {
    display_identifier = "Uk1288/terraform-google-cloud-dns"
    identifier         = "Uk1288/terraform-google-cloud-dns"
    oauth_token_id     = "ot-ID..."
    branch             = "main"
    tags             = true
 }
}

Results in changes to update:

      ~ vcs_repo {
          ~ tags               = false -> true
            # (4 unchanged attributes hidden)
        }

Actual: provider crashes.
Expected: should successfully apply or return an error

Config:

resource "tfe_registry_module" "test-with-branch-tags-and-test-config" {
 test_config {
 }
 vcs_repo {
    display_identifier = "Uk1288/terraform-google-cloud-dns"
    identifier         = "Uk1288/terraform-google-cloud-dns"
    oauth_token_id     = "ot-ID..."
    branch             = "main"
 }
}

CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Uk1288 Uk1288 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gave this another go, working as expected. Approving because functionality is working as expected.

🍹 One of my configs seems to be reset even after a successful apply. Expected behaviour is for state changes to reflect the resources after a successful apply.
Config:

resource "tfe_registry_module" "test-without-test-config-block" {
 vcs_repo {
    display_identifier = "Uk1288/terraform-aws-simple-s3-cdn"
    identifier         = "Uk1288/terraform-aws-simple-s3-cdn"
    oauth_token_id     = "ot-id..."
   branch             = "main"
   tags             = false
 }
}

After a successful apply still results in

# tfe_registry_module.test-without-test-config-block will be updated in-place
  ~ resource "tfe_registry_module" "test-without-test-config-block" {
        id                   = "mod-..."
        name                 = "simple-s3-cdn"
        # (6 unchanged attributes hidden)

      - test_config {
          - tests_enabled = false -> null
        }

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Expected behaviour to result in no changes to apply.

@hashimoon hashimoon merged commit ce83189 into main Nov 16, 2023
9 checks passed
@hashimoon hashimoon deleted the hashimoon/pmr-testing branch November 16, 2023 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants