-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Conversation
dbc8d5b
to
b1207c8
Compare
for _, s := range vpcConfig.Subnets { | ||
subnets = append(subnets, *s) | ||
} | ||
sort.Strings(subnets) |
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.
@bflad -- I'm still getting random sort ordering issues. Where am I going wrong?
return err | ||
} | ||
|
||
if err := d.Set("vpc_config", flattenAwsCodeBuildVpcConfig(project.VpcConfig)); err != nil { |
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.
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?
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.
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.
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.
|
@bflad sourceAuth is generating this for me:
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? |
Regarding the in VPC config. I've made the changes back to string and |
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.
@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"), |
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.
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, |
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.
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)) |
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.
Does this work with just values["subnets"] = flattenStringList(vpcConfig.Subnets)
?
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.
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 :(
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.
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 { |
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.
Same with the mention above about the test itself, the VPC configuration should be separated as well. Thanks!
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
0b57406
to
eb9bf45
Compare
@bflad -- one more review please? Thanks for the feedback so far. |
@bflad -- did we lose momentum? |
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.
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 { |
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.
FYI these function names are global across the entire provider so we would generally prefer sticking with the long for testAccAWSCodeBuildProjectConfig_X
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. |
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! |
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.