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

provider/aws: New resource codepipeline #11814

Merged
merged 10 commits into from
Feb 22, 2017
Merged

provider/aws: New resource codepipeline #11814

merged 10 commits into from
Feb 22, 2017

Conversation

comebackoneyear
Copy link
Contributor

@comebackoneyear comebackoneyear commented Feb 9, 2017

Hello there, I'm taking over some work done by @heimweh who is on Paternity leave.

First time coding a resource for terraform, It's not very clean at the moment. But I just thought that I'd put this pull request up there so you know that I'm working on it. (Or if someone else is working on it and I'm wasting time on this)

  • Schema
    •  Add all needed fields
    •  Figure out what to do with OAuthToken
  • Functionality
    • Create
    • Read
    • Update
    • Delete
    • Import
  • Tests
    • Schema Validation
    • Acceptance Tests
    • Running Them
  • Documentation

@comebackoneyear
Copy link
Contributor Author

comebackoneyear commented Feb 20, 2017

Test passing

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline*'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/20 16:36:19 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline* -timeout 120m
=== RUN   TestAccAWSCodePipeline_basic
--- PASS: TestAccAWSCodePipeline_basic (42.69s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	42.724s

@comebackoneyear
Copy link
Contributor Author

@heimweh is back and helped me finish this. Any input needed to get this finished would be great.

@comebackoneyear comebackoneyear changed the title [WIP] provider/aws: New resource codepipeline provider/aws: New resource codepipeline Feb 20, 2017
@comebackoneyear
Copy link
Contributor Author

@stack72 We're actively using this while developing our infrastructure. If you have any feedback on the schema before we spend too much time on it would be greatly appreciated.

Thanks

Copy link
Contributor

@stack72 stack72 left a comment

Choose a reason for hiding this comment

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

Hi @comebackoneyear

Thanks for the work here - I think there are a few small things we can clear up before merging

Questions / nits left inline

This is a solid looking feature :)

Paul


