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: FIxed the api_gw_domain_name replace operation #10179

Merged
merged 1 commit into from
Dec 7, 2016
Merged
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
24 changes: 12 additions & 12 deletions builtin/providers/aws/resource_aws_api_gateway_domain_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,43 +21,43 @@ func resourceAwsApiGatewayDomainName() *schema.Resource {

Schema: map[string]*schema.Schema{

"certificate_body": &schema.Schema{
"certificate_body": {
Type: schema.TypeString,
Required: true,
},

"certificate_chain": &schema.Schema{
"certificate_chain": {
Type: schema.TypeString,
Required: true,
},

"certificate_name": &schema.Schema{
"certificate_name": {
Type: schema.TypeString,
Required: true,
},

"certificate_private_key": &schema.Schema{
"certificate_private_key": {
Type: schema.TypeString,
Required: true,
},

"domain_name": &schema.Schema{
"domain_name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"cloudfront_domain_name": &schema.Schema{
"cloudfront_domain_name": {
Type: schema.TypeString,
Computed: true,
},

"certificate_upload_date": &schema.Schema{
"certificate_upload_date": {
Type: schema.TypeString,
Computed: true,
},

"cloudfront_zone_id": &schema.Schema{
"cloudfront_zone_id": {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -120,31 +120,31 @@ func resourceAwsApiGatewayDomainNameUpdateOperations(d *schema.ResourceData) []*
if d.HasChange("certificate_body") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/certificate_body"),
Path: aws.String("/certificateBody"),
Value: aws.String(d.Get("certificate_body").(string)),
})
}

if d.HasChange("certificate_chain") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/certificate_chain"),
Path: aws.String("/certificateChain"),
Value: aws.String(d.Get("certificate_chain").(string)),
})
}

if d.HasChange("certificate_name") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/certificate_name"),
Path: aws.String("/certificateName"),
Value: aws.String(d.Get("certificate_name").(string)),
})
}

if d.HasChange("certificate_private_key") {
operations = append(operations, &apigateway.PatchOperation{
Op: aws.String("replace"),
Path: aws.String("/certificate_private_key"),
Path: aws.String("/certificatePrivateKey"),
Value: aws.String(d.Get("certificate_private_key").(string)),
})
}
Expand Down
66 changes: 43 additions & 23 deletions builtin/providers/aws/resource_aws_api_gateway_domain_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,37 @@ func TestAccAWSAPIGatewayDomainName_basic(t *testing.T) {
var conf apigateway.DomainName

// Our test cert is for a wildcard on this domain
name := fmt.Sprintf("%s.tf-acc.invalid", resource.UniqueId())
uniqueId := resource.UniqueId()
name := fmt.Sprintf("%s.tf-acc.invalid", uniqueId)
nameModified := fmt.Sprintf("test-acc.%s.tf-acc.invalid", uniqueId)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayDomainNameDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccAWSAPIGatewayDomainNameConfigCreate(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
resource.TestCheckResourceAttr(
"aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody,
),
resource.TestCheckResourceAttr(
"aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain,
),
resource.TestCheckResourceAttr(
"aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name",
),
resource.TestCheckResourceAttr(
"aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey,
),
resource.TestCheckResourceAttr(
"aws_api_gateway_domain_name.test", "domain_name", name,
),
resource.TestCheckResourceAttrSet(
"aws_api_gateway_domain_name.test", "certificate_upload_date",
),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name"),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "domain_name", name),
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "certificate_upload_date"),
),
},
{
Config: testAccAWSAPIGatewayDomainNameConfigUpdate(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name"),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey),
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "domain_name", nameModified),
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "certificate_upload_date"),
),
},
},
Expand Down Expand Up @@ -205,10 +207,28 @@ func testAccAWSAPIGatewayDomainNameConfigCreate(name string) string {
return fmt.Sprintf(`
resource "aws_api_gateway_domain_name" "test" {
domain_name = "%s"
certificate_body = "%v"
certificate_chain = "%v"
certificate_body = <<EOF
%vEOF
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is done on purpose to avoid a diff issue. The other solution would be to update line 43 for instance, adding:

...
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", fmt.Sprintf("%v\n", testAccAWSAPIGatewayCertBody),
...

certificate_chain = <<EOF
%vEOF
certificate_name = "tf-acc-apigateway-domain-name"
certificate_private_key = <<EOF
%vEOF
}
`, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey)
}

func testAccAWSAPIGatewayDomainNameConfigUpdate(name string) string {
return fmt.Sprintf(`
resource "aws_api_gateway_domain_name" "test" {
domain_name = "test-acc.%s"
certificate_body = <<EOF
%vEOF
certificate_chain = <<EOF
%vEOF
certificate_name = "tf-acc-apigateway-domain-name"
certificate_private_key = "%v"
certificate_private_key = <<EOF
%vEOF
}
`, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey)
}