-
Notifications
You must be signed in to change notification settings - Fork 14
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
Fix: support more vcs-type fields in module creation #1006
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,6 @@ import ( | |
) | ||
|
||
func resourceModule() *schema.Resource { | ||
vcsExactlyOneOf := []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. using conflictsWith instead. |
||
"token_id", | ||
"github_installation_id", | ||
"bitbucket_client_key", | ||
} | ||
|
||
return &schema.Resource{ | ||
CreateContext: resourceModuleCreate, | ||
ReadContext: resourceModuleRead, | ||
|
@@ -50,10 +44,10 @@ func resourceModule() *schema.Resource { | |
Optional: true, | ||
}, | ||
"token_id": { | ||
Type: schema.TypeString, | ||
Description: "the git token id to be used", | ||
Optional: true, | ||
ExactlyOneOf: vcsExactlyOneOf, | ||
Type: schema.TypeString, | ||
Description: "the git token id to be used", | ||
Optional: true, | ||
ConflictsWith: []string{"github_installation_id", "bitbucket_client_key"}, | ||
}, | ||
"token_name": { | ||
Type: schema.TypeString, | ||
|
@@ -62,16 +56,16 @@ func resourceModule() *schema.Resource { | |
RequiredWith: []string{"token_id"}, | ||
}, | ||
"github_installation_id": { | ||
Type: schema.TypeInt, | ||
Description: "the env0 application installation id on the relevant Github repository", | ||
Optional: true, | ||
ExactlyOneOf: vcsExactlyOneOf, | ||
Type: schema.TypeInt, | ||
Description: "the env0 application installation id on the relevant Github repository", | ||
Optional: true, | ||
ConflictsWith: []string{"token_id", "bitbucket_client_key"}, | ||
}, | ||
"bitbucket_client_key": { | ||
Type: schema.TypeString, | ||
Description: "the client key used for integration with Bitbucket", | ||
Optional: true, | ||
ExactlyOneOf: vcsExactlyOneOf, | ||
Type: schema.TypeString, | ||
Description: "the client key used for integration with Bitbucket", | ||
Optional: true, | ||
ConflictsWith: []string{"token_id", "github_installation_id"}, | ||
}, | ||
"ssh_keys": { | ||
Type: schema.TypeList, | ||
|
@@ -119,6 +113,30 @@ func resourceModule() *schema.Resource { | |
Optional: true, | ||
Default: false, | ||
}, | ||
"is_gitlab": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not using conflictsWith for these as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure! |
||
Type: schema.TypeBool, | ||
Description: "true if this module integrates with GitLab", | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"is_bitbucket_server": { | ||
Type: schema.TypeBool, | ||
Description: "true if this module integrates with Bitbucket Server", | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"is_github_enterprise": { | ||
Type: schema.TypeBool, | ||
Description: "true if this module integrates with GitHub Enterprise", | ||
Optional: true, | ||
Default: false, | ||
}, | ||
"is_gitlab_enterprise": { | ||
Type: schema.TypeBool, | ||
Description: "true if this module integrates with GitLab Enterprise", | ||
Optional: true, | ||
Default: false, | ||
}, | ||
}, | ||
} | ||
} | ||
|
@@ -153,6 +171,13 @@ func resourceModuleRead(ctx context.Context, d *schema.ResourceData, meta interf | |
return ResourceGetFailure(ctx, "module", d, err) | ||
} | ||
|
||
if module.IsDeleted { | ||
tflog.Warn(ctx, "Drift Detected: Terraform will remove id from state", map[string]interface{}{"id": d.Id()}) | ||
d.SetId("") | ||
|
||
return nil | ||
} | ||
|
||
if err := writeResourceData(module, d); err != nil { | ||
return diag.Errorf("schema resource data serialization failed: %v", err) | ||
} | ||
|
@@ -200,7 +225,7 @@ func getModuleByName(name string, meta interface{}) (*client.Module, error) { | |
var foundModules []client.Module | ||
|
||
for _, module := range modules { | ||
if module.ModuleName == name { | ||
if !module.IsDeleted && module.ModuleName == name { | ||
foundModules = append(foundModules, module) | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default is false. Not sure why this was ever a pointer.