func validateAwsCodePipelineArtifactStoreType(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
types := map[string]bool{
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change this to be if v.(string) != "S3" then throw the error

Feel like overhead for a single value

func validateAwsCodePipelineEncryptionKeyType(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
types := map[string]bool{
"KMS": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change this to be if v.(string) != "KMS" then throw the error

Feel like overhead for a single value

func validateAwsCodePipelineStageActionConfiguration(v interface{}, k string) (ws []string, errors []error) {
value := v.(map[string]interface{})
types := map[string]bool{
"OAuthToken": true,
Copy link
Contributor

Choose a reason for hiding this comment

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

same as KMS and S3

conn := meta.(*AWSClient).codepipelineconn
pipeline := expandAwsCodePipeline(d)
params := &codepipeline.CreatePipelineInput{
Pipeline: pipeline,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, as expandAwsCodePipeline func doesn't return an error, then we can just do it as follows:

Pipeline: expandAwsCodePipeline(d)

if err != nil {
return fmt.Errorf("[ERROR] Error creating CodePipeline: %s", err)
}
d.SetId(*resp.Pipeline.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a chance that resp.Pipeline may be nil? If so, this will panic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does not seem like it, it should raise an error if the pipeline was not created. But I can add a check to be sure.

func resourceAwsCodePipelineUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).codepipelineconn

pipeline := expandAwsCodePipeline(d)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need to send the whole request back to AWS on update? Some of their APIs allow us to send just the values that change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears I can't. Update takes a PipelineDeclaration which is the same as the create, it has a lot of required fields.

http://docs.aws.amazon.com/sdk-for-go/api/service/codepipeline/#UpdatePipelineInput

@comebackoneyear
Copy link
Contributor Author

@stack72 @heimweh Made some adjustments, tests still passing.

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline*'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/22 15:40:52 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline* -timeout 120m
=== RUN   TestAccAWSCodePipeline_basic
--- PASS: TestAccAWSCodePipeline_basic (31.89s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	31.914s

@stack72
Copy link
Contributor

stack72 commented Feb 22, 2017

Hi @comebackoneyear

So 1 more request - could you extend the test to show an update?

P.

@heimweh
Copy link
Contributor

heimweh commented Feb 22, 2017

@stack72 added a test for update and separated out the import test.

We also found a bug where we rely on the name of the resource as ID (since we don't get any unique ID from AWS in the response). Solution simply: ForceNew.

@heimweh
Copy link
Contributor

heimweh commented Feb 22, 2017

Tests are passing:

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline*'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/22 17:44:47 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline* -timeout 120m
=== RUN   TestAccAWSCodePipeline_Import_basic
--- PASS: TestAccAWSCodePipeline_Import_basic (28.51s)
=== RUN   TestAccAWSCodePipeline_basic
--- PASS: TestAccAWSCodePipeline_basic (45.71s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	74.244s

Since we don't require a second pass, only do a read.
@stack72
Copy link
Contributor

stack72 commented Feb 22, 2017

Hi both

Code looks good to me - tests don't pass i'm afraid

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline'                                              ✭
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/22 19:00:22 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline -timeout 120m
=== RUN   TestAccAWSCodePipeline_Import_basic
--- FAIL: TestAccAWSCodePipeline_Import_basic (152.20s)
	testing.go:265: Step 0 error: Error applying: 1 error(s) occurred:

		* aws_codepipeline.bar: 1 error(s) occurred:

		* aws_codepipeline.bar: [ERROR] Error creating CodePipeline: InvalidActionDeclarationException: Action configuration for action 'Source' is missing required configuration 'OAuthToken'
			status code: 400, request id: c4b2ca67-f920-11e6-9f62-dba267d67d70
	testing.go:329: Error destroying resource! WARNING: Dangling resources
		may exist. The full state and error is shown below.

		Error: Check failed: Default error in CodePipeline Test

		State: <no state>
=== RUN   TestAccAWSCodePipeline_basic
--- FAIL: TestAccAWSCodePipeline_basic (149.71s)
	testing.go:265: Step 0 error: Error applying: 1 error(s) occurred:

		* aws_codepipeline.bar: 1 error(s) occurred:

		* aws_codepipeline.bar: [ERROR] Error creating CodePipeline: InvalidActionDeclarationException: Action configuration for action 'Source' is missing required configuration 'OAuthToken'
			status code: 400, request id: 1dc33c87-f921-11e6-af42-7f55ed0f471e
	testing.go:329: Error destroying resource! WARNING: Dangling resources
		may exist. The full state and error is shown below.

		Error: Check failed: Default error in CodePipeline Test

		State: <no state>
FAIL
exit status 1
FAIL	github.com/hashicorp/terraform/builtin/providers/aws	301.943s
make: *** [testacc] Error 1

P.

@heimweh
Copy link
Contributor

heimweh commented Feb 22, 2017

Tests without GITHUB_TOKEN environment variable set:

$ make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline*'
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/22 18:19:42 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline* -timeout 120m
=== RUN   TestAccAWSCodePipeline_Import_basic
--- SKIP: TestAccAWSCodePipeline_Import_basic (0.00s)
	import_aws_codepipeline_test.go:13: Environment variable GITHUB_TOKEN is not set
=== RUN   TestAccAWSCodePipeline_basic
--- SKIP: TestAccAWSCodePipeline_basic (0.00s)
	resource_aws_codepipeline_test.go:17: Environment variable GITHUB_TOKEN is not set
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	0.023s

@stack72
Copy link
Contributor

stack72 commented Feb 22, 2017

LGMT Thanks for that addition :)

% make testacc TEST=./builtin/providers/aws TESTARGS='-run=TestAccAWSCodePipeline'                                          
==> Checking that code complies with gofmt requirements...
go generate $(go list ./... | grep -v /terraform/vendor/)
2017/02/22 19:19:24 Generated command/internal_plugin_list.go
TF_ACC=1 go test ./builtin/providers/aws -v -run=TestAccAWSCodePipeline -timeout 120m
=== RUN   TestAccAWSCodePipeline_Import_basic
--- PASS: TestAccAWSCodePipeline_Import_basic (51.09s)
=== RUN   TestAccAWSCodePipeline_basic
--- PASS: TestAccAWSCodePipeline_basic (81.26s)
PASS
ok  	github.com/hashicorp/terraform/builtin/providers/aws	132.379s

@stack72 stack72 merged commit 62aa2c5 into hashicorp:master Feb 22, 2017
stack72 pushed a commit that referenced this pull request Feb 22, 2017
* provider/aws: New resource codepipeline

* Vendor aws/codepipeline

* Add tests

* Add docs

* Bump codepipeline to v1.6.25

* Adjustments based on feedback

* Force new resource on ID change

* Improve tests

* Switch update to read

Since we don't require a second pass, only do a read.

* Skip tests if GITHUB_TOKEN is not set
@ghost
Copy link

ghost commented Apr 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants