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

CodeBuild in VPC continuing Issue #2547 #3324

Merged
merged 2 commits into from
Feb 22, 2018

Conversation

moofish32
Copy link
Contributor

@moofish32 moofish32 commented Feb 11, 2018

updating 2547

@bflad -- I have made your requested changes here.
@DrSolaris happy to hand this back over, just trying to get it merged. I did squash your commits down during the conflict resolution.

@bflad -- the sourceAuth tests obviously fail locally, I'm not sure if it's worth making that test more intelligent.

@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 11, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 11, 2018
@moofish32 moofish32 changed the title Continuing Issue #2495 CodeBuild in VPC continuing Issue #2547 Feb 11, 2018
for _, s := range vpcConfig.Subnets {
subnets = append(subnets, *s)
}
sort.Strings(subnets)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bflad -- I'm still getting random sort ordering issues. Where am I going wrong?

@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. service/codebuild Issues and PRs that pertain to the codebuild service. labels Feb 11, 2018
return err
}

if err := d.Set("vpc_config", flattenAwsCodeBuildVpcConfig(project.VpcConfig)); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No matter how I sort subnets (and I've tried a few). I seem to get failing scenarios, but this line seems to be the indicator of the failure:

vpc_config is set to [map[security_group_ids:[sg-19a81766] vpc_id:vpc-61a22318 subnets:[subnet-d503a08f subnet-953c9fcf]]]
vpc_config is set to [map[vpc_id:vpc-61a22318 subnets:[subnet-d503a08f subnet-953c9fcf] security_group_ids:[sg-19a81766]]]

The object has the same values. The subnets are in the same order, but I get this error:

--- FAIL: TestAccAWSCodeBuildProject_basic (43.42s)
        testing.go:513: Step 0 error: After applying this step, the plan was not empty:

                DIFF:

                UPDATE: aws_codebuild_project.foo
                  vpc_config.0.subnets.0: "subnet-d503a08f" => "subnet-953c9fcf"
                  vpc_config.0.subnets.1: "subnet-953c9fcf" => "subnet-d503a08f"

                STATE:

Is it easier just go back to Set and calculate the hash for the difference?

Copy link
Contributor

Choose a reason for hiding this comment

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

The subnets and security_group_ids can be schema.TypeSet, but you don't need a special hash function for them. Terraform core will "do the right thing" when comparing simple string sets.

@bflad
Copy link
Contributor

bflad commented Feb 12, 2018

@bflad -- the sourceAuth tests obviously fail locally, I'm not sure if it's worth making that test more intelligent.

Are you on the latest master code? What is the error you are seeing? We should address this separately if its an issue as it passes in our daily acceptance testing.

=== RUN   TestAccAWSCodeBuildProject_sourceAuth
--- PASS: TestAccAWSCodeBuildProject_sourceAuth (30.17s)

@bflad bflad self-assigned this Feb 12, 2018
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 12, 2018
@moofish32
Copy link
Contributor Author

@bflad sourceAuth is generating this for me:

=== RUN   TestAccAWSCodeBuildProject_sourceAuth
--- FAIL: TestAccAWSCodeBuildProject_sourceAuth (9.65s)
        testing.go:513: Step 1 error: Error applying: 1 error(s) occurred:

                * aws_codebuild_project.foo: 1 error(s) occurred:

                * aws_codebuild_project.foo: [ERROR] Error creating CodeBuild project: InvalidInputException: No Access token found, please visit AWS CodeBuild console to connect to GitHub
                        status code: 400, request id: 1be10e94-1012-11e8-91d8-f7a26fdbda1c
        testing.go:573: Error destroying resource! WARNING: Dangling resources
                may exist. The full state and error is shown below.

                Error: Check failed: Default error in CodeBuild Test

                State: <no state>

I expect this is due to my git setup having some unique-ness because I have public github, work github enterprise, and experimental Code Commit (work). All being used in various flavors on my laptop. Is this worth a separate issue?

@moofish32
Copy link
Contributor Author

Regarding the in VPC config. I've made the changes back to string and Set please let me know if we need any other work to get this into the merge queue.

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

@moofish32 this is looking really good! Thanks for picking up the torch here. Can you split the testing for vpc_config into its own test then I think this is ready to 🚢 !

make testacc TEST=./aws TESTARGS='-run=TestAccAWSCodeBuildProject'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -run=TestAccAWSCodeBuildProject -timeout 120m
=== RUN   TestAccAWSCodeBuildProject_basic
--- PASS: TestAccAWSCodeBuildProject_basic (69.94s)
=== RUN   TestAccAWSCodeBuildProject_sourceAuth
--- PASS: TestAccAWSCodeBuildProject_sourceAuth (30.96s)
=== RUN   TestAccAWSCodeBuildProject_default_build_timeout
--- PASS: TestAccAWSCodeBuildProject_default_build_timeout (36.86s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	137.806s

Check: resource.ComposeTestCheckFunc(
testAccCheckAWSCodeBuildProjectExists("aws_codebuild_project.foo"),
resource.TestCheckResourceAttr(
"aws_codebuild_project.foo", "build_timeout", "5"),
resource.TestCheckResourceAttrSet("aws_codebuild_project.foo", "vpc_config.0.vpc_id"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please move the vpc_config testing to its own acceptance test? Its an optional attribute and we really prefer to keep the _basic tests only for required attributes. It should continue to test removing the configuration 👍

Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Copy link
Contributor

Choose a reason for hiding this comment

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

Set function should not be required for a simple TypeString set (same with security_group_ids attribute). Although you might have to do this since its nested, I think I ran into something similar recently but would love confirmation.

values := map[string]interface{}{}

values["vpc_id"] = *vpcConfig.VpcId
values["subnets"] = schema.NewSet(schema.HashString, flattenStringList(vpcConfig.Subnets))
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work with just values["subnets"] = flattenStringList(vpcConfig.Subnets)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

        testing.go:513: Step 0 error: Error applying: 1 error(s) occurred:

                * aws_codebuild_project.foo: 1 error(s) occurred:

                * aws_codebuild_project.foo: Invalid address to set: []string{"vpc_config", "0", "subnets"}
        testing.go:573: Error destroying resource! WARNING: Dangling resources
                may exist. The full state and error is shown below.

                Error: Error refreshing: 1 error(s) occurred:

                * aws_codebuild_project.foo: 1 error(s) occurred:

                * aws_codebuild_project.foo: aws_codebuild_project.foo: Invalid address to set: []string{"vpc_config", "0", "subnets"}

                State: <nil>
FAIL

I don't think so sadly :(

Copy link
Contributor Author

@moofish32 moofish32 Feb 17, 2018

Choose a reason for hiding this comment

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

It appears d.Set has the magic buried in there to make this work. I tried a few tricks to pull it out so it would work for subresources, but I couldn't quite make it work. I've stopped and decided that perhaps core should add some features to set and get with subresources instead of my hack-ish attempts. If you think we should invest more here let me know, but right now I didn't want to block this with that.

@@ -350,8 +365,27 @@ func testAccCheckAWSCodeBuildProjectDestroy(s *terraform.State) error {
return fmt.Errorf("Default error in CodeBuild Test")
}

func testAccAWSCodeBuildProjectConfig_basic(rName string) string {
func testAccAWSCodeBuildProjectConfig_basic(rName string, subnet string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same with the mention above about the test itself, the VPC configuration should be separated as well. Thanks!

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Feb 12, 2018
Ryan Moore and others added 2 commits February 17, 2018 12:31
Documentation for VPC block within aws_codebuild_project resource

Update basic codebuild test to support VPC block. Currently contains IAM race condition

Add further error catching to CodeBuild resource creation to deal with more IAM eventual consistency.
Remove unnecessary depends_on clause from CodeBuild basic acceptance test.

Formatting fix for codepipline environment variables documentation
@ghost ghost added the size/L Managed by automation to categorize the size of a PR. label Feb 17, 2018
@moofish32
Copy link
Contributor Author

@bflad -- one more review please? Thanks for the feedback so far.

@moofish32
Copy link
Contributor Author

@bflad -- did we lose momentum?

Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

LGTM -- Sorry I wasn't able to respond quickly, I'm out of office this week, but this is good to get in. Thanks for the work here. 👍

=== RUN   TestAccAWSCodeBuildProject_sourceAuth
--- PASS: TestAccAWSCodeBuildProject_sourceAuth (27.48s)
=== RUN   TestAccAWSCodeBuildProject_basic
--- PASS: TestAccAWSCodeBuildProject_basic (27.63s)
=== RUN   TestAccAWSCodeBuildProject_default_build_timeout
--- PASS: TestAccAWSCodeBuildProject_default_build_timeout (34.57s)
=== RUN   TestAccAWSCodeBuildProject_vpc
--- PASS: TestAccAWSCodeBuildProject_vpc (45.92s)

@@ -686,3 +737,40 @@ resource "aws_codebuild_project" "foo" {
}
`, rName, authResource, authType)
}

func hclVpcResources() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI these function names are global across the entire provider so we would generally prefer sticking with the long for testAccAWSCodeBuildProjectConfig_X

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Feb 22, 2018
@bflad bflad added this to the v1.10.0 milestone Feb 22, 2018
@bflad bflad merged commit 173342c into hashicorp:master Feb 22, 2018
bflad added a commit that referenced this pull request Feb 22, 2018
@bflad
Copy link
Contributor

bflad commented Feb 27, 2018

This has been released in version 1.10.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

@ghost
Copy link

ghost commented Apr 7, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/codebuild Issues and PRs that pertain to the codebuild service. size/L Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants