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

feat: allow toggling of state refresh #998

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions github/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
)

type Config struct {
Token string
Owner string
BaseURL string
Insecure bool
WriteDelay time.Duration
Token string
Owner string
BaseURL string
Insecure bool
DetectDrift bool
WriteDelay time.Duration
}

type Owner struct {
Expand All @@ -28,6 +29,7 @@ type Owner struct {
v3client *github.Client
v4client *githubv4.Client
StopContext context.Context
DetectDrift bool
IsOrganization bool
}

Expand Down
21 changes: 16 additions & 5 deletions github/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ func Provider() terraform.ResourceProvider {
Description: descriptions["organization"],
Deprecated: "Use owner (or GITHUB_OWNER) instead of organization (or GITHUB_ORGANIZATION)",
},
"detect_drift": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: descriptions["detect_drift"],
},
"base_url": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -157,6 +163,8 @@ func init() {

"base_url": "The GitHub Base API URL",

"detect_drift": "Will disable state refresh if true",

"insecure": "Enable `insecure` mode for testing purposes",

"owner": "The GitHub owner name to manage. " +
Expand All @@ -181,6 +189,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
baseURL := d.Get("base_url").(string)
token := d.Get("token").(string)
insecure := d.Get("insecure").(bool)
detectDrift := d.Get("detect_drift").(bool)

// BEGIN backwards compatibility
// OwnerOrOrgEnvDefaultFunc used to be the default value for both
Expand Down Expand Up @@ -249,11 +258,12 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
log.Printf("[DEBUG] Setting write_delay_ms to %d", writeDelay)

config := Config{
Token: token,
BaseURL: baseURL,
Insecure: insecure,
Owner: owner,
WriteDelay: time.Duration(writeDelay) * time.Millisecond,
Token: token,
BaseURL: baseURL,
Insecure: insecure,
Owner: owner,
DetectDrift: detectDrift,
WriteDelay: time.Duration(writeDelay) * time.Millisecond,
}

meta, err := config.Meta()
Expand All @@ -262,6 +272,7 @@ func providerConfigure(p *schema.Provider) schema.ConfigureFunc {
}

meta.(*Owner).StopContext = p.StopContext()
meta.(*Owner).DetectDrift = detectDrift

return meta, nil
}
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_actions_environment_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ func resourceGithubActionsEnvironmentSecretCreateOrUpdate(d *schema.ResourceData
}

func resourceGithubActionsEnvironmentSecretRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_actions_organization_permissions.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func resourceGithubActionsOrganizationPermissionsCreateOrUpdate(d *schema.Resour
}

func resourceGithubActionsOrganizationPermissionsRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
ctx := context.Background()

Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_actions_organization_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ func resourceGithubActionsOrganizationSecretCreateOrUpdate(d *schema.ResourceDat
}

func resourceGithubActionsOrganizationSecretRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func resourceGithubActionsOrganizationSecretRepositoriesCreateOrUpdate(d *schema
}

func resourceGithubActionsOrganizationSecretRepositoriesRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_actions_runner_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ func resourceGithubActionsRunnerGroupCreate(d *schema.ResourceData, meta interfa
}

func resourceGithubActionsRunnerGroupRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_actions_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func resourceGithubActionsSecretCreateOrUpdate(d *schema.ResourceData, meta inte
}

func resourceGithubActionsSecretRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
ctx := context.Background()
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_app_installation_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ func resourceGithubAppInstallationRepositoryCreate(d *schema.ResourceData, meta
}

func resourceGithubAppInstallationRepositoryRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ func resourceGithubBranchCreate(d *schema.ResourceData, meta interface{}) error
}

func resourceGithubBranchRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

ctx := context.WithValue(context.Background(), ctxId, d.Id())
if !d.IsNewResource() {
ctx = context.WithValue(ctx, ctxEtag, d.Get("etag").(string))
Expand Down
4 changes: 4 additions & 0 deletions github/resource_github_branch_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func resourceGithubBranchDefaultCreate(d *schema.ResourceData, meta interface{})
}

func resourceGithubBranchDefaultRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_branch_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ func resourceGithubBranchProtectionCreate(d *schema.ResourceData, meta interface
}

func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

var query struct {
Node struct {
Node BranchProtectionRule `graphql:"... on BranchProtectionRule"`
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_branch_protection_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func resourceGithubBranchProtectionV3Create(d *schema.ResourceData, meta interfa
}

func resourceGithubBranchProtectionV3Read(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_branch_protection_v3_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func flattenAndSetRequiredStatusChecks(d *schema.ResourceData, protection *githu
}

func requireSignedCommitsRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

repoName, branch, err := parseTwoPartID(d.Id(), "repository", "branch")
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func resourceGithubIssueLabelCreateOrUpdate(d *schema.ResourceData, meta interfa
}

func resourceGithubIssueLabelRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
repoName, name, err := parseTwoPartID(d.Id(), "repository", "name")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func resourceGithubMembershipCreateOrUpdate(d *schema.ResourceData, meta interfa
}

func resourceGithubMembershipRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_organization_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func resourceGithubOrganizationProjectCreate(d *schema.ResourceData, meta interf
}

func resourceGithubOrganizationProjectRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_organization_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ func resourceGithubOrganizationWebhookCreate(d *schema.ResourceData, meta interf
}

func resourceGithubOrganizationWebhookRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

err := checkOrganization(meta)
if err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_project_card.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func resourceGithubProjectCardCreate(d *schema.ResourceData, meta interface{}) e
}

func resourceGithubProjectCardRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
nodeID := d.Id()
cardID := d.Get("card_id").(int)
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_project_column.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func resourceGithubProjectColumnCreate(d *schema.ResourceData, meta interface{})
}

func resourceGithubProjectColumnRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

columnID, err := strconv.ParseInt(d.Id(), 10, 64)
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,11 @@ func resourceGithubRepositoryCreate(d *schema.ResourceData, meta interface{}) er
}

func resourceGithubRepositoryRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
repoName := d.Id()
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_autolink_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func resourceGithubRepositoryAutolinkReferenceCreate(d *schema.ResourceData, met
}

func resourceGithubRepositoryAutolinkReferenceRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

owner := meta.(*Owner).name
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func resourceGithubRepositoryCollaboratorCreate(d *schema.ResourceData, meta int
}

func resourceGithubRepositoryCollaboratorRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

owner := meta.(*Owner).name
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_deploy_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func resourceGithubRepositoryDeployKeyCreate(d *schema.ResourceData, meta interf
}

func resourceGithubRepositoryDeployKeyRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

owner := meta.(*Owner).name
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ func resourceGithubRepositoryEnvironmentCreate(d *schema.ResourceData, meta inte
}

func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client

owner := meta.(*Owner).name
Expand Down
4 changes: 4 additions & 0 deletions github/resource_github_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func resourceGithubRepositoryFileCreate(d *schema.ResourceData, meta interface{}
}

func resourceGithubRepositoryFileRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name
Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_milestone.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func resourceGithubRepositoryMilestoneCreate(d *schema.ResourceData, meta interf
}

func resourceGithubRepositoryMilestoneRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

conn := meta.(*Owner).v3client
ctx := context.WithValue(context.Background(), ctxId, d.Id())

Expand Down
5 changes: 5 additions & 0 deletions github/resource_github_repository_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ func resourceGithubRepositoryProjectCreate(d *schema.ResourceData, meta interfac
}

func resourceGithubRepositoryProjectRead(d *schema.ResourceData, meta interface{}) error {
drift := meta.(*Owner).DetectDrift
if !drift {
return nil
}

client := meta.(*Owner).v3client
owner := meta.(*Owner).name

Expand Down
Loading