Skip to content

Conversation

@whgiles
Copy link

@whgiles whgiles commented Nov 13, 2024

Resolves #2461


Before the change?

After I run an import command

Error: Configuration for import target does not exist

The configuration for the given import <module>.github_actions_environment_secret.<name> <repository>/<environment>/<secret_name> does not exist. All target instances must have an associated configuration to be imported.

After the change?

I should be able to run:

Terraform import '<module>.github_actions_environment_secret.<name> <repository>/<environment>/<secret_name>'

or use and import block

import {
    to = <module>.github_actions_environment_secret.<name> <repository>/<environment>/<secret_name>
    id = "<repository>/<environment>/<secret_name>"
}

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

No

Please see our docs on breaking changes to help!

  • Yes
  • No

@whgiles whgiles changed the title [Feature] add environment secret import feat: add environment secret import Nov 13, 2024
@whgiles whgiles changed the title feat: add environment secret import feat: add environment secret import capabilities Nov 13, 2024
@whgiles
Copy link
Author

whgiles commented Nov 13, 2024

changes are based off of #1763

@dcfsc
Copy link
Contributor

dcfsc commented Feb 28, 2025

Would love to see this merged instead of having to patch the Terrraform state directly. Please.

@dcfsc
Copy link
Contributor

dcfsc commented Sep 24, 2025

I just tried building the current 6.6.0 provider with this code merged in so I can do some importing. Not a go guru, but I think I am using go 1.22.4 on linux.

I get an error

$ go build
# [github.com/integrations/terraform-provider-github/v6/github](http://github.com/integrations/terraform-provider-github/v6/github)
github/resource_github_actions_environment_secret.go:238:72: undefined: escapedEnvName

I was able to get around it by adding

236: repo, _, err := client.Repositories.Get(ctx, owner, repoName)
237: 
238: escapedEnvName := url.PathEscape(envName)  <<<<<<<<<< ADD THIS
239: 
240: secret, _, err := client.Actions.GetEnvSecret(ctx, int(repo.GetID()), escapedEnvName, secretName)

@whgiles
Copy link
Author

whgiles commented Sep 27, 2025

@dcfsc Thanks for pointing that out. I just pushed the update

@whgiles
Copy link
Author

whgiles commented Sep 27, 2025

@dcfsc This PR is pretty old, I am not sure how to get the attention of the code admins to approve the CI checks.

@dcfsc
Copy link
Contributor

dcfsc commented Sep 29, 2025

@dcfsc This PR is pretty old, I am not sure how to get the attention of the code admins to approve the CI checks.

Me either. At least I can hack the provider for the cases I need it. Not an optimal solution, to be sure. Thanks for the fix!

owner := meta.(*Owner).name
ctx := context.Background()

parts := strings.Split(d.Id(), "/")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use colon for the import separator? Then you could use parseID3 here

func resourceGithubActionsEnvironmentSecretImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use Context-aware provider functions instead?

return nil, err
}

repo, _, err := client.Repositories.Get(ctx, owner, repoName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This shouldn't be necessary if the import ID contains enough information to be able to successfully run Read afterwards.
Usually that's the ID

}
`, randomID, envName, secretName, secretValue)

testCase := func(t *testing.T, mode string) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We've abandoned this pattern in tests, could you conform to the new pattern?

@github-project-automation github-project-automation bot moved this from 👀 In review to 🏗 In progress in 🧰 Octokit Active Jan 22, 2026
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.

[BUG]: Not able to Import github_actions_environment_secret

3 participants